LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop a while loop within a SubVI in a queued message handler

Solved!
Go to solution

Hello everyone,

 

I am trying to program a control for some manufacturing equippment. For that, I am using a queued message handler. Within the QMH, I have a VI that controls a particle size probe (called PPC, at the bottom of the first image. When I start the main-vi, the PPC.vi is set to the "Parsum measurement" case, in which the measurement data is repeatedly called in a while loop (the vis to call the data were provided by the probe manufacturer. Also, I am aware that I don't log the data yet. That will come later.). When I want to stop the measurement, I send the "Exit" message to the PPC.vi (last picture). However, the vi is stuck in the while loop in the measurement case and does not respond. I tried to send a notifier with a true-constant, but that didn't work as well.

 

Do you have any suggestions, how I can stop the while loop before sending the "Exit" message? Or is the a completely different way to approach this problem?

Thank you!

 

QMH_main.png

Parsum measurement.png

Parsum exit.png

0 Kudos
Message 1 of 7
(3,372 Views)

What I like to do in situations like this is use a timeout of the queue, stores in a shift register so you can change it.  The idea is to use one state to start your acquisition and set your timeout to 0.  Then in the default case (when you get the timeout) do your measurement and loop back around.  This way you are constantly looking for the commands.  Your timeout should be -1 (wait forever) when you are not in the measuring mode.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(3,355 Views)

Thanks for taking the time to answer me. I get the idea of what you propose, however, I somehow can't implement it. For once, I don't really know how to do it, but I hope I can figure that out in some time. What is more irritating is that I used the dequeue message.vi that was handed out during the Core 3 course. That one doesn't have a timeout input (I uploded the whole project, It would be great if you took a look at it). When I use the "normal" dequeue element.vi, I get an error because the element that is dequeed is not a string, which the case structure expects. Do you have an idea what I can do? I am not that deep into LabVIEW to have a good approach 😕

 

0 Kudos
Message 3 of 7
(3,309 Views)
Solution
Accepted by topic author Qbach

I just threw together a very fast framework to get you started.  The thing I did notice is that the Message Queue library does not have a timeout input for the Dequeue Message.  Since it is your own local (to the project) copy, add a timeout input and wire it to the Dequeue Element function.  I would set the default to -1 and make it "recommended".


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(3,292 Views)

This is very elegant and also something even I can add to my code!

Except to "add a timeout input". I know I somehow need to add the "standard timeout input", where -1 means continuous waiting for a message, etc.. Google told me that there doesn't seem to be an easy solution, or is there?

I hope I don't stretch your patience too far 😕

0 Kudos
Message 5 of 7
(3,277 Views)
Solution
Accepted by topic author Qbach

Here you go.  It took 30 seconds to make the change.

Spoiler
My toddler can be such a distraction

GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(3,259 Views)

Ok...now I feel just a little stupid Smiley Embarassed

I didn't look in the code of the dequeue messeage-vi. I started directly by looking for a command or code block to use and couldn't finde one. Thank you!!

0 Kudos
Message 7 of 7
(3,247 Views)