Modbus 485 通信(如果有 2 个或更多主站/客户端)

问题描述 投票:0回答:1

我目前正在致力于构建工业应用。我有一个基于 STM32 构建的从属 PCB 设备,它从传感器获取数据。它根据Master A的请求,每5秒通过RS485 USB转换器向Master A传输串行数据。现在,我想使用 RS485 转换器添加另一个 Master B 到 LAN。在这种情况下,当两个主机尝试同时读取数据时,如何避免数据损坏或冲突。

[*** PCB Slave 包括 Modbus RS485 库,这意味着它发送串行数据。]

RS485 转 LAN 转换器(我正在使用的转换器)-> http://www.realsys.co.kr/goods/content.asp?guid=581&cate=367¶ms=cate=367^sword=^swhat=^listsort=favorite^listtype=album^listsize=5^page=

更清楚地说,我想使用两个主机从PCB Slave读取数据。一种是使用 RS485 RTU USB 转换器,另一种是使用 RS485 转换器到 TCP/IP。在这种情况下是否可以顺利通信而不会中断或数据损坏?

为什么我需要使用2位大师: 因为,我们已经使用Master A(使用USB转换器)构建了产品。它已经安装在这些地方了。现在,一些客户希望获得相同的产品以及 Master B (Modbus TCP/IP) 选项。通过使用 Master B,他们希望使用 LAN 将传感器数据传输到自己的工业 PC。

我已经设置了硬件部件并使用了一些逻辑来测试案例。 当两个主机尝试同时读取数据时,我从使用 USB 转换器的主机收到超时错误。另一个 Master 抛出以下 Exception 错误

Exception - System.IO.IOException: Unable to read data from the 
transport connection: A blocking operation was interrupted by a 
call to WSACancelBlockingCall. ---> 
System.Net.Sockets.SocketException: A blocking operation was 
interrupted by a call to WSACancelBlockingCall
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, 
Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 
offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 
offset, Int32 size)
at FluentModbus.ModbusTcpClient.TransceiveFrame(Byte 
unitIdentifier, ModbusFunctionCode functionCode, Action`1 
extendFrame)in 
/home/runner/work/FluentModbus/FluentModbus/src/FluentModbus/Client/ModbusTcpClient.cs:line 269
   at FluentModbus.ModbusClient.ReadInputRegisters(Byte unitIdentifier, UInt16 startingAddress, UInt16 quantity) in /home/runner/work/FluentModbus/FluentModbus/src/FluentModbus/Client/ModbusClient.cs:line 317
   at FluentModbus.ModbusClient.ReadInputRegisters[T](Int32 unitIdentifier, Int32 startingAddress, Int32 count)
modbus serial-communication rs485 modbus-tcp
1个回答
0
投票

您不能在串行线上放置多个主机。您需要不同的硬件设置,将 Modbus TCP 转 RS485 网关(不是哑串口到以太网转换器)放在串行线前面,然后两个主机都需要使用 Modbus TCP 与网关通信。

© www.soinside.com 2019 - 2024. All rights reserved.