LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Access (read) value outside of while loops before it is finished

Solved!
Go to solution

Dear community,

 

yes, I know, there are already some suggestions of how to access variables from outside while-loops, however, none of these have worked for me so far. So: Let's say I change a variable inside a while loops each iteration (e.g. increment it by 1, or get a random number). I need this number outside the loop as well, but not only the last one, but the immediate value after each iteration. So, what I tried already was: 

- using a global variable (even though this is not the best choice) - somehow didn't work! The global variable was also updated only when the while-loop finished (I guess because it is itself a VI which is access from within the loop, and then only released when the loop finishes). 

- using a functional global: similar, also didn't work.

- using references. Now, this kind of works halfway. If I make an indicator (or control, doesn't matter) (say, A) outside a loop and follow the instructions of creating a reference to a variable inside the while-loop (vie ctrl reference, property node etc.), then I can see the value in A, but i cannot read or access this data/pass it on to something else. 

- using queues. But then I discovered that they only work with two (or more) while-loops which run in parallel, not just outside the one while-loop I have.

 

There is no simple possibility to remove these loops. Also, it is not a matter of using two parallel loops - really just accessing the data from outside the loop.

 

Do you have any suggestions of what I can also still try?

0 Kudos
Message 1 of 9
(7,917 Views)

Correct me if i am wrong. If you need the immediate value after each iteration, why dont you connect directly to the indicator?  or use a local variable?

Nghtcwrlr

---------------------------------------------------------------------------------------------
*************************************
---------------------------------------------------------------------------------------------
0 Kudos
Message 2 of 9
(7,903 Views)

Without seeing any code you were working on, i somehow have the feeling that you lack a little on the database programming paradigm which is the foundation of LV.

My biggest concern is that you seem to refer to an indicator with the term "variable", which is not the case.

 

From the description you give, the notifier comes closest to what you are looking for. But without seeing the way you implement, the reason why you thing that FGV is not working remains a total mystery.....

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 9
(7,898 Views)

Ok, to be a little bit more precise, I will explain the issues more:

 

1.) Yes, using an indicator inside the while-loop to update it works. But using a local variable from this indicator, putting it outside the loop and reading from it does not work (and this I need to do, since I need this value to do calculations/plotting etc. which is independent of the update time of the while-loop).

 

2.) I have several loops and need all the variables that are changed in those loops at once, to monitor my system - I want to put them all into one big array and update each value whenever in the according while-loop, this value gets updated.

 

So: Let's say I have 3 devices, A,B and C. For each device, there is a while-loop for reading from the device (as they have different speeds). A,B and C should be put together into an array [A,B,C] and then, after defined time intervals, I want to output [A,B,C] (e.g. into a file or a plot), but this timing should be independent of the while-loops, and the values being updated independently from one another (e.g. if A gets updated 3 times per second and B two times, A should not wait for B to be updated together). 

 

Sorry for my possibly clumsy description.

0 Kudos
Message 4 of 9
(7,892 Views)
Solution
Accepted by topic author Osmium

Why can't you add a fourth loop for processing the data?  Due to dataflow, I don't think it's possible to update another "variable" outside of a loop.

0 Kudos
Message 5 of 9
(7,887 Views)

I've been doing this kind of thing a fair amount lately with a structure that looks like the Queued Message Handler template.    This works pretty well for what I think of as "data push" systems, where there are multiple data producers working at different rates.  Each producer loop is only concerned with its own device, can iterate at whatever speed suits it, and pushes its data into a queue.   

 

If you find all the loops and queues to be a bit much to dive into all at once, you could put together a "data pull" system using functional globals.   The producers would be pretty much the same except that instead of pushing data onto a queue, they'd write it to an FGV.   You could then have a separate file writing loop that runs at a periodic rate, and whenever it's time to write the most recent device data, it pulls that data from the FGV's and writes it out to file.  This could be separate from a main display loop that also pulls data from the FGV's to display it.

 

I like the efficiency and losslessness of queue-based "push" systems.  But a simpler FGV-based "pull" system can also work pretty efficiently if you don't need losslessness, just the ability to know the most recent measured value at any arbitrary time.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 6 of 9
(7,868 Views)

Osmium wrote:

Also, it is not a matter of using two parallel loops - really just accessing the data from outside the loop.


Why do you say this?  How many times do you want to read the data?  If you want to read it more than once, you are going to need a second parallel loop. 

aputman
0 Kudos
Message 7 of 9
(7,861 Views)

Ok, I added another loop (as there really appears to be no other possibility) and now it even works with local variables within the loop! But what do you mean by "due to dataflow"? And also: good for LabView to use parallelism - but imagine a situation where one cannot run parallel things, then one really has to consider of what to do if it is really necessary to get the data out of the loop.

0 Kudos
Message 8 of 9
(7,833 Views)

@Osmium wrote:

 but imagine a situation where one cannot run parallel things, then one really has to consider of what to do if it is really necessary to get the data out of the loop.


Hmm...computers used to require a punch card.  That's the only situation I can imagine where things couldn't run in parallel.  Thankfully, computers today are multi-threaded and can handle things like this with ease.

aputman
0 Kudos
Message 9 of 9
(7,822 Views)