如何发送十六进制数据?
我正在尝试通过 modbusTCP 或 modbus 串行与 modbus 从机进行通信。制造商。 (partlow) 有一份 ASCII 通信手册 (http://www .partlow.com/uploadedFiles/Downloads/1160%20ASCII%20Comms%20Manual.pdf),看起来它与标准通信方法不同(http://en.wikipedia.org/wiki/Modbus)。许多现有代码都设置为与线圈等的正常 modbus 寻址一起工作,其中似乎(至少对我来说)与这些人不同。
那么,通过 ruby 或 perl,如何发送十六进制数据?我可能一切都很好,但是,如果我将“0DFA”写入串行端口......可以吗?或者我是否需要先将其转换为较低层,或者以某种方式表示它?
我在这方面做了很多工作,可能把自己搞混了(让事情变得比实际情况更复杂),但是,我正在尝试与此仪表建立通信,我可以看到 TX 活动灯闪烁,但没有 RX,这意味着我的数据格式是错误的...
主要是在解决这个问题(以及一些perl片段,试图找到一些有用的东西): http://www.messen-und-deuten.de/modbus.html
我正在通过终端服务器进行通信,该服务器接受 modbusTCP(此脚本使用的),但我无法将通信手册中的内容应用到上面的代码,以正确设置数据包格式。
I am trying to communicate with a modbus slave via either modbusTCP or modbus serial. The manuf. (partlow) has an ASCII communications manual (http://www.partlow.com/uploadedFiles/Downloads/1160%20ASCII%20Comms%20Manual.pdf) which, looks like it differs from the standard communication methods (http://en.wikipedia.org/wiki/Modbus). A lot of existing code out there is setup to work with normal modbus addressing of coils and such, where it seems (at least to me) to be different with these guys.
So, via ruby or perl, how can I send hex data? I may be doing everything fine, but, if I write "0DFA" to a serial port... is that ok? or do I need to convert it into a lower layer first, or denote it somehow?
Been working on this a lot and may have myself mixed up (making things out to be more complicated than they are) but, i am trying to establish comm with this meter, and I can see the TX activity light blink but no RX, which means my data format is wrong...
Been working off this mostly (and a few perl snippets here and there, trying to find something that works):
http://www.messen-und-deuten.de/modbus.html
I am communicating through a terminal server, which accepts modbusTCP (which this script uses) but i'm having trouble applying whats in the comm manual to the code above, to get the packet formatted correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你说的是原始数据吗?有几种方法,包括
Are you talking about raw data? There are several ways, including
我建议您查看 RModBus 库,以帮助处理 TCP/IP 上数据包形成的一些复杂问题来自 Ruby 语言内部。
您正在通信的设备总是可能需要或相反地避免使用 modicon 符号。当我第一次尝试从 PLC 读取寄存器时,遇到了一些问题。我在 Modbus 中发现的另一个“陷阱”是,某些寻址系统由于其实现中的怪异而被抵消了 1。
I would recommend you look at the RModBus library to help handle some of the intricacies of packet formation over TCP/IP from inside the Ruby language.
It is always possible that the device you are communicating with requires, or conversely avoids the modicon notation. That was a bit of a hiccup when I first tried reading registers from a PLC. The other "gotcha" that I've found with Modbus is that some of the addressing systems are offset by one due to quirkiness in their implementation.