LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sending information between two while loops

Hello,
I'm a beginner to Labview.
Right now I have a program with two while loops. One while loop (Loop A) cycles constantly, the other while loop (Loop B) exectues only with an input (button press) from the user. This structure is useful for me because I want a constant value to be output from loop B unless the user presses a button to change it. It is also useful because I use the Loop Iterations counter to count the number of button presses - it works because the loop only executes when a button is pressed.

Unfortunately, I would like to send data (the value of the constant output, and the value of Loop Iterations) from Loop A  to Loop B, as my create/save file structure is in Loop B. In this regard I encounter difficulties.

How can I send data from one while loop to another? I think a local variable might be my solution, but I am having trouble getting that to work. Other solutions would be appreciated.

If necessary, I can upload my program. Let me know.

Thanks for your help.
0 Kudos
Message 1 of 8
(2,680 Views)
Does loop B send data to loop A ONLY when when a button is pressed?
 
I am thinking about an Action Engine which would contain (1) a boolean to indicate that there is new data and (2) the actual data. 
 
If I could see your loops, I could suggest something more appropriate..
 
Some ideas that come to mind is using a queue where the queue could only be accessed if a condition is met.  If you press a button, based on certain conditions in the loop B, it would set a boolean in loop A (Local???  ) to a Case Structure which you'd access the queue and retrieve data.  That way if the button is pressed multiple times, you would not loose any data while loop A is processing it.
 
There are many ways to approach a solution.  Can you tell us more about the application and show us the loops?
 
RayR
0 Kudos
Message 2 of 8
(2,671 Views)


Zappow wrote:
If necessary, I can upload my program. Let me know.

Yes, please do!
 
The easiest way would be to place the control terminals inside loop A and use the "newval" event terminal to access the new values in loop B.
 
No locals or any other fancy stuff needed!
0 Kudos
Message 3 of 8
(2,668 Views)
Here is my program. Ideally, the user has four voltages he can set, and pressing a button chooses that voltage as the voltage that is output to the Daq device.

I would like the saved file ( which saves every time a button is pressed) to have the time stamp (seconds since 12am Jan 1, 1904, minus a constant), the  time at button press, the voltage of the button that was pressed (If I have Voltage 1 set to 1.3 V and hit button 1, the value 1.3 V would be recorded in the save file), and the number of times a voltage button has been pressed since the program began (right now I am using the loop iterations counter)

I appreciate your help. Thanks.
0 Kudos
Message 4 of 8
(2,648 Views)
Here's a quick and ugly modification that might give you some ideas. There is no reason for the event structure in the lower loop!
 
(I downconverted from 8.5.1, so hopefully it still works. ;))
 
(As I told you before, you should really considering using arrays, it dramatically simplifies the code. See my previous example from a while ago)
0 Kudos
Message 5 of 8
(2,640 Views)


altenbach wrote:

The easiest way would be to place the control terminals inside loop A and use the "newval" event terminal to access the new values in loop B.
No locals or any other fancy stuff needed!

Just catching up now..
 
Yes..  Totally agree with this approach.  I thought that the event structure (if any) would be located in the B loop..  But if it's in the A loop, then by all means yes..  this is the way to go.
 
I was hesitating to even mention the word "local"..  😉
 
I'll look at the code later.
 
RayR
0 Kudos
Message 6 of 8
(2,632 Views)
Altenbach,
You incorrectly said:

"There is no reason for the event structure in the lower loop!"

If you disable the file-saving structure in my program (which is the actual purpose of the program), you're right. But with your modifications and removal of my event structure in the lower loop, the program now writes to the file every 20 milliseconds.
What I need is for the program to write to the file ONLY when a button is pressed. THUS the event structure in the lower loop.

Also, your quick and ugly modification did not even confront the issue that this post is about!!

I need the value of the upper loop iterations (or the number of total button presses) AND the value of the output voltage to appear in the saved file. The save file structure is in the lower loop, so it can record the value of the time stamp in seconds.

Thanks for your time, but you did not help me.


Message Edited by Zappow on 06-27-2008 06:20 PM
0 Kudos
Message 7 of 8
(2,612 Views)


Zappow wrote:
What I need is for the program to write to the file ONLY when a button is pressed. THUS the event structure in the lower loop.

You still don't need an event structure, because the loop spins regularly. Simply place the file saving back in the case structure and wire the boolean wire that goes to the reset also to the case structure as before (I did not bother about the file saving stuff, because I disabled it for testing).


Zappow wrote:
Also, your quick and ugly modification did not even confront the issue that this post is about!!

Well, I did not charge you a cent, so take it for what it's worth. 😄


Zappow wrote:
I need the value of the upper loop iterations (or the number of total button presses) AND the value of the output voltage to appear in the saved file. The save file structure is in the lower loop, so it can record the value of the time stamp in seconds.

Well, you still only need one loop total. Here's another quick draft, again at no charge. 😄
 

 
Message 8 of 8
(2,602 Views)