Keeping alive a Bluetooth serial port on Windows Mobile 6.0 after power-off/suspend
I encountered an unexpected behavior while debugging a WinMo 6 program last night, and I wonder if I was dreaming. But first, some context.
The program communicates through a serial port with a GPS device. It uses either a physical port with cable, and also tries via Bluetooth. After a suspen开发者_C百科d or power-off, I don't need to close and reopen the port if it was using the physical link. However, if using Bluetooth, I need to reconnect : no bytes are transmitted with the old handle. Reopening takes about 6 or 7 seconds, so the app is not usable right away after a suspend on Bluetooth.
However, I remember one debugging streak where my Bluetooth serial port would be still valid and functional after several power-off/power-on cycles, and it surprised me pleasantly. I cannot reproduce the behavior now. Was that a bug in the BT driver?
Any hints you have about configurations or API to try would be great, if you ever got that to work.
The Bluetooth protocol is designed such that there must be communication between the GPD device and your Windows device at least once every few seconds. If the communication is not present, then the link will time-out and must be established again from the ground up.
And secondly, there is the way in which you perform the power cycle. A properly implemented Bluetooth stack will explicitly close-down any open connections if it goes into a power-off state in a normal way.
In short, a Bluetooth connection is not meant to survive across a power cycle, so your program must be prepared to re-establish the connection to a remote Bluetooth device after a power cycle.
精彩评论