LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Viewing and Logging Multiple Modbus Holding Registers Address for Micro Motion Flow meters using Labview

Hi, 

 

I am working on a project where I am working with 2 Micro Motion Flow meters. I would prefer to use modbus on this instead of analog output signal. I connect modbus through Serial Port on my laptop.

 

I read through the forum and downloaded examples posted, and watched youtube videos. I am able to see data from a single address in the holding registers. However, I am not sure how to move forward to view multiple other addresses, and also the second flow meter. Then log this data. 

 

I built the attached VI following steps in a youtube video. I would appreciate any help I can get on this. 

 

Thanks.

0 Kudos
Message 1 of 7
(288 Views)

When you talk about multiple addresses,  are you talking about multiple holding register addresses?  Or multiple slave addresses?  Or both.

 

If you are using multiple slaves, then you use multiple Create Serial Master subVI's.  You can put them in a For Loop auto-indexing on an array of slave addresses, it will then output and array of master class objects.  Later you can do the Read's on each of those array elements in a loop.

 

If you are talking about multiple register addresses, just put down additional Read Holding Register subVI's with the appropriate register starting addresses and quantities.

 

I'm not sure why you have all the additional array manipulation going on with the data you get back from the Modbus Read.  All of the that is being done internally by the Modbus library.  I can only guess that you wanted to visualize what the raw Modbus message looks like for debugging purposes.

Message 2 of 7
(248 Views)

There are VI's in the MODBUS library for reading or writing single holding registers and VI's for reading or writing multiple holding registers. The Read Multiple VI works by giving it a starting register address and telling it how many consecutive registers to read and returns an array containing the register values.

 

I know you are just starting to figure things out but take a step back and think about this from a higher level. Figure out the commands you are going to use most often and create your own set of VI's that use the MODBIS library to run the commands you need to read and write the registers.

 

========================
=== Engineer Ambiguously ===
========================
Message 3 of 7
(242 Views)

Thanks for the reply.

 

I am trying to read and log multiple holding registers from two separate slave devices. I have no idea what most of the components in my VI do. I have been trying to figure that out. My experience with LV has been just to build primitive read, visualize and log analog signals VI's.  

 

When I tried building one following the manuals on NI, I couldn't communicate with my devices at all. And this VI seems like its the only one that has communicated so far. I will go with duplicating the loop to get all the registers then log that.  

 

I was looking at the Raw data in HEX to compare with what I see on ModScan32 to verify that I am reading the correct register and value. 

 

 

0 Kudos
Message 4 of 7
(235 Views)

Okay to begin with you might want to read up on MODBUS as it is a little weird when you first start out. But in a nutshell to get reading out of your device you "read holding registers" to setup your device to so something you "write holding registers or coils".

 

Holding registers are basically memory address that store values. Since registers are often limited to 16 bit signed integers. To get precise values you often have to read multiple registers then convert and combine them. Your devices manual should have a register map and give you all the scaling and conversion information.

 

Multiple MODBUS devices are handled by the MODBUS library. Every device on the MODBUS should have a unique address (1-255)

 

I have a system with 12 power meters on MODBUS each is set to its own address and initialize them like this. 

M1Capture.PNG

This is what's inside "Init Serial Master"

M2Capture.PNG

 

For taking readings I built a set of custom VI's for my devices using the MODBUS library 

Here's an example that reads multiple holding registers 

M3Capture.PNG

What's inside "Get Primary Measurement"

M4Capture.PNG

 

========================
=== Engineer Ambiguously ===
========================
Message 5 of 7
(205 Views)

Hi RTSLVU, 

 

Thank you for your extensive reply. I have a whole lot of questions. And again I appreciate all the help with this. 

 

 

The second image is the standard create modbus instance sub vi. 

From your first image I am not sure about a few things. 

omerengineer_1-1615995800645.png

I believe 1 is a control for error. 

2- Number of devices? You said you have 12 devices. 

3- I dont know what this is or where it would go in the subvi? I am guessing Unit ID for the 12 devices. 

 

omerengineer_3-1616000831451.png

 

 

I couldnt get the controls in 4 and 2. And I believe 3 is Type Cast function as below. 

omerengineer_5-1616004352465.png

 

And for 1 I have no idea. When I placed constant it was orange and didnt have the x in the box. 

 

omerengineer_4-1616003393353.png

Here I am pretty clueless. I created a second event case. I am reading up on what these items are. 

Also when I use DBL in 7 I get broken wires. 

 

Thank you. 

 

 

0 Kudos
Message 6 of 7
(153 Views)
@omerengineer wrote:

Hi RTSLVU, 

 

Thank you for your extensive reply. I have a whole lot of questions. And again I appreciate all the help with this. 

 

 

The second image is the standard create modbus instance sub vi. 

From your first image I am not sure about a few things. 

omerengineer_1-1615995800645.png

I believe 1 is a control for error. 

2- Number of devices? You said you have 12 devices. 

3- I dont know what this is or where it would go in the subvi? I am guessing Unit ID for the 12 devices. 

 

  1. Yes that's just and Error Cluster constant. I don't like uninitialized shift registers unless I need it to be that way like in the case if an "Action Engine" or "functional global variable".
  2. That runs the For Loop 12 times initializing communications for all 12 of my devices on the MODBUS
  3. That is the instrument ID for all 12 of my devices. I take the iteration and add one, because MODBUS instrument ID0 is reserved for the MODBUSS master. I convert it to a U8 because I hate coercion (lazy) dots.  

omerengineer_3-1616000831451.png

 

 

I couldnt get the controls in 4 and 2. And I believe 3 is Type Cast function as below. 

omerengineer_5-1616004352465.png

 

And for 1 I have no idea. When I placed constant it was orange and didnt have the x in the box. 

 

omerengineer_4-1616003393353.png

Here I am pretty clueless. I created a second event case. I am reading up on what these items are. 

Also when I use DBL in 7 I get broken wires. 

 

Thank you. 

 

 


  • 4 is a typedef I created when making my "Get Primary Measurement" VI to make it easier to program. You will have to make your own as I doubt your instrument has any of the commands mine does.\
  • 2 shows up when you add a Conditional Terminal to a For Loop. Right click on the Four Loop boarder and look at the pop-up menu. Also this is set to "continue if true" the default is "stop if true" just like a While Loop
  • 3 yes combine the two registers and type cast to Single Precision but I also convert that Single to Double Precision because as I said I hate coercion dots.
  • Right click on a Constant and select "Representation" to change it from "Orange" to "Blue"
  • Also you can change the "Display Format" to display numbers in Hex instead of Decimal.
  • Enabling "Show Radix" will put the little 'x' indicator on the constant so know it's Hex or Decimal
  • My example look complicated but it's really not. Don't get hung up on the Arrays. I take several measurements in the inner For Loop. That builds a 1D array. Moving to the next instrument makes another 1D array. The outer For Loop builds a 2D Array out of the 1D arrays the inner loop creates and passes it on.
========================
=== Engineer Ambiguously ===
========================
Message 7 of 7
(149 Views)