在linux下的python中设置RS485设备地址

Setting RS485 device address in python under linux

我正在尝试通过RS485(HMI + PLC,通信协议是Fatek自己的协议)连接到现有的设备网络。我直接连接PLC没有问题(我可以读写寄存器),但是我必须离开HMI<>PLC连接。当直接连接到 HMI 和 PLC 之间的线路时(通过 FTDI USB<>RS485 适配器)我无法从 PLC 读取或写入寄存器(我没有收到正确的响应)。

据我所知,可以在一根 RS485 线上连接多个设备,前提是它们已设置好地址。问题是:我看不到在哪里设置这个地址。它是否包含在每个 "frame" 发送中?它是否设置在 USB<>RS485 适配器的驱动程序中?它是否硬编码在适配器中?

提前谢谢你,

迈克尔

正如下面的维基百科文章,RS485 是一种没有默认软件或协议的电气规范。
处理设备地址的机制必须由您自己创建或通过选择具有此类功能的协议并应用它来创建。

RS-485 - Wikipedia

RS-485 only specifies electrical characteristics of the generator and the receiver: the physical layer. It does not specify or recommend any communications protocol; Other standards define the protocols for communication over an RS-485 link. The foreword to the standard references The Telecommunications Systems Bulletin TSB-89 which contains application guidelines, including data signaling rate vs. cable length, stub length, and configurations.

比如Modbus不是经常用吗?
Modbus -Wikipedia

Modbus is a data communications protocol originally published by Modicon (now Schneider Electric) in 1979 for use with its programmable logic controllers (PLCs). Modbus has become a de facto standard communication protocol and is now a commonly available means of connecting industrial electronic devices. Modbus is popular in industrial environments because it is openly published and royalty-free.

还有一些 python 包。
minimalmodbus 1.0.2
pymodbus 2.3.0

如何设置设备地址需要根据所采用的封装规格来设置。


另外:

顺便说一句,如果您正在为 PLC 设备使用制造商的专有协议,则您很可能会为该设备和协议使用此类多点。 似乎第一种方法是联系制造商的支持台。

或者,即使此站点是制造商支持位置,您也需要添加信息,例如您尝试连接的设备和配置。

HMI_Support & PLC_Support
HMI_Products & PLC_Products

您的系统似乎正在使用 FB 用户手册附录 1 中记录的 "Fatek communication protocol"。 (Download here)

该协议看起来像工业 PLC 控制器的许多此类典型协议。但是,由于消息类型的数量,它有点复杂。不用看得太深,几天之内实现逻辑似乎是可行的。或者某处可能有一个开源实现(虽然我没有搜索)。

通常在串口通信中,无论是1:1还是1:N,只能有一个主机(在你的情况下HMI是主机)和一个或多个响应请求的从机master,而且master在提交新请求之前必须一直等待收到响应。

如果您连接第二个主机,就会在网络上造成冲突,RS-485 无法管理这些冲突。

串口网络上只能存在一个master。

如果您想克服这些限制,请考虑用以太网替换该网络,TCP/IP