LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Example on how to set an array as a Global Variable (LV2?).

Hi,
I am new to Labview and recently I have been given the task to evaluate labview as our new data acquisition software.
Let me briefly describe what we currently have set-up and what I need to accomplish.
We have developed several dll's (created in C) to access the shared memory where the data is located and I have imported these dll's in labview and read them in as one big 1-d array. (There are several 1-d array's that I import but I will try to keep things simple by starting out with one)
Now I want to share this array to several sub-vi�s, which will I am planning to call from the run-time menu. How can I assign this array globally so that I can access it from any sub-vi?

For example, lets say
that my array name that I imported is called ARRAY1 (name created using the local variable option). ARRAY1 is a 1-d array with 10000 elements.
I would like to access only a few elements of this array on another sub-vi by its name and index number i.e. ARRAY1[10], ARRAY1[20].

Please let me know if you need any more information.
I would really appreciate it if someone can help me out.

Thanks

Nish

My E-mail: nishchey.chhabra@ps.ge.com
0 Kudos
Message 1 of 10
(8,202 Views)
You can create globals of arrays just by selecting create globals...but globals are not very efficient to use, use a functional global instead (VI holding the data in a shift register etc...search for functional globals here on the zone). I have attached an example, you can use a 2D array to hold more than one array, or have more than one array in the same VI...or duplicate the VI and use it for other arrays. Just run the example.vi
Message 2 of 10
(8,202 Views)
See attached example for a general idea.

1) Connect ARRAY1 to the "Write" input and call the vi with "Initialize" mode.

2) Call the vi in "Read one" mode and define "Index" to read one element
...
Message 3 of 10
(8,202 Views)
HI Nish,

I would recomend you start with either Mads or JB's example and go one step beyond.

Add another case called "Refresh from DLL" and drop your dll in that case.

THis way your array gets copied ONE TIME from the dll into the shift register.

After that you will be able to "operate in-place" to yur heart's desire.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 10
(8,202 Views)
Ben,
Thank you for your advice. I am planning to write a small program based on Mads or JB's example.
I just wanted to make sure if I understood your suggestion correctly. I am planning to refresh the VI's (read from the dll) at least 10 times a second.
So that means that I will have to read the data from the dll at least 10 times, if not more, a second. Will your suggestion still apply to my scenario?

Once again I wanted to thank all of you for helping me out. Really there is great support for labview and I hope that this works out for us.
0 Kudos
Message 5 of 10
(8,202 Views)
Yes that is the way to go.

As long as you leave the VI set as "non re-entrant" (the default) this should work out fine. THe beuty of this technique is that while the "refresh" is happening, any other threads attempting to acess the data will wait until the update completes.

Please be for-warned;

If the refresh takes a long time to complete, the other threads will be blocked when they attempt to acess the LV2.

Regarding thanks;

Many of us work for peanut (i.e. stars).

If you find JB's and Mads example helpful, give em some stars!

Post a copy of your LV2 (along with the dll) and I (if I get a chance) will look it over to see if we failed to mention anything.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 10
(8,202 Views)
What is the "ps" part of GE?

I am currently working a project for GET. Are you connected?

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 10
(8,202 Views)
Ben,

Once again thank you. I work for GE Power Systems in Greenville, SC.
Currently, all the dll's that we wrote exists on another PC, which is busy for development purposes. In the meantime I am trying to write as much labview code that I can on my laptop and when I get a chance I will import my code to the PC that has all the dll's. Instead of creating a 1-d array from the dll I am creating a 1-d array using the for loop. That 1-d array will be written to the LV2GlobalArray.vi (example that JB wrote- unfortunately I have 6i version on my laptop that’s why I can’t open Mads example).
All of this will be done on the main vi. Then using the “open_panel.vi” I will open another sub-vi and I will
read different elements of the 1-d array using the read mode in the LV2GlobalArray.vi. This way I can import this LV2GlobalArray.vi to other sub-vi’s and read data from the element that I am interested in.
As I mentioned earlier, we are still evaluating labview and if you are interested I can write-up small summary of the items that we want labview to accomplish.

Thanks
Nish
0 Kudos
Message 8 of 10
(8,202 Views)
Attached is the VIs in LV 6i format...The advantage of those VIs is that they allow you to read and write subsets of the array, not just one element at a time.
Download All
0 Kudos
Message 9 of 10
(8,202 Views)
Mads,
Thanks for the examples. I tried to open them up but it still comes up with the error "VI version (6.1) is newer than Labview version (6.0.1)"
0 Kudos
Message 10 of 10
(8,202 Views)