Re: USB unplug notification
- From: "SP" <spanliu@xxxxxxxxxxxx>
- Date: Sat, 15 Mar 2008 00:01:55 +0800
More detail~
The reason why you can receive notification from OS is driver info OS the
changes with CeEventHasOccurred( ) API.
If you look at driver.
You will find that the CeEventHasOccurred( ) has been placed somewhere in
USB driver plug-in detection routine. And somewhere CLOSE() in serial driver
since there is no plug-in detection inside serial driver.
That's OS will not acknowledge the cable change if driver do not info.
And driver will not acknowledge the cable change if hardware do not info.
Unfortunately, there seems to be NO hardware cable detection in COM port by
default.
SP
"BrownB" <cristian.brunelli@xxxxxxxxxxx>
???????:1b7ffaa4-6290-4408-b48f-6cf2ed7704f7@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On 12 Mar, 17:12, superclass <supercl...@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
I depends how do process plug events. I've found that following code will
not work on Windows CE:
// read everything from message queue
while (PeekMessage(&msg,hWnd,0,0,PM_REMOVE)) {
switch (msg.message) {
// observate WM_DEVICECHANGE event - must come on USB plug in
or
plug out
// WARNING: under Windows CE message will not appear here!
see
windows procedure
case WM_DEVICECHANGE:
printf ("WM_DEVICECHANGE:%d\n",msg.wParam);
}
// do usual message processing
TranslateMessage(&msg);
DispatchMessage(&msg);
}
You must check for event in your Window Procedure:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_DEVICECHANGE:
// in case of Windows CE windows callback function is called
directly
and
// this message only comes here, but not seen by PeekMessage()
below!
printf ("WM_DEVICECHANGE:%d\n",wParam);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
The reasons is that somehow some events are not placed in message queue,
but
window procedure is called directly.
Strange Microsoft logic....
"BrownB" wrote:
Hello, I'm trying to use a USB/Serial adapter in my program, detecting
when it becomes available and when it gets unplugged. At the moment I
can always get the USB notification when the device is plugged in. But
if I open the COM port, the unplugging notification is not received,
nut is somehow placed in a system queue: I say this because I receive
that notification only when I CLOSE the serial port.
Is there a way to receive the unplug notification when the device is
in use? does this depend only from the driver?
WM_DEVICECHANGE is not defined ( more precisely, is #undefined ) for
the WindowsCE 5.0 SDK. I only found that I can receive the USB
notifications only closing the COM port, and then reopening to use it
if the device is not detached. But this leads to lost data, if data is
arriving while closing the port.
I don't know how I could continue to receive these notifications while
the device is in use....note also that the adaptor should be generic
for my application, so I don't want to work on a too low level.
Thank you a lot anyway^__^
.
- References:
- USB unplug notification
- From: BrownB
- RE: USB unplug notification
- From: superclass
- Re: USB unplug notification
- From: BrownB
- USB unplug notification
- Prev by Date: Re: USB unplug notification
- Next by Date: Re: USB unplug notification
- Previous by thread: Re: USB unplug notification
- Next by thread: Re: USB unplug notification
- Index(es):
Relevant Pages
|