使用自由通信协议示例让MT6070IH与modbus设备通信宏指令如下:- macro_command main()
- char command[32], response[32]
- short address, checksum
- short read_no, return_value, read_data[2], i
- FILL(command[0], 0, 32)// init
- FILL(response[0], 0, 32)
- command[0] = 0x1// station no
- command[1] = 0x3// read holding registers
- address = 0x84
- HIBYTE(address, command[2])
- LOBYTE(address, command[3])
- read_no = 2// read 4x_1, 4x_2
- HIBYTE(read_no, command[4])
- LOBYTE(read_no, command[5])
- CRC(command[0], checksum, 6)
- LOBYTE(checksum, command[6])
- HIBYTE(checksum, command[7])
- OUTPORT(command[0], "MODBUS RTU Device", 8)// send command
- INPORT(response[0], "MODBUS RTU Device", 9, return_value)// read response
- SetData(return_value, "Local HMI", LW, 0, 1)// return_value == 0 -> error
- SetData(response[0], "Local HMI", LW, 10, 9)// send response to LW
- if (return_value > 0 and response[1] == 0x3) then
- read_data[0] = response[4] + (response[3] << 8)// 4x_1
- read_data[1] = response[6] + (response[5] << 8)// 4x_2
-
- SetData(read_data[0], "Local HMI", LW, 100, 2)
- end if
- end macro_command
复制代码 设备通信口属性RS485/2W COM1 9600 N 8 2,读取返回数据存到LW10-LW18,通过外接2个串口线到电脑使用串口调试助手监视数据看到,HMI能发送数据如下:
01 03 00 84 00 02 84 22
MODBUS设备返回数据为:
01 03 04 00 00 00 13 BB FE
但是HMI中数值显示元件只有LW10、LW11、LW12显示有数据,数据分别为:
2001 0010 3713
请问各位高手:为什么通过串口助手看到的数据和HMI中显示的数据不一致,是不是宏指令中接收数据问题?如何解决? |