LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Referencing data values

Solved!
Go to solution

I read in 2 excel sheets of data and create an array of objects dynamically that belong to a class. I want the front end to take in the 2 address' for the excel files and create the array in the background. I need all the other subvi's to have access to this array.  How do I use the created array in other subvi's without making copies? I do not want to create any controls or indicators so as to not clutter the front panel of the main vi. I tried creating vi reference of the various arrays (input data and array of objects) but they don't seem to transmit from one subvi to another.

0 Kudos
Message 1 of 10
(2,985 Views)

I basically want to connect 1 to 2 which are in 2 different subvi's. Connecting them directly or connecting the corresponding references to these arrays and using the property node to extract their value does not seem to do the trick.

Download All
0 Kudos
Message 2 of 10
(2,979 Views)
Solution
Accepted by topic author rohith2

For starters, get rid of all of the local variables. Since you created a class to work with the array just pass that wire through to your other code. Create accessors methods to retrieve the data from the array. If you need to branch the class wire because you will be passing it into different subVIs running in parallel, then you can put the array into a Data Value Reference and the actual array will be shared across the branched wires. This can cause race conditions but LabVIEW will protect the data so that only one task can modify it at a time. The race conditions would come into play if you needed to coordinate the updates to the data before reading them again in another task.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 10
(2,971 Views)

I agree that it does not make sense to have local variables anymore as the array is used in other subvi's. Is it necessary to have the accessor function in the same subvi as the one where the array is created? Or is it possible to pass a reference of the array to the accessor subvi? 

Furthermore, can I use local variable within the initialization subvi as the array is local to this domain or should I be using the acessor function for initializing the array?  

0 Kudos
Message 4 of 10
(2,956 Views)

I very rarely use local variables in my code. I generally only use them for UI specific code. What I was suggesting is that you create a class which contains the array. This gets created prior to starting your other parallel tasks or subVIs. Pass the class wire into all of the tasks/subVIs that need to access the array. The array itself is stored in a DVR. The DVR is part of the class private data. You have accessors in the class which can interact with the array. It can return the array if necessary, update it, etc. Have you subVIs use the accessor methods of the class that you passed. This should resolve your problem.

 

A more simplified solution is to use a Functional Global Variable (FGV) or Action Engine (AE) to store the array. Use this to access your array in the parts of your code that need access to the array. A FGV/AE is essentially a non-reentrant subVI with a while loop and an uninitialized shift register to contain your data. I personally do not use FGV/AE much anymore since most everything I do is class based.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 10
(2,946 Views)

Thank you for your input. I was curious about the array of class objects being a part of another class. I managed to create it and added vi for data member access. The vi's are access by elements. I wanted to load the excel sheet with the data to initialize the new class. I was wondering whether the class object need to be inside or outside the loops in file1. On a different note, I want this initialization to occur only once when I run continuously, but if I link it to an event structure, my subsequent subvi's do not seem to run continuously. They expect a value change in the event structure. This happens even if any of the subvi's have an event structure. Any work arounds for this? Do I have to create while loops that trigger on events like you previously suggested?

Download All
0 Kudos
Message 6 of 10
(2,907 Views)

I created a state machine and that seems to have solved the event trigger and order of execution issues. I still need answers to my first question though regarding image 1. Thanks! 

0 Kudos
Message 7 of 10
(2,902 Views)

You need to post more of your code then a few static pictures. The pictures you posted don't provide enough information to see what you are trying to do and therefore I can't really provide you with helpful information.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 10
(2,885 Views)

Sorry about that, I have included the files that I am concerned about. (I had seen in the past that the class files don't like changing location and there might be an issue in opening those).

 

I have a BitClass that contains a bunch of properties. The BitClassArray is an array of BitClass objects. The "Write Element of Array" is an accessor function to BitClassArray, that provides access to the array per element. 

 

Under TOP2 state "Create array", the subVI "CreateObjArray" passes single BitClass element inputs one at a time to the Write Element accessor to populate the BitClassArray. This subVI was the image1 that I attached in the previous post. I was wondering about the location of the BitClassArray reference inputs to its Write accessor, whether it made a difference if they are inside or outside the for loops.

 

PS: Hopefully, I can access the BitClassArray in different states based on the flow of the software. Also any comments on the overall architecture would be greatly appreciated.

0 Kudos
Message 9 of 10
(2,871 Views)

The BitClassArray inputs/output location definitely matters - the class is by value, not by reference - so you are losing the classes you put it in each iteration, aside from the last. Move the input/output to outside the loops, and use shift registers on both the inner and outer for loops to pass the updated class into the next iteration of the loop. 

 

Hard to comment on the architecture further without knowing how you are using the classes. One item - in your 'Update Array' state of the state machine, add an event case structure to handle the user input, and get rid of the loop wait. I would also change the name of that state to 'Idle' or something similar to make it more clear you are really just waiting for user input in that state. 

 

An oh, when uploading files, please put everything in a single directory (preferably with a project file) and zip up the entire directory - makes it much easier for others to download the files and open up your code. 

0 Kudos
Message 10 of 10
(2,864 Views)