LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

collecting data from register via MODBUS into array

Solved!
Go to solution

Hello there,

 

I have trying loads of different approaches to do something as simple as collecting a value(an U16 value) of a register(via modbus) and store it in a simple 1D array indexed in every iteration by means of a for loop.

 

THe example that I thought it could fit into my application is attached, but it does not collect anything.

 

What do I do wrong??

 

In the image attached, please see below, the register contais a 183 value on every interation(two in this example), and nothing is stored in the Array!

 

 

Thanks in advance.

 

attempt_collecting_data.gif

0 Kudos
Message 1 of 7
(2,830 Views)

Hi Rcano,

 

where exactly are you collecting your data?

All you do is reading a ModBus message, indexing a scalar value from an array of "Registers" and typecasting this scalar to an array - in each iteration. No collection of data, only conversions…

 

In the image attached, please see below, the register contais a 183 value on every interation(two in this example), and nothing is stored in the Array!

- we do not know which index you try to read with IndexArray

- after indexing you get a zero, either by indexing the wrong value or a non-existing value

- there is something stored in the array as the probe window clearly shows: an array containing a single element of value zero!

Lesson learned: when probing you should probe all relevant wires!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(2,813 Views)

Hi GerdW,

Sorry if I was not clear enough in my previous post.

attempt_collecting_data_2.gif

I am collecting the value of one register (fixed addresses) from two modbus devices sequentially addressed with the "for loop".

(BTW that loop is excuted inside of a state machine)

 

I am trying to use the iteration number of the for loop to index an array and store those two values in it.

 

I have been trying all ways I can possible think, and I am not able to do such as simple thing.

 

 

 

 

0 Kudos
Message 3 of 7
(2,797 Views)

Hi Rcano,

 

please go through beginner courses offered by NI and read the labVIEW help. Learn things like "auto-indexing"!

 

You need to index the first value of your "Register" data and wire that value to the FOR loop border. The loop will create an array by AUTO-INDEXING…

 

I am trying to use the iteration number of the for loop to index an array and store those two values in it.

Right now you don't use the iteration number (and you don't need to). You would use it when you have a pre-defined array in a shift register and take the function ReplaceArraySubset to replace values in that array. This is a basic programming technique in LabVIEW that you should have learned in those beginner courses…

 

I have been trying all ways I can possible think, and I am not able to do such as simple thing.

You missed autoindexing as the simplest solution. That is tought in the beginner courses offered by NI.

 

Did I mention those beginner courses offered by NI (for free!)?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(2,791 Views)

Hi GerdW,

 

Thanks for looking at it.

 

Well thanks for your suggestions but I have read through all that.

 

The issue is that the data to be collected, is not available until the "for loop" is executed. I also always thought Auto indexing is not so efficient as pre-defining the dimensions of the array in advance. This is just one state of a larger state machine which uses high resources.

 

Please see below the thread below,  I was actually going down this route.

 

http://forums.ni.com/t5/LabVIEW/MODBUS-6101-Time-Out-Error/m-p/2151812/highlight/true#M694759

 

I will wire the array outside the for loop and see how relaible is all put together.

 

Again thanks for your comments

 

Regards

0 Kudos
Message 5 of 7
(2,782 Views)
Solution
Accepted by topic author Rcano_1982

Hi Rcano,

 

I also always thought Auto indexing is not so efficient as pre-defining the dimensions of the array in advance

- Autoindexing in a FOR loop is the most efficient way to work with arrays…

- You did not predefine your array size, atleast not in the snippet you have shown…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 7
(2,779 Views)

Thanks for your comments,

 

I think I am in the right direction now.

 

Regards

0 Kudos
Message 7 of 7
(2,772 Views)