LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to add sequencing to a Queued Message Handler?

Solved!
Go to solution

Hi all,

 

I’ve set up a QMH which controls 3 pieces of hardware (power supply, waveform generator and actuator) over VISA. I have the front panel set up and all I can control all these individually through their respective controls. Great so far.

Now I would like to be able to sequence their events – this isn’t something I’ve had to do before and I’m unsure of how to approach it.

 

Example Use Case

 

Event Loop: 'Run Sequence Button' is pressed

 

Loop 1. Change PSU output to 5V.

Loop 2. Change Waveform Amplitude to 10kHz

Loop 3. Move Actuator to position 2.

 

What’s the best way to approach this? Do I used semaphores here? Do I have a separate loop which just controls the sequencing? Do I perform all the sequencing through the event structure?

 

I can send the 3 respective messages from event structure, but how do I ensure that they run in the order of 1,2,3? Are semaphores the right approach to take?

 

If anyone has any experience or can point me in the right direction it would be greatly appreciated.

0 Kudos
Message 1 of 10
(1,657 Views)

Hi,

 

I suggest you to share you're code or an representive exemple.

 

If you're following the NI guidelines about QMH, you should have at least 2 while loop :

- One for event handling (Interface with user)

- Another for message processing

 

The event handler is responsible for detect event on you're "Run sequence" Button and enqueue one or more messages to the message loop handler.

 

Two approaches :

- Enqueue all messages in the right order. In that case you're message handler is just consumming messages

- Enqueue the first message and each state is responsible of the enqueue of the nexte step

 

You can check online documentation about QMH :

Using a Queued Message Handler in LabVIEW - NI

- Create a Message Handling Loop in LabVIEW Queued Message Handler Template - NI

 

And check the project template : 

 

Loc_fr_0-1685967125860.png

 

 

Loïc

0 Kudos
Message 2 of 10
(1,634 Views)

I always get into trouble when I (naively) talk about a QMH as though it is a State Machine.

 

When the "Run Sequence" button is pressed, send the Message "Send PSU output to 5 V".  At the end of this Message, have the QMH send itself the Message "Change Waveform Amplitude to 10kHz".  At the end of this second Message, have the QMH send itself the Message "Move Actuator to position 2".

 

Mission accomplished.

 

Bob Schor

Message 3 of 10
(1,605 Views)
Solution
Accepted by topic author Jee_with_a_J

I like this approach:

 

QMH - Run Sequence.png

Greets, Dave
Message 4 of 10
(1,583 Views)
Solution
Accepted by topic author Jee_with_a_J

Btw. you can share the User Event RefNum between different loops or even SubVIs (Producer-Consumer-Pattern)

Greets, Dave
Message 5 of 10
(1,579 Views)

Hi Dave,

 

That's awesome. This is exactly what I'm looking to achieve.

 

Awesome. Thanks.

0 Kudos
Message 6 of 10
(1,564 Views)

But I didn't do your homework, didn't I?

 

Greets, Dave
0 Kudos
Message 7 of 10
(1,504 Views)

@Bob_Schor wrote:

I always get into trouble when I (naively) talk about a QMH as though it is a State Machine.


They DO have many similarities. I see it as a Queued State Machine. 🙂

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 10
(1,370 Views)

@Jee_with_a_J wrote:

 

Event Loop: 'Run Sequence Button' is pressed

 

Loop 1. Change PSU output to 5V.

Loop 2. Change Waveform Amplitude to 10kHz

Loop 3. Move Actuator to position 2.

 


Btw. I'm just realizing: why do you set an amplitude to a frequency? Without thinking it over I just used it the same way...

Greets, Dave
0 Kudos
Message 9 of 10
(1,363 Views)

I'm really not convinced about recommending a custom design pattern so different from the basic ones (QMH, State Machine) to a beginner...

There plenty of ressources about basic design pattern that solve this problem.

 

Loïc.

0 Kudos
Message 10 of 10
(1,358 Views)