Discussion:
How to use functional global with a large amount of variables?
(too old to reply)
geno13
2008-08-04 19:40:05 UTC
Permalink
Hi all, I'm currently developping a LV program which control and acquired data from a device. Up to now I used global variables ( very conveniente to use for experimental parameters). But now my program is become to be too large and I have too much "global" variables to continue to use a global.vi. I'm wondering if functional global can help me. If someone has an exemple of how use functional global with a large amount of variables...thanks
MikeS81
2008-08-04 19:40:06 UTC
Permalink
Hi geno13, one solution for you could be to use a global functional variable (action engine) with clusters. Use clusters to bundle your data and store it in shift registers.Mike
JoeLabView
2008-08-04 20:10:05 UTC
Permalink
Yes, Functional Global(s) may be able to help you, but you may fall also into the same (or similar) trap.
However, what you could do is to use Functional Globals that contain clusters which group data together.
But before you code too far, why are you using so many Global Variables (globals) in the first place?  Maybe there are better alternatives..  I often see people over using Globals and Locals when there is no need to do so.
Is it possible to show your code?
R
Ben
2008-08-04 20:40:07 UTC
Permalink
yes sharing your code will let us supply better suggestions.
I seldom use AN&nbsp;<a href="http://forums.ni.com/ni/board/message?board.id=170&amp;thread.id=240328&amp;view=by_date_ascending&amp;page=1" target="_blank">Action Engines </a>(Functional globals) with a large amount of variables unless they are related in some way. This decision only comes after a lot of thought about who needs to access them and how the various fields interact. Once I have completed all of that work and decide I have to group a set of variables together and have ruled out using queues, only then will I create a cluster for that data structure and develop the AE. Whenever possible put un-related values in distinct AEs.
Ben
JoeLabView
2008-08-04 22:10:22 UTC
Permalink
I agree with Ben.
Using queues is better than a number of Globals or Action Engines (Functional Globals).&nbsp; If you need to pass data to a sub-vi, you can simply wire the queue out to a queue control of a sub-vi, or a reference.&nbsp; See attached example of passing data to a sub-vi using a queue.&nbsp; The example is an extremely simple, undocumented tid-bit of code that sends the loop count to the consumer VI.
Run the main program called QueueProducer.vi.
R
&nbsp;


QueueProducer.vi:
http://forums.ni.com/attachments/ni/170/346489/1/QueueProducer.vi


QueueConsumer.vi:
http://forums.ni.com/attachments/ni/170/346489/2/QueueConsumer.vi
geno13
2008-08-05 14:40:06 UTC
Permalink
thanks for your replies. my program has to control 5 devices with many parameters ( voltage, frequency, power... arround 50 parameters up to now). send or read parameters of these devices is very simple but some times one parameter from device A has to be send to device B (conditionnal parameters)up to now I used global variables because I can have access to them at any time.I didn't know the concept of "queue". I will have a look of this.
JoeLabView
2008-08-05 14:40:09 UTC
Permalink
From your description, you may also want to look into "Event Structures" to handle operator events (selections &gt; pressing button and then handling it).&nbsp; The Event Structure combines very well with a queue.&nbsp; There are many example of this.
&nbsp;
R
DFGray
2008-08-06 21:40:05 UTC
Permalink
If you have not already done so, you may also want to look at "state machine".&nbsp; A queue driven state machine works very well as a task handler for a subVI with no GUI.&nbsp; It will be faster than implementing similar functionality with user events and the event structure because it is not forced to run in the UI thread.&nbsp; As JoeLabVIEW said, you can combine an event structure and a queue driven event handler.&nbsp; You can find an example of this <a href="http://forums.ni.com/attachments/ni/170/114240/1/LargeGUIApplicationsInLabVIEW.zip" target="_blank">here.</a>
Ben
2008-08-06 22:10:06 UTC
Permalink
DF wrote;
&nbsp;
"It will be faster than implementing similar functionality with user events and the event structure because it is not forced to run in the UI thread.&nbsp; "
&nbsp;
[Emphesis added]
&nbsp;
I can't find a reference to the contrary but are you sure about that?
&nbsp;
I am just trying to keep track of what runs in the UI and what doesn't.
&nbsp;
Thanks,
&nbsp;
Ben
&nbsp;
&nbsp;
DFGray
2008-08-08 13:40:09 UTC
Permalink
Ben, I am not 100% sure of this, but the evidence points that way.&nbsp; The major piece of this evidence is that you cannot remove the front panel of a VI containing an event structure without breaking the VI, even if the event structure is only registered for user events (been there, done that...).&nbsp; However, in the interest of completeness, I will query the current maintainer and find out.
Ben
2008-08-08 14:10:06 UTC
Permalink
Thanks DF!
Judging by <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=245990#M245990" target="_blank">the posts in this thread </a>both Jason and Craig may be able to "fast-forward" you to the answer. :smileywink:
Ben
DFGray
2008-08-08 16:40:07 UTC
Permalink
I was wrong. :smileysad:&nbsp; The event structure can run in any thread.&nbsp; However, if its contents force it into the UI thread (e.g. read local variable), it is likely to stay there.
Ben
2008-08-08 16:40:08 UTC
Permalink
Hi DF thanks for claifying!
And if it was anyone other than you I would just let it go but...
Your posting are generally viewed as "coming down from on high" so need to split hairs one more time. If you hade posted
"However, if its contents force it into the UI thread (e.g. property node), it is likely to stay there."
See the <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=175796#M175796" target="_blank">post by JLS re: access locals in this thread</a>.
Sorry abou thte nit-picking but there has been confusion on these topics for years and it took a lot of work to get definative answers.
Just one of your students,
Ben
DFGray
2008-08-11 13:10:08 UTC
Permalink
That's what I get for writing a post just as I am about to walk out to lunch.&nbsp; You are correct, Ben, and I have posted timing examples of this particular issue many times.&nbsp; Even though the object of a local or global lives in the UI thread, access to them does not.&nbsp; Property nodes will send you to the UI thread every time.&nbsp; Thanks for keeping me honest.&nbsp; Now where is that coffee :smileyvery-happy:...
Loading...