LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

WHILE LOOPS

HI

I HAVE TWO WHILE LOOPS 'A' AND 'B'. OUTPUT OF 'A' IS USED AS A VARIABLE IN 'B'. 'B' WHILE LOOP RUNS EVERY 5 MINUTES. NOW 'A' RUNS CONTINUOUS BUT ITS OUTPUT CHANGES DEPENDING ON CERTAIN CONDITIONS. HOW CAN I MAKE SURE THAT THE OUPUT OF 'A' AFFECTS 'B'. LIKE SOMETIMES THE OUPUT OF 'A' MIGHT BE 4 AND AT TIMES IT MIGHT BE 0.

0 Kudos
Message 1 of 7
(2,624 Views)

How are you passing the variable from A to B?

0 Kudos
Message 2 of 7
(2,616 Views)

Using it as a local variable

 

0 Kudos
Message 3 of 7
(2,606 Views)

Its clearly a Race condition scenario. Leave about passing data from one loop to the other, when you said B executes only every 5 minutes and A is continous (since you didn't provide time lets assume it runs every 1 second) here itself you are missing lot of info. Can you please explain what exactly you are trying to do? Please attach the code if possible.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 7
(2,605 Views)

Smething is wrong with you keyboard. Did you spill sugary soda under the capslock or shift key and now it is stuck?

 

You need to define what you mean by "affects". What is a "variable"? What is "runs every 5 minutes"? What is "runs continuously"? How is all this implemented?

 

Please attach some simplified code so we get a better picture of all this.

Message 5 of 7
(2,604 Views)

This is the code.. It's just a rough one. But the idea is the same.

0 Kudos
Message 6 of 7
(2,591 Views)

Your code just screams "rewrite me from scratch!!!!" but your main problem in the little loop is the fact that all local variables are read right at the beginning of each iteration and then never again. To ensure that you receive updated values, you need to make sure that the local varaible are only read after the time has elapsed. You can use a single flat sequence frame for that.

It might be better to place the current code in an event structure with a 60s timeout, thus making sure that the locals are only read when the event timeouts. Now you can add a second event for the stop button to allow stopping the program even if it is waiting for the timeout.

 

In the upper loop, the use of an event structure is misguided. Just use a plain wait instead.

 

You mght also give informative boolean text to all the radio buttons to make the code easier to read. Overall, the code seems quite convoluted. I ma sure there is a much clearer way to implement all that functionality.

0 Kudos
Message 7 of 7
(2,575 Views)