04-13-2011 02:27 PM
Hi all
How do you make a single state to process code only on the second time that particular state is called. For example in the code attached how would you make the "log state" execute after double the log time.
Solved! Go to Solution.
04-13-2011 02:39 PM
So you're logging every 125 ms on the timeout event? And you want to continue logging every timeout event, but bypass the first timeout event?
If that's what you're tring to do you could use the First Call? function to ignore the first time that event is called.
Eric
04-13-2011 02:41 PM
04-13-2011 02:42 PM
Oh, you're actually acquiring every 125 ms and logging every 15 s. I still think you can use First Call? for this.
04-13-2011 02:47 PM
Thanks guys
Egraham , your latter presumption is actually correct. I will try your solution first.
04-13-2011 02:58 PM
Maybe I should state the root of my problem. I have one state that executes after double the time of another so I'd like to use the same timer for both states. I am thinking this is much simpler than trying to use multiple timers which i really don't know how to do.
04-13-2011 03:06 PM
04-13-2011 03:13 PM
Hmm... I guess GerdW understands what you're trying to do. I'm still not understanding. The same timer used for multiple states could be pulled out of the case structure and fed in. If one requires double the time, just multiply the output by 2.
04-13-2011 03:16 PM
Correction... you would have to set the timer to the maximum state time and execute the case requiring half the time on increments of half of what the timer was set for.
04-13-2011 04:46 PM
Why not remove the actual code from the timeout event and use user defined events. Create an event for each of your states and then the timeout event will simply compare the time to see which events should be fired. You can use the current time or tick count to track time. A shift register with a cluster of your various start times for tracking the individual times themselves would work. This would work much more like a true state machine. Also, your Stop event can handle the cleanup and there is no reason to post another state.