02-23-2023 03:31 AM
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.
02-23-2023 04:59 AM
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?
02-23-2023 07:10 AM
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
02-23-2023 08:10 PM - edited 02-23-2023 08:54 PM
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.
02-23-2023 08:19 PM - edited 02-23-2023 08:55 PM
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.
02-23-2023 11:12 PM
Unfortunately, you did not attach any files
02-24-2023 01:52 AM - edited 02-24-2023 02:03 AM
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.
02-24-2023 02:47 AM
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.
02-24-2023 03:22 AM
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.
02-24-2023 07:45 AM
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.