LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adapt My Modbus Serial Master VI to Control Multiple Devices

Hi this is more of a feasibility discussion, so if you have an answer to any of the questions I am about to ask then please write in. I am trying to control multiple devices using a Modbus serial master controller VI. I know that I need to identify each device by their individual serial ID number, but I am wondering what is the best way to control that process to allow me to switch between which sensor I am reading. Basically, I want the master program to be reading the holding/input registers from multiple devices while I choose which sensor's values show up on the graphs. With that in mind, I have a few questions about which approach makes the most sense and is more reasonable to attempt to implement.

 

1) Should I use an array to store the ID numbers?

2) Should I use the attached VI as a sub VI in another project and call it for each COM port connection I have?

3) If #2) is true, how would I determine which sensor's values to show. 

 

I know there are other questions I have not asked, so please write in if you have any suggestions. Thanks for your time.

 

 

0 Kudos
Message 1 of 12
(2,068 Views)

@vanceblake wrote:

Hi this is more of a feasibility discussion, so if you have an answer to any of the questions I am about to ask then please write in. I am trying to control multiple devices using a Modbus serial master controller VI. I know that I need to identify each device by their individual serial ID number, but I am wondering what is the best way to control that process to allow me to switch between which sensor I am reading. Basically, I want the master program to be reading the holding/input registers from multiple devices while I choose which sensor's values show up on the graphs. With that in mind, I have a few questions about which approach makes the most sense and is more reasonable to attempt to implement.

 

1) Should I use an array to store the ID numbers?

2) Should I use the attached VI as a sub VI in another project and call it for each COM port connection I have?

3) If #2) is true, how would I determine which sensor's values to show. 

 

I know there are other questions I have not asked, so please write in if you have any suggestions. Thanks for your time.

 

 


I did a project that has 12 power analyzers.

 

Since all 12 instruments were identical I used a very simple approach.

 

First I made a set of VI's that use the Modbus library for my specific tasks

 

I set meters up to use sequential Unit ID's, so I could initialize all my meters using a For Loop

 

MB1Capture.PNG

 

Inside my Init Serial Master

MB2Capture.PNG

 

This is how I take measurements, again since all the meters are taking the same measurements I used a For Loop. The "Address" indicator is normally hidden and can be toggled for troubleshooting with a key press.

MB3Capture.PNG

 

Inside my Get Primary Measurement VI

MB4Capture.PNG

 

Your program architecture is a little messy but at least it's a state machine... So it should not be too much work to modify it to something like I did. You might what to think about making sub-VIs for all your Modbus interactions too.

 

========================
=== Engineer Ambiguously ===
========================
Message 2 of 12
(2,041 Views)

Hi RTSLVU,

 

Thanks so much for this thorough response and outline! I just have a few clarification questions.

 

1) The sensor have distinct ID numbers, however the registers I will be reading are the same. Since each sensor has its own serial number that is stored in a register, should I have a step that reads all the serial id numbers for each sensor and establishes a COM port connection with each one?

2) How would graphing work in the setup you've diagramed below? I don't/can't show all the graphs at once, but I do need the ability to select any sensor and have its information show up on the graphs in the main VI.

3) You recommend that I should make a sub VI for each Modbus interaction, so would that mean using a nested while loop to continuously read a specifc register or do the Sub VIs stay in the same main VI while loop?

4) What would be the best way to save the data to a file for each sensor I am reading?

 

Thanks again for your help!

Vance

0 Kudos
Message 3 of 12
(2,014 Views)

@vanceblake wrote:

Hi RTSLVU,

 

Thanks so much for this thorough response and outline! I just have a few clarification questions.

 

1) The sensor have distinct ID numbers, however the registers I will be reading are the same. Since each sensor has its own serial number that is stored in a register, should I have a step that reads all the serial id numbers for each sensor and establishes a COM port connection with each one?

2) How would graphing work in the setup you've diagramed below? I don't/can't show all the graphs at once, but I do need the ability to select any sensor and have its information show up on the graphs in the main VI.

3) You recommend that I should make a sub VI for each Modbus interaction, so would that mean using a nested while loop to continuously read a specifc register or do the Sub VIs stay in the same main VI while loop?

4) What would be the best way to save the data to a file for each sensor I am reading?

 

Thanks again for your help!

Vance


  1. I don't understand what you are asking... You need to open a "serial session" for each device and you can open all of your serial sessions at once with a For Loop.
  2. Well that's up to you. In my case I have a tabbed interface so the end user can tab through each device and see that devices readings in graphs and tables. Plus a "main" tab that shows the measurements we are most interested in for all devices on one screen.
  3. It depends on your measurements and how often you need them updated. In my case I am retrieving the same register values for all 12 devices so I made a Sub-VI to get the registers I need and put it in a For Loop 
  4. Honestly, I use a simple tab delimited text file for all my data files.
========================
=== Engineer Ambiguously ===
========================
Message 4 of 12
(2,005 Views)

Hi RTSLVU,

 

1) I understand what you mean about opening a serial session with each device using a for loop. But I could be working with a variable number of sensors, so even though I know the upper limit (247) I won't always be using all 247 connections. How can I make my program work with however many connections I have?

 

I guess I could have the code check for all 247 connections and then count the ones that are present and update the code's for loops that way, but is that the most effective way to accomplish my goal?

 

1 cont) Also, unlike your case where the sensors were identical so you named them numerically, each sensor I have has its own unique serial ID number already stored on one of the sensor's holding registers. So I was aiming for a system that opens the session and reads that register for the ID number at the same time. 

 

Thanks again!

Vance

 

0 Kudos
Message 5 of 12
(1,999 Views)

@vanceblake wrote:

Hi RTSLVU,

 

1) I understand what you mean about opening a serial session with each device using a for loop. But I could be working with a variable number of sensors, so even though I know the upper limit (247) I won't always be using all 247 connections. How can I make my program work with however many connections I have?

 

I guess I could have the code check for all 247 connections and then count the ones that are present and update the code's for loops that way, but is that the most effective way to accomplish my goal?

 

1 cont) Also, unlike your case where the sensors were identical so you named them numerically, each sensor I have has its own unique serial ID number already stored on one of the sensor's holding registers. So I was aiming for a system that opens the session and reads that register for the ID number at the same time. 

 

Thanks again!

Vance

 


I do not understand what you are saying. Do you have (up to) 247 unique Modbus devices, each with multiple sensors?

 

I do not understand what you mean by each sensor having it's own serial ID. Is that is not the same as the Modbus Device ID?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 12
(1,994 Views)

That's the thing I could have that many, so I need to be able to handle that many. And maybe we are talking about the same thing. The modbus unit ID is 21, but each sensor has its own unique serial number that is stored in a holding register. I read that value to get the serial number value in the code I originally posted. I don't think that is the same as the unit ID, but I could be wrong? 

 

Also, you have inputs to your Init Serial Master sub vi. Could explain how they are being used, and what they connect to within the serial master vi? I cannot follow the process clearly with my novice eye. I'm trying to break this job in small pieces and I want to start by establishing a connection with just two sensors over 2 COM ports and then reading a holding register and some input registers from both sensors. 

0 Kudos
Message 7 of 12
(1,990 Views)

I took another look at your code snippet; are all your devices sharing the same com port? I see the input wired to visa resource name is a constant COM2? I ask because the sensors I am working with do not share COM port. I connnect to them using 2 separate USB cables, therefore each connection uses a COM Port. 

 

 

0 Kudos
Message 8 of 12
(1,950 Views)

@vanceblake wrote:

I took another look at your code snippet; are all your devices sharing the same com port? I see the input wired to visa resource name is a constant COM2? I ask because the sensors I am working with do not share COM port. I connnect to them using 2 separate USB cables, therefore each connection uses a COM Port. 

 

 


I am sorry I do not understand your test setup at all.

 

  1. Please describe it in detail.
  2. What Modbus devices are you using?
  3. How many?
  4. What sensors are you using?
  5. How are they connected?
  6. What are they connected to?   
========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 12
(1,946 Views)

No worries, I figured that was the case because I haven't been able to find any examples of what I am trying to do online, which means I am doing something completely new (highly unlikely) or not explaining it to google and this forum well (occam's razor).

 

1) I am trying to sample CO2 gas parts per million from the air. I use the modbus library to read input and holding registers, and then I have different modes for calibrating the sensor as seen in the VI attached to  my orignial post. 

 

2) I am using T6713 sensors from Amphenol AS Telaire. They use modbus serial communication, but idk know if that is a Modbus device...

 

3) Currently, I am trying to connect with 2 sensors in the same VI for simplicity. However, I will need to connect with the maximum number of 247 going forward, so I am searching for solutions that can adapt to the number of sensors present during any one monitoring session.

 

4) I am using T6713 sensors from Amphenol AS Telaire. 

 

5) The sensors are connected using TTL-234X-3V3-WE usb to uart cables that I connected to my computer using an Atolla usb hub for extra usb ports. Each cable connects to one usb port. 

 

6) The sensors have a TX/RX pins, plus a power pin and and ground pin that connect to the TTL cables.

0 Kudos
Message 10 of 12
(1,942 Views)