LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Single Modbus TCP Master reading multiple Modbus TCP slaves

I don't know if my examples just aren't populating my LV environment Help section, but the example finder isn't turning up many results for example projects utilizing a Modbus TCP master vs. multiple Modbus TCP slaves. I'd like to see some NI or 3rd party examples of how management of the connection objects and how concurrent use, if any, is handled in communicating with multiple devices at once if that is possible. Right now I have 3 Modbus TCP Init Master VIs in use in separate threads but only one of them is reliably working, and I am beginning to wonder if it needs to all be handled in one loop with an array of connection objects used instead of true parallel execution, if that makes sense. 

 

Using a cRIO-9068 as my Master device running RT 2015 and developing on an old Win7 Professional SP1 machine utilizing LV 2015 Professional SP1.

0 Kudos
Message 1 of 7
(524 Views)

Usually I use a single master per port for reading and iterate over the IDs in a loop, since communication on the wire must be sequential anyway. My devices are all the same, it might be more convenient to use multiple loops if you use different devices. If you want multiple threads, you can set up the master once and wire it to the each loop. Access to the visa ressource is internally restricted with a mutex.

modbus rtu master multiple slavemodbus rtu master multiple slave

The VI is backsaved to LV2015.

0 Kudos
Message 2 of 7
(489 Views)

It is true for serial that you use one loop. However with modbus TCP you can use one loop for each TCP slave. If a tcp slave is actually a gateway to rtu devices use one loop for that device and address each slave at a time.

Make sure any vi that use modbus read or write functions is re-entrant or your loops will block. 

I use multiple loops with any modbus top devices and nothing blocks.

0 Kudos
Message 3 of 7
(478 Views)

Oops, I totally blocked out the word TCP, sorry.

0 Kudos
Message 4 of 7
(474 Views)

So you use something like Create Master Instance (TCP) in each loop, then synchronously read, then Close on shutdown? I noticed the Creates/Closes are usually non-reentrant in MB TCP libraries, but I assume that is a special case so as not to muck up the resource allocation. 

 

I can't seem to make a connection to some of my slave TCP devices and wasn't sure if Create Master Instance VI was possibly supposed to be run just once or could be done in parallel.

 

multi.png 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

One of my (TCP) slaves is also indeed a gateway with 2 RTU devices behind it, but I'm not sure what happened with that one. I probably need to plug into the RTU slave devices and see if they've actually retained their network ID.  The library above doesn't seem to have an accessible/public Set Unit ID, or at least that I can see. 

0 Kudos
Message 5 of 7
(441 Views)

Still interested in some examples if any are out there. Would I be better off organizing my connection ID objects and running them in the same loop if I’m not getting responses from the two loops above? The last errors were timeouts, but the devices are up and running and respond to pings / web interface access. I would also be particularly interested in any recommendations of specific modbus libraries, 3rd party or otherwise, if anyone has had a good experience with them in similar use cases with multiple tcp slaves / tcp slaves acting as RTU gateways. 

0 Kudos
Message 6 of 7
(405 Views)

Still very new to this but I have found the Modbus I/O Server to be fairly easy to use but it does require having the DSC module.

0 Kudos
Message 7 of 7
(379 Views)