求大神帮助:
无论是采用内置的modbus协议,还是自己用宏定义的传输均有问题
内置:7F 7E DF FF FD F5 18 (应该为01 03 00 10 00 01 **)
我用宏指令简单测试了一下:给0x01 输出0x7F ,给了个0x56 输出0x2A,但是这个值输出到HMI的寄存器(我给到LW00100)值是对的
macro_command main()
char command[32], response[32]
short address, checksum
short read_no, return_value, read_data[2]
FILL(command[0], 0, 32) // 命令初始化
FILL(response[0], 0, 32)
Command[0] = 0x56
Command[1] = 0x3 // 功能码:读取保持寄存器
address = 0
HIBYTE(address, command[2])
LOBYTE(address, command[3])
read_no = 2 // read 2 words (4x_1 and 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 函数将命令送出去
OUTPORT(command[0], "Modbus RTU", 1)
read_data[0] = command[0]
SetData(read_data[0], "Local HMI", LW, 100, 1)
end macro_command
|