Sign in to follow this  

State Machines and Timeouts. How could I do/control it?

This topic is 3371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all! Could you help me? I'm developing a embedded program to control a roulette (a real one). I send commands thru serial port, and then, the roulette reply to my program. My program has to play matches all the time. And this is more or less easy using a state machine (send switch on, wait confirmation, send launch ball, recieve confirmation, wait until recieve winning ball, then swallow the ball, wait some seconds, start again...) My problem is that I don't know how to control timeouts or waiting periods (Sleep(1000) does not seem a good idea). For instance, after sending launch the ball, if I don't recieve anything in the next 5 seconds (for example) I would have to retry, or jump to an error state. Do you have any idea about how I can to this? My idea is to use a thread that every 2 seconsds test the current state to know if there is any timeout and use a variable like start_time every time I send a message. if current_time-start_time>5 seconds then timeout or retry. But, Is this going to work if I add code at entry and exit of my states? (I ask this because my entry and exit code will take a few seconds) Am I going to have thread or blocking problems? Thank you very much for your time. I'm looking forward to hearing opinions. Ricardo.

Share this post


Link to post
Share on other sites
If you're writing an embedded program, you're either running in an OS specific to the hardware which will provide special real-time processing functions that may help, or you're running alone on the hardware.

In the first case, check the OS documentation (or tell us which one it is).

In the second case, you just have to loop and poll until you timeout.

Share this post


Link to post
Share on other sites
Well, I said embedded but my system is just a common PC (just the tower) with any Linux distribution, situated under the roulette. But I'm not using any real time OS. I said embedded because I have a specific purpose computer, as a phone or a MP3. Perhaps calling my system an embedded is not right in my case.

You say "In the second case, you just have to loop and poll until you timeout."

I understand what you mean with poll (I already proposed that) but could you explain what do you mean with loop, please?

Thanks for your help.

Share this post


Link to post
Share on other sites

This topic is 3371 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this