LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I maniuplate constants outside of separate while loops?

Solved!
Go to solution

What I want to do is subtract the incrementing constants in while loops 1&2. I've removed the meat of the code, as it would get in the way of the question. Basically, everytime a value is read (outside the case structure), iI want it to increment the 'number of times read'.The same happens in the second while loop (they're essentially independent of each other). I can't subtract them outside of the while loops because the code never leaves the loop. Could I use a global variable? Thanks for any replies.

 


Capture.JPG

0 Kudos
Message 1 of 5
(2,430 Views)

First, a minor pet peeve of mine on terminology. Constants don't increment. 🙂

 

You may have taken away too much meat to get a clear understanding. Basically it looks like you have two independent counters and you want to calculate the difference between them.

A global variable would work. A functional global or action engine would be even better. How often are you going to be comparing counts? You'll need a third loop do the calculation and display the result.

Message 2 of 5
(2,416 Views)

Oh yeah of course haha.

 

Basically outside of the case structure is a VISA read, which reads a tag. This goes straight to the case structure. I want it to increment by 1, everytime the tag is read. Then to subtract one count from the other.

Would I need a third loop surrounding the two separate while loops?
 I've added a bit more, hopefully it makes more sense.

 

Capture.JPG

0 Kudos
Message 3 of 5
(2,402 Views)
Solution
Accepted by topic author CJBee

You'll need to put in the globals or functional globals to make your counter values available outside of your acquisition loops.

You'll need a third loop in PARALLEL to do the subtraction of the values that you have in your globals.

 

You may also want to look into using Queues and Notifiers.

 

Another way to do this would be to pop a notifier each time you receive a tag and then have a processing loop that handles the received notifiers.

Message 4 of 5
(2,358 Views)

Thank you so much.

Used a parallel loop with global variables and it worked perfectly first time.

0 Kudos
Message 5 of 5
(2,343 Views)