06-05-2023 06:09 AM
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.
Solved! Go to Solution.
06-05-2023 07:12 AM
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 :
Loïc
06-05-2023 08:01 AM
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
06-05-2023 09:10 AM
I like this approach:
06-05-2023 09:13 AM - edited 06-05-2023 09:13 AM
Btw. you can share the User Event RefNum between different loops or even SubVIs (Producer-Consumer-Pattern)
06-05-2023 09:50 AM
Hi Dave,
That's awesome. This is exactly what I'm looking to achieve.
Awesome. Thanks.
06-05-2023 03:21 PM
But I didn't do your homework, didn't I?
06-08-2023 02:40 AM
@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. 🙂
06-08-2023 02:54 AM
@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...
06-08-2023 03:03 AM
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.