fullde 发表于 2016-12-13 21:39:09

宏指令写modbus,串口读写有问题

这是找到的宏指令模板
// Read Holding Registers
macro_command main()
char command, response
short address, checksum
short read_no, return_value, read_data, i
FILL(command, 0, 32)// initialize command~command to 0
FILL(response, 0, 32)
command = 0x1// station number
command = 0x3// read holding registers (function code is 0x3)
address = 0// starting address (4x_1) is 0
HIBYTE(address, command)
LOBYTE(address, command)
read_no = 2// the total words of reading is 2 words
HIBYTE(read_no, command)
LOBYTE(read_no, command)
CRC(command, checksum, 6)// calculate 16-bit CRC
LOBYTE(checksum, command)
HIBYTE(checksum, command)
OUTPORT(command, "MODBUS RTU Device",8)// send request
INPORT(response, "MODBUS RTU Device",9,return_value)// read response
if (return_value > 0 and response == 0x4) then
read_data = response + (response << 8)// 4x_1
read_data = response + (response << 8)// 4x_2
SetData(read_data, "Local HMI", LW, 0, 2)
end if
end macro_command

写到触摸屏上后,通过485连电脑,用串口助手读到的数据却是
7F DF EB FF FB 5D 6D 00

不知道是什么原因?
刚接触这个东西,触摸屏是MT8102iE,望大神指教!
页: [1]
查看完整版本: 宏指令写modbus,串口读写有问题