LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[QMH] How to stop a loop running in a sub-vi?

Dear all,

 

I'm using a classical QMH architecture.I have different consumer loops.

In one of them, I have a sub-vi which need to run in a loop (DAQ signal generation).

Could you tell me how to stop the loop Inside the subvi please?

Traditionnaly, I use a reference to a boolean which is located in the front panel and I stop the subvi loop like this.

 

But, here, as in the consumer loop, the state "Autofocus start" launches a subvi containing a loop which SHOULD run until a Stop button is pressed in the main front panel.

Loop with subVi.PNG

After this state, the consumer loop QMH waits for a new message in the queue. This message is sent via the queue from the front panel and the state is now "Autofocus stop".

Stop previous state subvi.PNGI don't know how to stop the subvi which is in the previous state.

Could you help me please?

Best regards

 
 

 

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

Hi,

 

I think you should put the subvi block in the case structure: autofocus stop. After this open the subvi and add an input for the subvi on this panel :

WillemNL_0-1587741872140.png

Click on one of the blocks on the left side (input) and click after that on the stop button on your main vi. Now you can connect the stop button to the stop knob in the loop. Maybe I am wrong, I am quite new in LabVIEW. 😅 

 

With kind regards,

 

Willem

 

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

 

You could launch it async in the AF start and turn your AF subVI into a queued state machine.  Enqueue the stop state in your AF stop.  It's easier done than said.  Ugh.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 5
(2,734 Views)

Seeing only "selected parts" of your routine, I'm uncertain what you are trying to do and what you are failing to do.

 

You mention a QMH and show a few states of the QMH.  You also mention "Producer/Consumer" (or "P/C").  Am I correct that the QMH acts as the Producer, and sends data to the Consumer by a separate Queue?  If so, there is a simple way for the QMH to send a "Stop and Exit" signal to the Consumer, potentially allowing the Consumer to be restarted at a later point in the code.

 

There have been numerous discussions of how to stop P/C loops.  The important thing to recognize is that (generally) the Producer "knows" when to stop, but the Queue must be kept active until the Consumer "knows" it has processed everything in the Queue.  This means the Producer must not release the Queue.  Instead, the Producer puts a "unique value", conventionally called a "Sentinel", on the Queue to mean "That's all, no more data are coming".  As the Consumer processes the Queue, it checks every element to see if it is the Sentinel.  If so, it exits without processing (and optionally can Release the Queue), otherwise it processes the (valid) data.

 

So what makes a Sentinel?  If you are sending Arrays of samples, then an Empty Array makes a good Sentinel.  Sending a String?  Use the Empty String.  Sending Floats?  Send NaN.  Sending I32 values?  Try sending the "unique number", -2147483648 (there is no +2147483648 in I32).  If you are sending a Cluster, any of its elements can act as the Sentinel.

 

So all you need to do to have the QMH stop the Consumer is to send the Consumer the Sentinel.

 

If you still can't figure out how to do this, compress the Folder containing your Project and attach the resulting .zip file so we can see your code in context.  If the QMH isn't obvious, mention which VI contains it.

 

Bob Schor

Message 4 of 5
(2,664 Views)

Dear all, 

Thanks for your suggestions.

I will try to apply your recommendations.

Do you have in mind some examples of code that I should see and understand.

I honnestly need to see to understand because I know how to stop a Producer loop but not to stop a subVi, as I said. If the subVi contains a P/C loop itself, I never saw this type of example.

Once again, I'm here to understand your suggestions, I will gave a careful look.

Best regards and stay safe.
Sébastien

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