Timer Events

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

I'm new to this type of programming, so please bear with me. I just came
over from Top Down style Pascal. (Yes lots of books, evidently the wrong
books).

My program will read data from an ADC card, and then grabs some readings
from the serial port (PLC) each time the timer fires its event set at
whatever interval I desire. (100ms)

Is there a way to keep the new timer event from firing if the previous timer
event hasn't completed yet?

For simplicity, I would rather recieve the data from the comport and manage
that data before ending my timer event. My idea was simply set a timeout
for the serial port routines at 1 second, so if for some reason I don't get
a response, I flag an error, however if I do that, then won't I get ten more
instances of the timer event being fired which could lead to a big mess?

So Basically, when the code in the timer event might take longer than the
timer interval on occasion, how is the best way to handle it?

Thanks
 
Richard,

You can disable the timer upon entry into your timer routine, and then
enable it when you exit. This should prevent the timing messages from
getting backed up.

However, I would consider going about it a slightly different way. I
would perhaps have a dedicated thread which would block reads of the serial
port, which would then fire an event when you know data has come through on
it. It might help with the processing somewhat.

Hope this helps.
 
Back
Top