CF and Forms.Timers problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We are porting existing desktop/laptop applications to a Windows CE 4.2 based
platform using VB.NET 2003. Our software interacts via RS232 to in-house
manufactured hardware.

We have established basic comms with our hardware using OpenNetCF serial IO.
We need to send the hardware a startup command, wait 2 seconds for a startup
acknowlegement from the hardware, and if received, send hardware setup
parameters, and wait for 4 seconds for an acknowlegement of those settings,
the user being presented with a dialog box indicating a failure in comms if
either the 2 or 4 second timeout elapses.

I have a form, with timer. On a command button I send the startup character
to the hardware, set the timer.interval to 2000, and enabled to true.

In the oncomm event for the OpenNetCF comm port, when the startup
acknowlegement comes in I disable the timer, send the hardware settings out
the comm port, set the timer.interval to 4000 and enable it again. If the
hardware is set to deliberately NOT give the startup acknowlegement, the
tick event of the timer always fires. However, if it is set to give the
startup, but NOT the settings acknowlegement the second tick event doesn't
fire (after disabling the timer, changing the interval, and re-enabling it)

If I DON'T disable the timer, but still change it's interval, the second
event still does'nt fire.

If I DON'T disable the timer, and DON'T change it's interval the second tick
event DOES fire.

I did set up a second timer which would check the enabled property of the
first timer, and it indicated that the first timer IS enabled after the
second enabling, but still the tick event doesn't fire.

Any suggestions?
 
Not certain, but I suspect that since the Forms Timer is in your STA, and
the serial event handler is in a worker thread, this may be a problem
source. Try using Control.Invoke to alter the Timer.

-Chris
 
Thanks Chris

I'm relatively new to .NET (from VB6) and only two weeks into smart device
programming (1 week just sorting out a crypto key corruption issue on the
devices we're using), so it's taken a bit to get a handle on control.invoke.
But it appears to be working, and has fixed the timer change problem.

Cheers
Phil
 
Back
Top