LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

End condition of the while loop using 'AND ∩'

When the end-of-loop condition is executed, the result is false when both conditions are true, and the program cannot run down. But sometimes the result can be true to run normally. So this problem occasionally comes up and I don't understand what causes it. I hope someone could help with that. Thanks.

0 Kudos
Message 1 of 11
(1,039 Views)

Hi Yang,

 

mind to share some code?

Where are those "both conditions" come from?

 


@Yang_s wrote:

When the end-of-loop condition is executed, the result is false when both conditions are true,


This sounds like a NAND operation, or is it a NOR?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(1,021 Views)

Remember the Third Rule of Data Flow programming -- functions that do not share an output-to-input relationship with each other run asynchronously with respect to each other.  This means that if you have a Stop control wired to an And and another wire that gets evaluated in the course of the While loop's internal computation, no matter when you push the Stop button, the loop will not stop on that iteration (as the Stop button was evaluated "at the same time" as everything else in the Loop, and almost certainly "won the race" while still unpushed), but will do "one more time".

 

Of course, I'm only guessing at how you are trying to stop your While Loop, as you failed to show us anything about your code.  Please (please) attach more than just a picture of part of your code -- attach the entire .VI, either as a .VI file or as a Snippet (look up LabVIEW Snippets -- "pictures" that can automagically turn into working LabVIEW code).

 

Bob Schor

Message 3 of 11
(1,002 Views)

Thanks for your reply.

My test code is provided in the attachment. I hope to end the while loop when the queue empties and the stop key is pressed, but after probe test, when the two conditions are true, sometimes the result is true and the program stops normally, sometimes it is false and the program cannot continue running. The acquisition module is KPA101 from Thorlabs.

0 Kudos
Message 4 of 11
(963 Views)

Thanks for your reply.

My test code is provided in the attachment, in which KPA101 of Thorlabs company is used to collect data. The end of loop condition is set to the queue is empty and press the stop key, that is, press the stop button and process all the data, then exit the loop. But sometimes both conditions are true and the result is true and it ends normally, but sometimes the result is false and the program can't continue. Maybe there is a problem in another part of the code that causes this.

0 Kudos
Message 5 of 11
(960 Views)

Unfortunately, you did not attach any files

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
Message 6 of 11
(937 Views)

I changed the code, but it still has the same problem. The end of the while condition is true but the data stream does not run down. This is an occasional bug, and sometimes the code works.

0 Kudos
Message 7 of 11
(906 Views)

It works if you hold down the stop button for a longer time...

I'm not entirely sure but I think it's a combination of the stop button mechanical action and the nested event structure that leads to the error. You should make the logic simpler.

 

Some suggestions:

- do not use nested even structures (at all)

- do not use local variables (not necessary in this case)

- use the "Value Change" Event instead of "Mouse Down"

- poll the stop terminal in the consumer (lower) loop

- stop the producer (upper) loop when enqueue gives an error

- you do not have to name queues (if you only access them by wire)

 

A blocking action inside an event structure is generally not a good idea but works for this simple case.

Message 8 of 11
(884 Views)

Thank you for your suggestion. I'll think it over.

 

But I don't have to press for a long time to make it work, in fact I do the same thing every time but with different results. And I found that if I added the same delay in the lower loop as in the upper loop there would be no error, but I don't understand why this is the case.

0 Kudos
Message 9 of 11
(872 Views)

You are right, I only tested with Sampling Time set to zero.

 

The lower loop is waiting to dequeue data, but the upper loop has stopped enqueueing data.

0 Kudos
Message 10 of 11
(853 Views)