威纶通官方论坛

MT6070IH宏指令使用free protocol读取modbus设备问题

[复制链接]
发表于 2014-4-14 15:47:27 | 显示全部楼层 |阅读模式
使用自由通信协议示例让MT6070IH与modbus设备通信宏指令如下:
  1. macro_command main()

  2. char command[32], response[32]
  3. short address, checksum
  4. short read_no, return_value, read_data[2], i

  5. FILL(command[0], 0, 32)//  init
  6. FILL(response[0], 0, 32)

  7. command[0] = 0x1//  station no
  8. command[1] = 0x3//  read holding registers

  9. address = 0x84
  10. HIBYTE(address, command[2])
  11. LOBYTE(address, command[3])

  12. read_no = 2//  read 4x_1, 4x_2
  13. HIBYTE(read_no, command[4])
  14. LOBYTE(read_no, command[5])

  15. CRC(command[0], checksum, 6)

  16. LOBYTE(checksum, command[6])
  17. HIBYTE(checksum, command[7])

  18. OUTPORT(command[0], "MODBUS RTU Device", 8)//  send command
  19. INPORT(response[0], "MODBUS RTU Device", 9, return_value)//  read response

  20. SetData(return_value, "Local HMI", LW, 0, 1)//  return_value == 0 -> error
  21. SetData(response[0], "Local HMI", LW, 10, 9)//  send response to LW  

  22. if (return_value > 0 and response[1] == 0x3) then
  23.   read_data[0] = response[4] + (response[3] << 8)//  4x_1
  24.   read_data[1] = response[6] + (response[5] << 8)//  4x_2
  25.   
  26.   SetData(read_data[0], "Local HMI", LW, 100, 2)  
  27. end if

  28. 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中显示的数据不一致,是不是宏指令中接收数据问题?如何解决?
发表于 2014-4-21 18:49:39 | 显示全部楼层
接收的是16进制,你显示设置的可能是十进制!
您需要登录后才可以发帖 登录 | 注册

本版积分规则

回复帖子

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

GMT+8, 2024-6-16 13:46

Powered by Discuz! X3.4

© 2001-2023 Comsenz Inc.

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