Time outs and state machines



I have a state machine that sends messages to an external device. After
sending each message, the state machine waits for 20 milliseconds. If it
has not received an acknowledgment (ACK) from the receiving device when
the 20 milliseconds have elapsed, it assumes a non-handshaking mode and
sends the next message. On the other hand, if it does receive an
acknowledgment before the 20 milliseconds have elapsed, it sends the
next message immediately.

The way I have implemented this is to have a timer that sends a one-shot
timer event when the specified interval has elapsed, in this case 20
milliseconds. If the state machine receives an acknowledgement from the
receiving device before the timer event has elapsed, it stops the timer,
sends the message, and starts the timer again to begin the whole process
all over again, i.e. send message wait for ACK, etc...

There is a scenario that's probably rare but it's bothering me. Suppose
the receiving device sends an ACK message just before the timer elapsed
event. The ACK message gets put on the queue and immediately after the
timer event places its message on the queue as well. The state machine
consumes the ACK message. The next message in the queue is the timer
event. When the state machine consumes it, it believes that the 20
milliseconds for the last message have elapsed when in fact they have
not.

I'm not sure what I'm missing, but I'd like my code to me more robust
than this. Is there an additional state that would prevent the above
scenerio? I was thinking about giving each timer event a unique ID as
one approach. When the state machine consumes a timer event, the ID must
be valid for the next message or it is ignored.

Any help is appreciated.



.



Relevant Pages

  • Re: Time outs and state machines
    ... the state machine waits for 20 milliseconds. ... receiving device before the timer event has elapsed, it stops the timer, ... all over again, i.e. send message wait for ACK, etc... ...
    (comp.object)
  • Re: How do i make text in a control on a form flash
    ... Access cannot give you blinking text ... You can achieve it if program the Timer event of the form, ... TimerInterval in milliseconds. ... rather than allenbrowne at mvps dot org. ...
    (microsoft.public.access.forms)
  • Re: How can I set the interval property to 30 or 60 minutes?
    ... The Interval property is measured in milliseconds and the max value ... Then the timer event ... Private Sub Timer1_Timer ...
    (microsoft.public.vb.controls)
  • Re: HELP! Need Access DB to show realtime changes in different location
    ... value can be between 0 and 65,535 milliseconds), and put code in the forms ... Timer event to do a requery ... Wouldn't that have the unwanted side-effect of setting the current record as ...
    (microsoft.public.access.forms)
  • Automatically run code at given time.
    ... Timer event of the form. ... minute (60,000 milliseconds) and check if the Timeis ... >the database do this automatically at 5PM. ... >your help with the automation code. ...
    (microsoft.public.access.modulesdaovba)