本帖最后由 pcsms_mGDDHX7J 于 2024-12-25 10:18 编辑
这个程序在比较时为啥总显示相同,明明写入LW界面显示不一样,通过串口通讯 写入界面显示 ,之后再写入前 ,比对一下是否重复,如果重复,就不写入 。 关键读出来后比对,明明不一样,却显示相同
macro_command main()
//初始值
char c[27]={0}
short ss =0
short cc=0,bb =0
//读取的数组
char c0[32]={0}
char c1[32]={0}
char c2[32]={0}
char c3[32]={0}
char c4[32]={0}
char c5[32]={0}
char c10[32]={0}
bool ResultCp0 =false,ResultCp1=false,ResultCp2=false,ResultCp3=false,ResultCp4=false
short n =0
bool Result =true
//读取数据
FILL(c[0], 0, 28)
PURGE(2)
INPORT(c[0], "Free Protocol", 27, n)
//判定数据标头
LOBYTE(c[0], cc)
HIBYTE(c[0], bb)
//
if n >0 and cc ==0xAA and bb ==0xFF then
SetData(c[8], "Local HMI", LW, 260, 1)
SetData(c[9], "Local HMI", LW, 261, 1)
SetData(c[10], "Local HMI", LW, 262, 1)
SetData(c[11], "Local HMI", LW, 263, 1)
SetData(c[12], "Local HMI", LW, 264, 1)
SetData(c[13], "Local HMI", LW, 265, 1)
SetData(c[14], "Local HMI", LW, 266, 1)
SetData(c[15], "Local HMI", LW, 267, 1)
SetData(c[16], "Local HMI", LW, 268, 1)
SetData(c[17], "Local HMI", LW, 269, 1)
SetData(c[18], "Local HMI", LW, 270, 1)
SetData(c[19], "Local HMI", LW, 271, 1)
SetData(c[20], "Local HMI", LW, 272, 1)
SetData(c[21], "Local HMI", LW, 273, 1)
SetData(c[22], "Local HMI", LW, 274, 1)
SetData(c[23], "Local HMI", LW, 275, 1)
//读取前5个数据
//FILL(c0[0], 0, 32)
FILL(c1[0], 0, 32)
FILL(c2[0], 0, 32)
FILL(c3[0], 0, 32)
FILL(c4[0], 0, 32)
FILL(c10[0], 0, 32)
GetData(c10[0], "Local HMI", LW, 260, 16)
//测试使用
//SetData(c0[0], "Local HMI", LW, 500, 8)
//SetData(c1[0], "Local HMI", LW, 600, 8)
//SetData(c2[0], "Local HMI", LW, 700, 8)
//SetData(c3[0], "Local HMI", LW, 800, 8)
//SetData(c4[0], "Local HMI", LW, 900, 8)
SetData(c10[0], "Local HMI", LW, 500, 16)
//判定
GetData(c0[0], "Local HMI", LW, 107, 16)
ResultCp0 =StringCompare(c10[0], c0[0])
SetData(c0[0], "Local HMI", LW, 600, 16)
GetData(c1[0], "Local HMI", LW, 144, 16)
ResultCp1 =StringCompare(c10[0], c1[0])
GetData(c2[0], "Local HMI", LW, 160, 16)
ResultCp2 =StringCompare(c10[0], c2[0])
GetData(c3[0], "Local HMI", LW, 176, 16)
ResultCp3 =StringCompare(c10[0], c3[0])
GetData(c4[0], "Local HMI", LW, 192, 16)
ResultCp4 =StringCompare(c10[0], c4[0])
//比较结果显示
SetData(ResultCp0, "Local HMI", LB, 6, 1)
SetData(ResultCp1, "Local HMI", LB, 7, 1)
SetData(ResultCp2, "Local HMI", LB, 8, 1)
SetData(ResultCp3, "Local HMI", LB, 9, 1)
SetData(ResultCp4, "Local HMI", LB, 11, 1)
关键读出来后比对,明明不一样,却显示相同
//判定是否更新and not ResultCp3 and not ResultCp4
if cc ==0xAA and bb ==0xFF and not ResultCp0 and not ResultCp1 and not ResultCp2 then
//if cc ==0xAA then
ss =2
SetData(ss, "Local HMI", LW, 5, 1)
else
ss =8
SetData(ss, "Local HMI", LW, 5, 1)
end if
//执行写指令
end macro_command
|