Modbus Gateway

I am using the Modbus gateway, Ethernet to an RTU client. The gateway works fine. External TCP/IP clients can access the RTU device as expected.

How do I access the RTU device in my TinyCLR code?

What I have below works but I get frequent Modbus timeout errors on the mbMaster.ReadHoldingRegisters() while TCP/IP devices are accessing the device, at the same time the TCP/IP device times out as well. Is there a better way to do this?

I tried mbMaster as a ModbusTcpInterface, but that didn’t work. I tried the “127.0.0.1” address and the device’s actual IP address but neither worked.

var mbInterface = new ModbusRtuInterface(
    port1,
    9600,
    8,
    UartStopBitCount.One,
    UartParity.None
    );

 var gateway = new ModbusGateway(ModbusConst.TcpDeviceAddress, mbInterface, 1000);
 var tcpInterfaceListener = ModbusTcpInterface.StartDeviceListener(gateway);

 mbMaster = new ModbusMaster(mbInterface, mbSlaveSync);
         
 gateway.Start();

ushort[] _data;
while(true)
{
    try
    {
      _data = mbMaster.ReadHoldingRegisters(1, 96, 6, 2000);
    } 
    catch(Exception)
    {}

   Thread.Sleep(1000);
}
  
1 Like