LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local variable/global variable/ FGV: when to use them? ( Scenario outlined)

Solved!
Go to solution

@crossrulz wrote:

@Yamaeda wrote:

So, AE with Init, Get queue ref, Queue data, Close

Init AE at start of program

Use Queue data whenever you want to update something

A loop which uses 'Get queue ref' to actually update the indicator

Close ref as you exit program.


I have learned over the years that this is not quite a good setup.  You should only have 1 loop that is a consumer of the queue.  So I do not even have the Get Queue Ref.  The consumer calls the Init and gets the queue reference as part of that.  It can then dequeue for the lifetime of the process.  The consumer should then also be the one calling the Close.  So what this points to is a library for the Consumer.  The AE should be a private member of this library and you make public message VIs that call the Send case of the AE.  This way, the reference is protected and the messages that can be sent to the consumer are explicitly defined.


You're right, the last time i used it i didn't have a "get ref" but just reused it from Init. I didn't use a library but it can clean some stuff up. 

/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 21 of 23
(68 Views)
Highlighted
Solution
Accepted by rajiv85

@rajiv85 wrote:

What I tried: I put the controls inside events: value change triggers update of global variables. These global variables I then use anywhere. However from within a subvi if I need to write to the global variable, how to change the value on the Front panel: guess I will need to update a local variable. Is there a better way? 


Going back to reread the thread...

 

What I like to do is have 1 loop completely dedicated to the GUI.  This loop is just a While Loop and an Event Structure.  Use loops to control the state of your motor, DAQ, etc.  The GUI loop can send messages to the other loops to start, stop, etc via Queues, Notifiers, or User Events.  If a loop wants to send updates to the GUI, they use a User Event to send that update to the GUI loop, where the Event Structure will handle it.  You can do whatever you wish with that update (update an indicator, update a progress bar, ignore it, etc).  This will decouple your GUI from the logic of the other parts of your application, increasing reusability.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 22 of 23
(55 Views)

Thank you very much!!! This was very helpful!

0 Kudos
Message 23 of 23
(50 Views)