Change Unit ID in Modbus TCP ADU Header

Updated Apr 3, 2023

Reported In

Software

  • LabVIEW

Issue Details

I'm using the Data Communication > Modbus > Master palette to establish interfaces using Modbus over TCP/IP. I need to be able to change the Unit ID value from 1 to a different number in the ADU packet. Is there a way to change this value?

I have tried to use the Modbus Master.lvclkass:Set Unit ID.vi but this only works with a Serial connection. 

Solution

For TCP/IP, it is possible to change the Modbus Unit ID when creating the master. This can be done using a property node as shown in the figure below. The Modbus master instance needs to be taken from the property node. If the reference is taken directly from the Create Master Instance.vi, it will still have the default Unit ID value of 1.

 

Additional Information

On TCP/IP, the MODBUS server is addressed using its IP address; therefore, the MODBUS Unit Identifier is generally not used. When addressing a MODBUS server connected directly to a TCP/IP network, it’s recommended not to use a significant MODBUS slave address in the “Unit Identifier” field. In the event of a re-allocation of the IP addresses within an automated system and if a IP address previously assigned to a MODBUS server is then assigned to a gateway, using a significant slave address may cause trouble because of a bad routing by the gateway.

Unit ID is not a necessary property for Modbus TCP unless you are trying to access multiple slaves in the same IP address. Unit ID was used for the serial implementation as a way to identify the slave address, but with the TCP implementation uses the actual IP address.