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

rajiv,

 

The solution to this is a proper design pattern.  Take a look at this PDF... it goes into a lot of the standard patterns.

 

Based on what you described it seems like the Producer/Consumer design would be best for you.  Your event would enqueue an element containing the data from the control.  The consumer loop would then pull that data out and feed it into the subvi that handled the data.

 

If you post code of what you're trying to do, most everyone on this board would be happy to do a basic code review and give you tips/tricks on how to do it better.  And if someone is truly bored, you might even get a free refactor of your vi 🙂

0 Kudos
Message 11 of 23
(1,080 Views)

Thank you very much. Thanks for the pdf.. slide 47 very useful. 

 

On Monday I will have access to my code again. 

 

You guys are very helpful. Thank you so much!!

 

P.S: It gets complicated: I have 4 front panel controls. So would I need to use a cluster? bundle / unbundle? Also if I need to supply this data to more than 2 subvis that are running in parallel which have their own subvis.. basically these are just control parameters that are used in many places.. and more over, I hve additional events that also use those control values. It is not clear to me how queues will help me since I know that a queue can only be used once: read once. :S

0 Kudos
Message 12 of 23
(1,074 Views)

Ok: I have made a simplified Vi to illustrate what am trying to do.

 

Since am having to use the values in many places, I just tried as a test with notifier. It is doing the job fine except for freezing when the OK event button is pressed multiple times and then the control FP value is changed. But this is another issue. 

 

We have an events Loop and it has 3 controls on the Front Panel. 

And: 

-1. We have 2 parallel Loops that should receive the latest values of the 3 controls from the events loop triggered by events due to value change.

-2. We have an events loop that should also use the latest value of the 3 controls. 

-3 Also if the value of the variables change inside any of the subvis, it should change the value of the control on FP. 

 

In my actual program those 3 control values are used in many places but in general this is a simplified situation.=> The issue is how to communicate between the respective subvis. 

 

In the current setup, pressing the OK button multiple times, then changing the control FP value freezes the FP. Probably because the notifier is also being read inside an events.

 

=> What would be the most best practice way of doing this? 

 

Big thanks for your help.. ::thumbs up::

 

0 Kudos
Message 13 of 23
(1,065 Views)

@rajiv85 wrote:

It is doing the job fine except for freezing when the OK event button is pressed multiple times and then the control FP value is changed. But this is another issue.


It is freezing because it is waiting for a notification.  A general hint: you should not have anything "long" happening in your event cases.  Have them pass on data to other loops and continue to handle the GUI.

 

And you example code does not really tell us much.  What are all of these loops trying to do?  Why do they need all of these variables?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 14 of 23
(1,040 Views)

It is freezing because it is waiting for a notification.--> Thanks for pointing this out..wasn't sure why!! So in that particular situation, how to fix this?--> how to send the latest value of a control to an event triggered event case that is itself triggered by an event value change within the same event case. 

 

--> what we are talking here: is how to communicate 3 or more variables on a front panel to 2 parallel running subvis+ and events case+ register changes within the subvis which changes the front panel values. 


Am just not getting a firm solution of a best approach.

 

For example: I have 3 or more front panel controls, the user inputs some parameters: like motor position, speed etc. 

 

I press a start button: these parameter values need to go to the subvi of 2 different parallel loops. furthr when the user presses save button it activates an event which will also use those parameters..so they need to be fed to 2 parallel loops+ stuffs happening in the same events case. At the same time if within the subvi one of these controls change value, it should change the value of the front panel value. 

 

Question 1: where do I put these controls? In the events loop or in a timeout events case or is there a better place?

Question 2: I could use local variables for this. But then we are not respecting dataflow. So how to do it with dataflow?

 

 

 

 

0 Kudos
Message 15 of 23
(1,026 Views)

@rajiv85 wrote:

 At the same time if within the subvi one of these controls change value, it should change the value of the front panel value. 


This is the part that concerns me.  Why are the other loops changing control values?  When it comes to global data like this, you need to control it in 1 location or at least lock it down so you don't have multiple places updating and overwriting each other.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 16 of 23
(1,015 Views)

Well this is how it is.. as the SubVIs can have internal decisions that can modify the control parameters based on certain conditions.. it is the application which dictates the necessity to have it that way. The question is how to do it with dataflow. 

 

I can already do all this using this approach: control values inside events: value change updates globals...globals used in all subvis.. if the globals are written to within the subvis.. write to property nodes of the controls via a reference.

 

But is this the best practice respecting dataflow.. or is it that it simply cannot be done via dataflow and I need to modify my program to make it work with dataflow? What I did with the above example VI is using notifiers is a sketch of what I want ..trying to implement dataflow. Am sure it is not the best way..so what is the best way?

 

P.S: yes but as the writing is happening in indepedant events.. this means that there is no risk of a race condition in writing. 

0 Kudos
Message 17 of 23
(994 Views)

Your program is never "freezing", it just no longer updates the notifier because you are destroying the notifier in the shift register (the output tunnel of the OK case uses default if unwired, meaning that the next time one of Numeric 1..3 change, they operate on an invalid notifier. (And since the error out is wired to something, you won't get an automatic error notification, even though you are not really handling the error).

You don't need to place the notifier wire in a shift register here, just get it from the plain tunnel as in the OK case.

 

lostnotifier.png

 

 

Message 18 of 23
(980 Views)

Altenbach, thank you soooo much for the clarification, I am studying this to understand it better, it was not clear to me what was happening.

 

So would you say this approach is overall ok or is there a different way of doing this?  

0 Kudos
Message 19 of 23
(965 Views)

@rajiv85 wrote:

So would you say this approach is overall ok or is there a different way of doing this?  


There are many different ways of doing "this", and there might even be better ways doing it differently. However, I don't have sufficient information to decide what's best. Every case is different.

0 Kudos
Message 20 of 23
(909 Views)