LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus RTU connection to multiple slaves

Solved!
Go to solution

I can connect to a single Modbus RTU slave with no problem. However, how can I expand this to communicate with multiple slaves using the same COM port?

0 Kudos
Message 1 of 14
(1,892 Views)

Change the addresses to be different. I cannot open your code as I don't have LV 2023. You may want to save for previous version code posted here. However, if you can talk to one slave device, the address is part of the communication for Modbus RTU. You will need a way to change it on your slave device. (I've had to connect one at a time and set the address before integrating into a bigger project).

 

0 Kudos
Message 2 of 14
(1,887 Views)

How can I change the Unit ID on the fly so that I can address another unit and keep the information separate? What I have now does well for one unit and graphs the temperature every second.

0 Kudos
Message 3 of 14
(1,884 Views)

To better see what I have so far, I am attaching a Word document with the VI.

0 Kudos
Message 4 of 14
(1,874 Views)

Save for a previous version is the preferred method. Posting a png image also works. Using a proprietary Word document to insert an image is something I am not going to look at.

 

0 Kudos
Message 5 of 14
(1,855 Views)

Didn't know what version to save as, so here is the png file. Sorry!

0 Kudos
Message 6 of 14
(1,844 Views)

Ok. It looks like you are using NI's Modbus library, but honestly I am a little confused as to why they have a yellow border. Maybe a newer feature I am not familiar with. 

 

At any rate, you want two Create Master functions. Both have the same com port and baud rate, but with different ID's. Use the two instance wires the same as how you have done with one. If they are the same type of device and you want the same data you can bundle the instance wires and use a for loop (see the picture).

 

modbus-multiple-slaves.png

 

 

 

0 Kudos
Message 7 of 14
(1,820 Views)

Thank you! I will try that. The yellow borders are because I unchecked "View as Icon" as it is easier on my old eyes that way. Not sure if trying to create two instances using the same COM port will cause a conflict when trying to open the second one. With what I have now, in order to see the  second unit, I have to stop it, change the ID, then start it again. I have to stop it as the COM port isn't released until the While Loop completes execution. Thanks again for the assistance!

0 Kudos
Message 8 of 14
(1,816 Views)

think I have used two devices on the same COM port. The NI Modbus Library should be smart enough to deal with it as multidrop is part of the Modbus specification (assuming it is 485 wiring, not 232). If you do have issues with it, there is another Modbus Library other people on the forums use called Plasmionique

 

https://www.vipm.io/package/mb_master/ 

 

 

0 Kudos
Message 9 of 14
(1,813 Views)

You can just change the address with Set Unit ID.vi

 

cordm_0-1677184099173.png

 

0 Kudos
Message 10 of 14
(1,779 Views)