LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus Slave with multiple slaves in one vi.

Solved!
Go to solution

I think your task is complicated, but doable.

 

I found my library and dug into.  I think it will be impossible to do what I though about just duplicating libraries.  There is too much interaction of multiple reentrant VI's and dynamically called VI's, but that they need to share the same serial port means they would step all over each other.

 

I drilled down and found the VI that is doing all the "Serial Receive" work.  It is called MB Serial Receive.vi.  Study that one.  It is design to look for messages directed to a single slave ID on a single serial port.  With not too much modification, you can probably get it to react to one or more slave addresses on that same serial port. (trace where the slave ID data wire goes to.)

 

If it gets a message for any one of the slave ID's you feed to it in an array, then allow the loops to end and report back the Modbus data value and the slave ID that it matched.

 

The NI examples use other VI's to update an action engine "register manager".  But that really only handles the registers on a single "slave".  I think you could write your own functional global variable that can handle the data storage for multiple registers across multiple slaves.

 

The other VI's to study are

MB Update Registers.vi

MB Serial Slave Communication.vi

 

It's doable and if this was my own project, I'd tackle it.  If you take this on, make sure you do a Save As with a new name for any of the NI Modbus libraries you want to use but need to modify.

 

Message 11 of 22
(3,806 Views)

Cannot see any screenshots

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 12 of 22
(3,807 Views)

What would you like a screen shot of? i only said if something was unclear i could add screenshots.

0 Kudos
Message 13 of 22
(3,798 Views)

@RavensFan,

 

I will give it a shot and see if i can manipulate the slave id. 

 

I've never worked with global variables before and i wasn't able to learn much from the built in NI examples so i'm unsure of the process to create a global variable to handle the data for multiple registers

Message 14 of 22
(3,797 Views)

Not a global variable which is a specific LabVIEW entity.

 

 I'm saying there is a functional global variable which is a VI with a specific kind of architecture where data is stored in uninitialized shift registers.  They are also know as Action Engines particularly when extra functionality is build in.

0 Kudos
Message 15 of 22
(3,793 Views)

i just tried running 2 vi's connected to 2 different serial ports with 2 differnt slave id's and i ran into the same problem, i was atleast hoping this would work with differnt port becasue once the full system is online i will be connected to 30 different serial devices.

 

I'm still working on drilling down the modbus libraries to see if i can manipulate them in such a way to allow this.

 

Again any assistance you guys can provide is very much appriciated.

0 Kudos
Message 16 of 22
(3,791 Views)
Solution
Accepted by picky33

Hey Guys, I appreciate all the help.

I found a solution and i wanted to post wanted to post my solution here just in case someone in the future runs into the same problem i did, they will be able to find an answer.

 

Here is a quick rundown of the problem again

Problem: I was tasked with emulating an entire engineering plant (pumps, valves, fans, engines, etc) I had to pretend to be all the pieces of equipment so the PLC's which will be actually controlling the equipment can be tested and debugged prior to being sent out to the real world and installed. 

 

All the equipment i had to emulate, communicates over serial (RS485) using the Modbus Protocol

 and some the equipment had multiple slaves in them, that needed to communicate over one RS485 cable. by default, you can only communicate with 1 serial port and 1 slave ID at a time.

 

The Solution:

The first thing i did was get a more modern embedded controller for my PXI rack. this came with LabVIEW 2014, which was new enough to allow me try 3rd party Modbus libraries. I was not able to get any of these to work out of the box. I also tried the latest NI Modbus library but had the same issue. The solution came when one of the third party companies I reached out too, suggested I try a virtual serial port emulator. After trying a few emulators i discovered Virtual Serial Port Driver Pro by Eltima. 

 

I used that software to merge the real port with 2 virtual ports. This way each Slave ID would connect to a different virtual port and both data would go out over the real port. LabVIEW could not connect to the real port because the Eltima software was using and that’s why I had to create a pair of virtual ports.

 

Other possible solutions i was looking into but stopped perusing was a serial to Ethernet idea where i would create a virtual Modbus TCP server on the console and then all the Modbus programs would connect to it over TCP and then all the data would be forwarded to the serial port and vice versa. I had some leads and idea's but i was never able to pursue it.

0 Kudos
Message 17 of 22
(3,766 Views)

@RavensFan wrote:

The newer modbus libraries build in the slave address when you create the connection and use the class wire to distinguish between the different connections.

 

If so, you'll create two connections, one for each slave.  Just keep the class wires separate, but use the error wire to determine order of execution when you alternate between each device/connection you are talking to.


For multiple slaves on the same COM port, is a New Serial Master required for each connection?   

 

Does the library handle/prevent any conflict with trying to access the same COM port if it's already open?  

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 18 of 22
(3,668 Views)

I have a test system that has 12 Modbus devices on one RS485 using a USB to RS485 adapter that installs a virtual serial port.

 

I am using the NI Modbus library inside my VI's

 

 I initialize all my devices using a For Loop, the class wire then becomes an array.

m1Capture.PNG

 

Taking measurements uses the same method and auto indexing steps through all 12 devices 

m2.PNG

 

If I only want to measure from one device I just select it first

m3.PNG

 

========================
=== Engineer Ambiguously ===
========================
Message 19 of 22
(3,661 Views)

@RTSLVU wrote:

I have a test system that has 12 Modbus devices on one RS485 using a USB to RS485 adapter that installs a virtual serial port.


Thanks for the reply on an old thread.      🙂 

 

I've got a similar hardware setup, and I believe this is exactly what I was looking for. 

 

Thanks again.   

---------------------
Patrick Allen: FunctionalityUnlimited.ca
0 Kudos
Message 20 of 22
(3,648 Views)