rossmann-engineering / EasyModbusTCP.NET

Modbus TCP, Modbus UDP and Modbus RTU client/server library for .NET implementations
928 stars 402 forks source link

UnitIdentifier & Modbus TCP #44

Closed pechezerov closed 4 years ago

pechezerov commented 4 years ago

I use ModbusServer like this:

public SlaveWrapper(int port)
{
      server = new EasyModbus.ModbusServer();
      server.Port = port;
      server.SerialFlag = false;
      server.UDPFlag = false;
      server.LogDataChanged += someMethod;
      server.Listen();
}

If I connect to the server with SlaveId = 1: image

If I connect to the server with SlaveId = 2 (or any other value): image

In this page I see:

public byte UnitIdentifier gets or sets the unit identifier (Slave-ID). Normally only nessesary for Modbus-RTU (Standard is 1)

But there is slightly different approach from modbus.org see page.23

On TCP/IP, the MODBUS server is addressed using its IP address; therefore, the MODBUS Unit Identifier is useless. The value 0xFF has to be used.

This approach is followed, for example, by libmodbus. Default UnitId for all Modbus TCP requests is 255.

What do you think, does this mean that a UnitIdentifier match check should not be performed for the TCP server?

Padanian commented 4 years ago

Exactly. The node address in modbusTCP is the TCPIP address. There is an exception for modbusRTU over TCP. In this case the TCP address is the gateway's, which shall route the request to the node address specified in the unitID. But modbusRTU over TCP was never officially approved, and Easymodbus does not cover it.

pechezerov commented 4 years ago

So, I have to use UnitId = 1 anyway on all clients?

Or I should explicitly set UnitId while work with TCP Server this way: server.UnitIdentifier = 255;

Padanian commented 4 years ago

Strictly speaking, it shall make no difference whatsoever. If it abides strictly to specs, you set it to 0xFF and the server shall ignore it.