LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure: How to use Timeout

Hey, I have button with switch (not latch) action that sits inside a JKI State Machine, precisely in the Event strucutre. Pressing it (to on) will trigger a procedure which I want to repeat until the same button is switched to off again. I am aware that this can be done using queues, however I want to implement this in a state machine. My idea was to check the state of the button ("Is it still on?") after each repetiiton of the procedure and if it is on, repeat the procedure. If it is off, stop the procedure. My question is, can I use the Event Structure Timeout for this? My ideas was to go to the event case that holds the button (with a small timeout of, say, 10 ms), check its value, and based on its value proceed to the next state. Would this work?
Cheers
Doug

0 Kudos
Message 1 of 16
(7,508 Views)

That sounds like you could probably make it work, yes. However, if you are going to poll the boolean on every timeout, what is the point of putting it in an event structure to begin with? Also, if timing is of importance I wouldn't do it this way. Theoretically, if you have enough events being processed by your structure, the timeout might not ever happen. I understand that is not likely, and the timeout will usually occur on a regular basis. 

 

I still think that polling a boolean in a timeout to take an action repeatedly is not the right way to do this. There are a few structures which stand out to me. One would be to call your procedure with an asynchronous node when boolean is clicked "true" and employ some method to stop your procedure when it is clicked "false". This is probably more complicated than it has to be though for your situation.

 

A more simple way though could be to just put your procedure in it's own loop if you want to stick with polling your boolean if its timing is at all critical.

 

Corey


Corey Rotunno

0 Kudos
Message 2 of 16
(7,498 Views)

Im not terribly familiar with the JKI state machine, i have used it before but briefly.  But you can create an event for value change of your button, inside that event you can check new value of the button, if false proceed to false case, if true proceed to true case.



-Matt
Message 3 of 16
(7,496 Views)

The problem I see is that while the procedure is running, I am not in the Event Structure state. So I thought that my button press would get lossed if I do not check the event structure...

0 Kudos
Message 4 of 16
(7,492 Views)

That there is an entirely different probelm.  You may try a different architecture or force an abort of the current task if that matters.  If you dont need to abort the current case and you want to just queue the event then you could use a QMH.



-Matt
0 Kudos
Message 5 of 16
(7,490 Views)

Oh yea, didnt think about that. However, if you fire an event for the boolean then check the value in the event case and stay in some true state until its clicked back off then the event structure wont be able to process anything else until the boolean is turned off.  This works, but the behavior might not be acceptable. Ussually an event structure is used to continually monitor events. If any event has a lot of work to do, the work is passed off to another loop so the event structure can keep listening for new events.


Corey Rotunno

Message 6 of 16
(7,487 Views)

Thats very true so you have either the choice to put it in a queue and wait until later to process it, abort the current task and process it, or just process both depending on what it is? I dont know the task at hand.  What i was saying about checking the state of the button though is that the event case will process every time the button value is changed.

For example button is pushed, event registers, button is true and the application proceeds to true process( outside the event structure loop). Then the case structure is in idle mode again, you can then capture the button push again and decide how you want to handle it. 



-Matt
0 Kudos
Message 7 of 16
(7,478 Views)

Put an IDLE state in your procedure so that after it runs one iteration, you force it to check the event loop. You'll also want to add a call to the state that is running your procedure so that execution comes back if the event loop times out.  If it doesn't time out and the boolean goes false, clear out the states so execution doesn't go back to your procedure.

 

Edit: make sure your timeout is small so that execution of your procedure isn't slowed down.

Capture.PNG

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 8 of 16
(7,475 Views)

@aputman This seems like what I wanted. So lets say one iteration of the procedure is done and I enqueue the message "Idle". This goes to the event strucutre that I've wired a timeout of 10ms to. There I put a case strucuture that, depending on the value of the button enqueues a message that goes to the appropiate state, yes?

 

What will happen if I press the button during the procedure? Will the new value be recognised?

0 Kudos
Message 9 of 16
(7,462 Views)

Yes that correct, idle then procedure if you want to go back to the procedure case after checking the button.  I just took a look at the JKI state machine.  Then in that event case you can use the boolean logic i presented in message 3. 



-Matt
0 Kudos
Message 10 of 16
(7,449 Views)