From 11:00 PM CDT Friday, May 10 – 02:30 PM CDT Saturday, May 11 (04:00 AM UTC – 07:30 PM UTC), ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure state machine

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

0 Kudos
Message 1 of 18
(3,838 Views)

Give it a zero-millisecond timeout.

 

Example_VI_BD.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 2 of 18
(3,836 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 18
(3,818 Views)
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...
0 Kudos
Message 4 of 18
(3,793 Views)

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


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 18
(3,781 Views)
It depends up on the user decision... In case while initializing, if the event is not needed, in the initialization state itself user can make the boolean false (shift register boolean). If you think after the precheck/data acquisition is done, UI needs user event, you can enable the Boolean (shift register boolean) in that data acquisition/precheck state itself.
Because state machine is very good at sequential execution. If you want to terminate a code suddenly, you can raise a error, this can enter into error case and do the nessesory action either close or error handling.
0 Kudos
Message 6 of 18
(3,775 Views)

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.

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 7 of 18
(3,759 Views)

,

 

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

0 Kudos
Message 8 of 18
(3,701 Views)

Your timeout needs to be in a shift register.  Then each case can set the timeout to whatever you need it to be.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 18
(3,690 Views)
Yes, that's what I did, but its the Timeout event that decides if its goig to be a 0 or -1 that the Timeout terminal takes. My question is, how does the timeout event gets notified of any event that need to be handled?
0 Kudos
Message 10 of 18
(3,679 Views)