//宏指令定义
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] = 0x01// station no
command[1] = 0x03// read holding registers
address = 0
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], "Free Protocol", 8)// send command
INPORT(response[0], "Free Protocol" , 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
我用宏指令填了以上代码 我大概意思是发送01 03 00 00 00 02 C4 0B(CRC的两个检验字节) 然后用位状态设置元件触发宏指令,然后用触摸屏串口跟电脑连接,想看看接收的是不是我想发的。。
结果我用串口助手看到收到的指令是7F 7E FF FF FB 77 7A 才7个,但是我上面的宏指令是发送8个 代码我是仿EB8000使用手册的,我仔细看了各个函数,按道理应该是没错的。。但是接收的却是“货不对板” 有人知道怎么弄吗 求助