Exception reading Comm port

G

Graham McKechnie

Hi All,

I'm developing a GPS app and I'm having problems when the device Auto powers
off. Up until that point it works well. When I switch the device on again
I'm getting an Exception (I'm throwing it ) when I call ReadFile. I then
have to reboot the device and it then works again until it auto powers off
again. Of course if its in the cradle it works all day because it never
powers down.

My first thoughts were to trap the activated and deactive events - this is
where I open/close the port and start/stop the reading of the GPS data. This
appears to work well enough when swapping between programs. When I come back
to my app after bringing another to the foreground, it just continues
reading away as normal. But it doesn't work when the device powers off. I
don't even know if those events get called when the device powers off as I
have no way of debugging it ( I can't get my 5450 to auto power off when its
in the cradle, even though I have that option checked )

I'm presuming they don't and therefore the port is left stuck open or
whatever when the device powers down. It shouldn't be though, because
ReadFile wouldn't be called unless the port is open, so its probably
something else I'm overlooking.

For the moment I'm getting around the problem by preventing the auto power
down with constant calls to SystemIdleTimerReset as per the SDK example.
This is essential for when I'm collecting GPS data for I don't want it to
power down when I'm in the middle of mapping a hole on a golf course.

However that is not what I want for the end user when he comes to use my
program. For the end user I do want the device to automatically power down
during his round of golf as I doubt the battery would last 5 hours
continuous running, especially with the GPS CF card also draining the power.
But obviously I want the program to resume from where it was when the device
was shut down or auto pwered off. The GPS only needs a couple of secs to
start transmitting again on a warm start.

Anyone have any ideas?

Graham
 
G

Ginny Caughey [MVP]

Graham,

I know this isn't what you want to do, but how kludgey would it be to make the
user click a button to recalculate the position and only open the port and read
from it and then close it right then? (Maybe I'll get to find out on a golf
course near me one day. ;-))

You could also trap the WM_HIBERNATE message in a MessageWindow's WndProc. This
message is triggered when the device is running low on power, so you might be
able to close the port when you get this message and open it again on
WM_ACTIVATE.
 
G

Graham McKechnie

Hi Ginny,

Thanks for the reply. I shouldn't ask questions when you go on hols,
although it sounds like you got out of town, just at the right time.

Yeh maybe, but a bit too kludgey<g>. What I want is for the golfer to decide
when to turn it off or if he forgets just let it time out and automatically
turn off. That way the distance to the pin is available at any point on the
course at every step. As the player gets closer to the green the graphic
will automatically zoom to display a more realistic view of the green and
that effect will be tend to be lost too.

It may not be a problem if the device can ran for say 5 hours, I haven't
done enough testing yet to check that. But with the GPS unit also sucking
power its going to be a close thing. There are some nice Bluetooth GPS units
that have their own power supply (up to 8 hours), but the disadvantage of
that is now you have two gadgets to carry on the course (and two gadgets to
remember to charge) and of course I'm targeting the walker not those lazy
cart guys.

I've been reading up on WM_HIBERNATE, but it sounds as though you don't have
much time at that point. Hopefully there will be enough time to close the
port. I'm just surprised that we don't get a Deactivate after the
WM_HIBERNATE. I'm hoping to close the port, sleep some and then let
hibernate do its thing.

I need a Spy program for this thing, just to see what does happen. I sort of
got sidetracked on other aspects and had assumed you would have had the
answer. What happens with your program and your serial port when the device
turns off. Is it normal to have to reboot in your case?

Of course I'm assuming a lot here re the port closing. Its probably more at
the device driver level.

Oh you will!!! If only I could claim this is going to improve your handicap
by 10 strokes

Regards
Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top