macro_command main()
unsigned char baifenbi,cishu //定义变量类型
unsigned short canshu[10] //参数值
unsigned int guocheng[10] //过程变量
unsigned short jieguo[10] //结果值
GetData(baifenbi, "HMI", LW, 0, 1) //读取LW0的当前值
GetData(canshu[0], "HMI", LW, 10, 10) //读取LW10到LW19的值分别存入canshu[0]到canshu[9]
for cishu = 0 to 9 step 1 //变量cishu从0到9一次计算,每次cishu值+1
guocheng[cishu] = baifenbi * canshu[cishu] //百分比*参数值
jieguo[cishu] = guocheng[cishu] / 100
next
SetData(jieguo[0], "HMI", LW, 101, 10) //将运算结果写入HMI,方便查看运算结果是否正确
SetData(jieguo[0], "MODBUS RTU", 3x, 1, 10) //将运算结果写入目标设备
end macro_command |