02-04-2014 06:19 AM
Hello,
I have created a state machine and one of those states includes an Event structure for User events to be handled. This event structure is polled after each data acquisition. It seems like my program gets stalled because after the 'Start' button is pressed, the program gets data and then the event structure waits for an event to happen before it gets new data again. Is there a way to bypass the event structure if no events need to be handled?
Thank you.
Richard
02-04-2014 06:21 AM - edited 02-04-2014 06:24 AM
02-04-2014 07:14 AM
You need to be careful about just putting a 0ms timeout on your event structure. Sometimes you need to sit there and wait forever, like when waiting for the Start button. So you really need to use a shift register to control what the timeout should be. Set it to -1 when you want to wait forever and 0 when you just need to do a quick check for events before continuing on with data collection.
A better way would like be to separate your event handling and yoru data acquisition into two loops, using queues or notifiers to communicate between the loops.
02-04-2014 09:04 AM
02-04-2014 09:51 AM
@leumaseoj wrote:
The main advantage of this state machine is, you can dynamically change the states...
If you feel that the even structure need not to be handle, simple switch/bypass that case.
So that the next case will execute.
This witching can be done through a shift register and a Boolean...
And then how do you expect to handle UI events? The event structure needs to be handled otherwise you could be stuck with no way to quit.
02-04-2014 10:03 AM
02-04-2014 10:12 AM
The JKI State Machine handles this well. The "Idle", "" case in the state machine contains the Event structure so a long operation "macro" can poll the Idle case and when the system is simply waiting for a UI event, the "" (empty string) state will.
This method works well for many of us using the JKI SM.
02-06-2014 06:02 AM
This is the way I'm going to do it. I made the Timeout event select between 0 or -1 wether an event needs to be handled or not. Then, inside all the other events, I just set a Timeout constant to 0 so that at the next loop, the Timeout event is handled again and selects between 0 or -1.
The only question I have is how to notify the Timeout event that an event just happened and needs to be handled and to set the Timeout terminal to -1 instead of 0?
Thank you,
Richard
02-06-2014 06:40 AM
Your timeout needs to be in a shift register. Then each case can set the timeout to whatever you need it to be.
02-06-2014 08:02 AM