简体   繁体   English

多客户端 modbus 到单个 modbus 服务器

[英]Multi clients modbus to single modbus server

I have two python scripts which need to get data from the same modbus server.我有两个 python 脚本需要从同一个 modbus 服务器获取数据。

However they cannot be simultaneously connected to the same modbus server, so I am looking for a "proxy" software.但是它们不能同时连接到同一个 modbus 服务器,所以我正在寻找一个“代理”软件。

This proxy will then sequentially transfer the modbus queries to the modbus server.然后,该代理将顺序地将 modbus 查询传输到 modbus 服务器。 Solution should run on debian 11 lite.解决方案应在 debian 11 lite 上运行。 Thanks!谢谢!

Assuming you are dealing with Modbus TCP you can try modbus-proxy :假设您正在处理 Modbus TCP,您可以尝试modbus-proxy

Many modbus devices support only one or very few clients.许多 modbus 设备只支持一个或很少的客户端。 This proxy acts as a bridge between the client and the modbus device.该代理充当客户端和 modbus 设备之间的桥梁。 It can be seen as a layer 7 reverse proxy.它可以看作是第 7 层反向代理。 This allows multiple clients to communicate with the same modbus device.这允许多个客户端与同一 modbus 设备进行通信。

When multiple clients are connected, cross messages are avoided by serializing communication on a first come first served REQ/REP basis.当连接多个客户端时,通过在先到先得的 REQ/REP 基础上序列化通信来避免交叉消息。

EDIT: According to your comment below:编辑:根据您在下面的评论:

...it is RTU over a linux file descriptor /dev/ttyS1 ...它是 linux 文件描述符 /dev/ttyS1 上的 RTU

That seems to me a not-so-straightforward way of saying that you are dealing with a serial link.在我看来,这是一种不太直截了当的方式来说明您正在处理串行链接。

If that's the case I'm afraid you need to go back all the way to the physical layer.如果是这种情况,恐怕您需要 go 一直返回到物理层。

If you have a point-to-point serial connection (no matter the voltage levels you have, they can be TTL 3.3VDC or RS-232) there is no way you can have more than one Modbus client connecting to the same server.如果你有一个点对点串行连接(无论你有什么电压水平,它们可以是 TTL 3.3VDC 或 RS-232),你就不可能有多个 Modbus 客户端连接到同一台服务器。

For a serial link to have more than two devices (two or multiple clients sending queries to a Modbus server, for instance) you need a way for the devices to take control of the bus when they communicate and let go of it when they are idle.对于具有两个以上设备的串行链路(例如,两个或多个客户端向 Modbus 服务器发送查询),您需要一种方法让设备在通信时控制总线,并在空闲时让 go 控制总线. An RS-485 multipoint serial link is the most frequent solution to this problem. RS-485多点串行链路是解决此问题最常用的方法。

If you follow the link you will find many resources and documentation.如果您点击该链接,您将找到许多资源和文档。 That might be a bit overwhelming but it is actually very easy: instead of connecting RX to TX as you'd do for a normal serial port you will have two cables for each device (they are called A and B or D+ and D-) that you can put together.这可能有点让人不知所措,但实际上非常简单:不是像普通串行端口那样将 RX 连接到 TX,而是为每个设备准备两根电缆(它们称为 A 和 B 或 D+ 和 D-)你可以放在一起。 And you only need to add a TTL to RS-485 transceiver in between each device and the bus (or RS-232 to RS-485, depending on your devices).您只需在每个设备和总线之间添加一个 TTL 到 RS-485 收发器(或 RS-232 到 RS-485,具体取决于您的设备)。

There are a couple of nuances:有一些细微差别:

The most complete reference on all these topics I know of is Jan Axelson's book Serial Port Complete .我所知道的关于所有这些主题的最完整的参考资料是 Jan Axelson 的书Serial Port Complete It's a bit old (the last edition was released in 2007) but still very relevant.它有点旧(最后一版于 2007 年发布)但仍然非常相关。 And you can find older editions secondhand for next to nothing.您几乎可以免费找到二手的旧版本。 If you need to work with serial ports, this book will be a very valuable companion.如果您需要使用串行端口,这本书将是非常有价值的伴侣。

Final note: if you are not able or willing to mess with the phy layer, you might, of course, find other solutions that are more palatable.最后说明:如果您不能或不愿意弄乱 phy 层,您当然可以找到其他更适合的解决方案。 You might, for instance, implement a software forwarder to take queries from your clients and convert them to Modbus RTU to be sent to your server.例如,您可以实施一个软件转发器来接收来自您的客户端的查询并将它们转换为 Modbus RTU 以发送到您的服务器。 Pymodbus includes an example , but since you did not elaborate much I'm not sure it will be useful for your situation. Pymodbus 包含一个示例,但由于您没有详细说明,我不确定它对您的情况是否有用。

I have the same challenges before and ended up with Modbus-to-MQTT bridge solution, because each protocol has its limit, Modbus is designed for master-slave poll in nature and MQTT is good for multiple clients/subscribers.我之前遇到过同样的挑战,最终得到了 Modbus-to-MQTT 桥接解决方案,因为每个协议都有其限制,Modbus 本质上是为主从轮询而设计的,而 MQTT 适用于多个客户端/订阅者。

Modbus + MQTT , such a combination is just nice and could be very powerful in modern IoT applications. Modbus + MQTT ,这样的组合非常好,在现代物联网应用程序中可能非常强大。 You can try modpoll , which is a python-based Modbus tool and can run as a Modbus-to-MQTT bridge in your case.您可以尝试modpoll ,这是一个基于 python 的 Modbus 工具,在您的情况下可以作为 Modbus-to-MQTT 桥运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM