04-17-2026 10:56 AM
At first, I had a simple state machine that sent commands to a Mass Flow Controller (MFC) when a certain time elapsed. With this setup, the inlet MFC stayed closed and the outlet MFC was fully opened once the time condition was met.
Now I want to add an Event Structure so I can send commands at any time by pressing a LabVIEW control. The problem is that all these commands go directly to a VISA write/read, and I’m not sure how to make both approaches work together.
I tried a couple of things. First, I used a Select structure to choose which command to send, but then the commands coming from the state machine never reached the VISA communication. In the second attempt, I used a queue to enqueue the commands, but they were only received when the elapsed time condition was met for the second, fourth, sixth time, instead of every time.
What should I do. I need easy solutions im learning little by little.
Thanks
04-19-2026 09:46 PM
I recommend JKI State Machine.
The Write Command case can be sent from the timeout event and the button pressed event.
04-20-2026 07:29 AM
So your issue is that you still need a particular command to be sent regularly at some time interval, but you also need to interject a manually triggered command from a button, but that manual command should not cause a regular command to get lost, correct?
If I'm understanding your situation, what I would do would be to create a second, parallel loop with an event structure. The event structure would recognize both the manual button press, and a User Event that would come from the original state machine loop. I'd have the original state machine loop now just send a User Event at the regular interval, rather than execute the VISA VI's which I'm assuming it's doing. The only place the VISA communication would take place would be in the new event structure. So every time interval, it would receive an event from the state machine and run it, while also being responsive to the button to run that command as soon as possible while not overriding the interval command. Now there should probably be at least one more event to end the new parallel event structure loop based on however the state machine loop is terminated (button press, variable, a new User Event, etc.).
There are a few other ways I could think of to achieve the same thing, but I think this is probably how I'd do it. I could mock something up if it's not clear enough. The queue scheme should have done pretty much the same thing, so maybe that could be salvaged if you could share your VI.
04-20-2026 09:03 AM - edited 04-20-2026 09:03 AM
@MrMattPayne ha escrito:
So your issue is that you still need a particular command to be sent regularly at some time interval, but you also need to interject a manually triggered command from a button, but that manual command should not cause a regular command to get lost, correct?
If I'm understanding your situation, what I would do would be to create a second, parallel loop with an event structure. The event structure would recognize both the manual button press, and a User Event that would come from the original state machine loop. I'd have the original state machine loop now just send a User Event at the regular interval, rather than execute the VISA VI's which I'm assuming it's doing. The only place the VISA communication would take place would be in the new event structure. So every time interval, it would receive an event from the state machine and run it, while also being responsive to the button to run that command as soon as possible while not overriding the interval command. Now there should probably be at least one more event to end the new parallel event structure loop based on however the state machine loop is terminated (button press, variable, a new User Event, etc.).
There are a few other ways I could think of to achieve the same thing, but I think this is probably how I'd do it. I could mock something up if it's not clear enough. The queue scheme should have done pretty much the same thing, so maybe that could be salvaged if you could share your VI.
Hi, thank you all.
04-20-2026 09:04 AM
@ZYOng ha escrito:
I recommend JKI State Machine.
The Write Command case can be sent from the timeout event and the button pressed event.
I'll give it a try
thanks!
04-20-2026 10:57 AM
Try this out. I think it achieves what you're looking for. The upper loop runs the countdown, while the lower loop generates the commands and responds to buttons. This is pretty much a simple introduction into user events, which you can trigger anywhere in a program and have them picked up in an event structure somewhere else. You can send variable data through them, or if the event structure will know everything it has to do, just use a simple bool for the data type. Very useful!
I noted that since your upper loop runs once per second, and you have both the automatic commands in their own case, there is a 1 second delay between them. You could instead send both AS0 and BS0 commands in the same loop iteration (in one case, rather than two), and the bottom loop will run them back to back pretty much immediately. Not sure if that's desired or not.