07-10-2014 04:06 PM
The main calls a subvi where there is a for loop. Is it possible to pass a variable from inside the for loop to the main in real time, that is while the for loop is still running?
I tried with a global variable. The global itself is updated, but if I put in the main the global variable with a wire to an indicator, the indicatore doesn't update until the sub vi has not completely passed the control back to the main.
Is it possible to do that?
Solved! Go to Solution.
07-10-2014 04:15 PM - edited 07-10-2014 04:17 PM
Of course this is easily possible with a global (not pretty, but posssible). 😉
You are doing something wrong. Please show us your code. Mostl likely you need to poll the variable in a parallel loop if the main loop is stalled due to the subVI call. Think dataflow!
07-10-2014 04:32 PM
Yes, Use a Control Reference and a Property Node Value and the sub VI will update the value in real time to the Front panel and the main vi. But if the variable value in the top VI is passed in a wire it will not update the value of the wire until the loop starts a new iteration. You must be very careful and control the order of execution or you could have flaky code due to race conditions. Remember LabView processes everything in parallel and if you are using a reference and property you are not sure when it updates.
07-10-2014 07:11 PM
@Dave_Brandt wrote:
Yes, Use a Control Reference and a Property Node Value and the sub VI will update the value in real time to the Front panel and the main vi. But if the variable value in the top VI is passed in a wire it will not update the value of the wire until the loop starts a new iteration. You must be very careful and control the order of execution or you could have flaky code due to race conditions. Remember LabView processes everything in parallel and if you are using a reference and property you are not sure when it updates.
That won't work if we are in Real Time.
What you really want to do is remove the loop out of the subVI and adjust your main VI's loop accordingly. That way you can update your indicator after each time your subVI runs.
07-11-2014 01:12 AM
hi
can it work with an "Action Engine" ? you put a write state in the AE in the for loop of the subvi and read it elsewhere
n
07-13-2014 01:11 PM
Hi, here I attached a simplified skeleton of what I would like to do. I have a for loop in the subvi, and I want to check the percentage of executed for loop (because in the original file it takes a very long time, and I need to check how much time I have to wait for it to be finished).
The simplified version in the attachment works. However I would prefer not to have a while loop to poll the global variable, since it waste a percentage of the cpu time which could be used better to perform calculations
@altenbach wrote:
Of course this is easily possible with a global (not pretty, but posssible). 😉
You are doing something wrong. Please show us your code. Mostl likely you need to poll the variable in a parallel loop if the main loop is stalled due to the subVI call. Think dataflow!
.
07-13-2014 01:22 PM
What is your target? By real time do you mean a real time target such as an fpga host vi or executable?
07-13-2014 01:24 PM - edited 07-13-2014 01:25 PM
Might be misunderstanding, but this might be what you want:
07-13-2014 01:36 PM
If you are running in windows see example vi
07-13-2014 02:45 PM
Hi, here I attached a simplified skeleton of what I would like to do. I have a for loop in the subvi, and I want to check the percentage of executed for loop (because in the original file it takes a very long time, and I need to check how much time I have to wait for it to be finished).
The simplified version in the attachment works. However I would prefer not to have a while loop to poll the global variable, since it waste a percentage of the cpu time which could be used better to perform calculations.
Yes, the main loop has to keep iterating to update the FP indicator. If you wait int he main diagram for the subVI to finish all its for loops then you won't be able to update things. You have a few of choices if you don't want parallel polling.
Make the For loop in the main diagram and the math in the subVI, then the main diagram can update the indicator.
Second, you can pass the FP progress indicator reference to the SubVI and it can update the FP indictor from within the loop.
And even more elaborate, pass a USER Event reference to the SubVI and it can trigger an even every iteration to update the front panel and you will have an event structure in a while loop that will respond to these events. This won't take CPU until the event is triggered and then updates the FP display.