UnitIdentifier & Modbus TCP
pechezerov opened this issue · 3 comments
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:
If I connect to the server with SlaveId = 2 (or any other value):
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?
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.
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;
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.