Showing results for 
Search instead for 
Did you mean: 

Modbus TCP changing connect ID

Hello forum,

My problem is as follows: I already connected LabView to my PLC (Siemens S7-1200) and everything works excellent. Labview is my Master and the PLC is a Slave. Everything works fine if the connect ID on the PLC is 1. If I change it, the connection can't be established. So I want to know if there is a way to change connect ID on the LabView side if I want my PLC to have some different value (for example 5).


Thanks in advance . . .

0 Kudos
Message 1 of 12

Hi Jelicic and welcome to NI Forums!


Which ModBus library are you using? We have a couple of implementation for ModBus, one for the DSC Module, an object-oriented one and an open-source library as well.

In general, you should set the RTU unit ID to a different value when you are creating the master. In the standard library, this is modifying input [7]:



Kind regards:

Andrew Valko
National Instruments Hungary
0 Kudos
Message 2 of 12

This is implied by the previous response, but keep in mind that the connection ID really has little meaning in the IP context. It's really designed for multi-dropped (bussed) serial links where everybody broadcasts to everybody else, so it's the only means of evaluating "who said that?"

0 Kudos
Message 3 of 12

I am using the MB Ethernet Example Mater from the NI MODBUS Library 1.2.1. I modified that example to suit my needs. Connection ID is going out of the TCP Open Connection Function. Does that correspond to the Connect_ID on the PLC's modbus ? ? ?

0 Kudos
Message 4 of 12

That library has a Transaction ID and Unit ID within a wire-able input called the MBAP header. And as others have said it has little value in a ModbusTCP application. In fact the only time I have ever had occasion to use it was when a slave required some value other than the default 0. So I set it to constant '1'. I doubt this slave would work with any other value. Which may or may not be true of your slave(s).


This is far and away different than anything 'ID' on the Open/Close TCP connection function blocks.


0 Kudos
Message 5 of 12

Thanks for the answer,

What I have learned from Modbus working with PLC's is that both master and slave have to have the same Connect_ID parameter.

But if master wants to communicate with more slaves (or the other way around) then the value can't be the same, you tell master with that parameter which specific slave to call.

Is there a way to change that MBAP header so I can change it to my needs ? ? ?

0 Kudos
Message 6 of 12

First of all - Connect ID is not a typical Modbus term. It's Unit ID.

And in the serial implementations of Modbus the Unit ID is the serial slave's node address. Which, in ModbusTCP is typically not used, as it is replaced by the IP address - (4 octets etc... for example).

Unit ID should only be needed in TCP if you are using an Ethernet / Serial Gateway and need to address multiple slaves behind a single IP address. If your slaves are native ModbusTCP - then they will have unique IP addresses. What would you need to manipulate the Unit ID for?


0 Kudos
Message 7 of 12

I am currently working with two PLC's - experimenting. There is an input for one of the blocks for modbus communication called Connect_ID and it's on the PLC. As I explained in my first post the communication between PLC and LabView is only possible if that input has value 1. In the PLC - PLC communication that value needs to be the same so it could work. It works with every number (intiger).

I want to know if that parameter, whatever it is called, can be changed on the LabView side so I don't have to always change it on the PLC (one is programmed with Connect_ID=1 and the other one has Connect_ID=5).

I hope we have an understanding . . .

0 Kudos
Message 8 of 12

I am attempting to setup a modbus TCP connection to a set of slaves behind a single IP address. Can anyone offer some insight into how to define the slave id in the Modbus TCP VI's? Any help is appreciated. 


0 Kudos
Message 9 of 12

You clearly didn't read the thread.  There are several APIs.  If you're going to bump an old thread, at least take the time to read it enough so that you can give enough information to be helped.

0 Kudos
Message 10 of 12