LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[lvl1] State machine + Event structure

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

0 Kudos
Message 1 of 6
(189 Views)

I recommend JKI State Machine.

The Write Command case can be sent from the timeout event and the button pressed event.

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
-------------------------------------------------------
https://github.com/ZhiYang-Ong
Message 2 of 6
(97 Views)

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. 

Message 3 of 6
(67 Views)

@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. 

I thought I had already uploaded the code, sorry. In the end, what I tried to do was send the command generated by the event to a queue, and when the dequeue has no commands (that is, when the event is not triggered), it runs its process and eventually sends the automatic commands at the end of the elapsed time.
I’m not sure whether this diverges too much from your solution or if it’s a bit of a hack.
 
 
0 Kudos
Message 4 of 6
(53 Views)

 


@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!

0 Kudos
Message 5 of 6
(50 Views)

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!

 

MrMattPayne_2-1776700157793.png

 

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.

0 Kudos
Message 6 of 6
(32 Views)