威纶通官方论坛

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

[复制链接]
发表于 2016-12-13 21:39:09 | 显示全部楼层 |阅读模式
这是找到的宏指令模板
// Read Holding Registers
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)// initialize command[0]~command[31] to 0
FILL(response[0], 0, 32)
command[0] = 0x1// station number
command[1] = 0x3// read holding registers (function code is 0x3)
address = 0// starting address (4x_1) is 0
HIBYTE(address, command[2])
LOBYTE(address, command[3])
read_no = 2// the total words of reading is 2 words
HIBYTE(read_no, command[4])
LOBYTE(read_no, command[5])
CRC(command[0], checksum, 6)// calculate 16-bit CRC
LOBYTE(checksum, command[6])
HIBYTE(checksum, command[7])
OUTPORT(command[0], "MODBUS RTU Device",8)// send request
INPORT(response[0], "MODBUS RTU Device",9,return_value)// read response
if (return_value > 0 and response[1] == 0x4) 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, 0, 2)
end if
end macro_command

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

不知道是什么原因?
刚接触这个东西,触摸屏是MT8102iE,望大神指教!
您需要登录后才可以发帖 登录 | 注册

本版积分规则

回复帖子

Archiver|小黑屋|威纶通官网 ( 粤ICP备06054553号 )

GMT+8, 2024-4-27 03:10

Powered by Discuz! X3.4

© 2001-2023 Comsenz Inc.

快速回复 返回顶部 返回列表