LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Which is the best method to access variables?

Hello,
        I have a VI having number of array of boolean and numeric controls and indicators. I have two threads running one is accessing all controls and indicators directly. Other thread is going to put values in controls based on values read from text file. Which is the best method to access variable - Is it through local variables or VI server reference->Value.? Any other suggestion with explanation is highly appreciated.......Best Regards.
0 Kudos
Message 1 of 8
(3,301 Views)
Please follow this link for further instructions....

hope this helps,
Norbert
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 8
(3,298 Views)
Hi 12345qwer…,
i think you misunderstand something, the wire is the variable. Smiley Wink Depending on what you try to do, i recommend to use a loop with shift registers to store your data. The controls or indicators are only to insert some data or to show it to the user.
 
Mike
0 Kudos
Message 3 of 8
(3,297 Views)
Do a search on Functional Global Variables and Action Engines.
 
RayR
0 Kudos
Message 4 of 8
(3,289 Views)


12345qwertt wrote:
        I have a VI having number of array of boolean and numeric controls and indicators. I have two threads running one is accessing all controls and indicators directly. Other thread is going to put values in controls based on values read from text file. Which is the best method to access variable - Is it through local variables...

SInce you list local variables as an option, I must assume that both "threads" are running in the same VI (e.g. two parallel while loops). Is this correct?
 
In this case, you should go with the local variables.
 
Still, you might want to show us your code so we can better understand what you are doing and how things are arranged, because there is always the problem of race conditions. For example what good is a control, if the user has no real control over it because the values are programmatically overwritten at regular intervals. If you just e.g. allow the user to reset the controls to a new set of settings from a stored file, locals are good.
0 Kudos
Message 5 of 8
(3,269 Views)


altenbach wrote:


12345qwertt wrote:
        Which is the best method to access variable - Is it through local variables...

SInce you list local variables as an option, I must assume that both "threads" are running in the same VI (e.g. two parallel while loops). Is this correct?
 
In this case, you should go with the local variables.


I'd be careful with the use of Locals..  THe problem is not the Local Variable itself..  It is in how it is used and usually abused..  The biggest problem is scalability... People add more functionality, and constinue to add Locals to the point that the sw is unreliable (usually race condition).
 
If you do have to pass data between two loops, I would suggest looking into Queues..  And possibly Notifiers.. 
 
There are many options.  As Altenbach mentionned, it is easier after seeing your code and understanding what you are trying to accomplish.
 
RayR
0 Kudos
Message 6 of 8
(3,260 Views)
Thank you all so much for quick response with some valuable info......The threads are running in the same VI. My thought is since local variable is a copy by value and reference->Value is reference to value, it would be better if I go with reference->value. Eg: I have 25 numeric controls. In this case I can create 25 references and only 1 value property node. This would save the memory compared to local variables. I don't know the race conditions possibility...Best Regards
0 Kudos
Message 7 of 8
(3,247 Views)


12345qwertt wrote:
Eg: I have 25 numeric controls. In this case I can create 25 references and only 1 value property node. This would save the memory compared to local variables. I don't know the race conditions possibility...Best Regards

Then group your controls into arrays or a cluster.
 
If you update dozens of controls via value property nodes, you should defer front panel updates until al controls are updated.
0 Kudos
Message 8 of 8
(3,242 Views)