views:

516

answers:

2

I want to attach a tracking box that has a serial port, with a serial to usb lead to a windows mobile. Is there anyway to detect usb plugin when i connect windows mobile device with tracking box through USB?

A: 

There is a system event called NOTIFICATION_EVENT_DEVICE_CHANGE that is triggered during certain system changes. I don't know whether or not connecting your USB device generates that event, but that's a place to start. The event is accessed through the native function CeRunAppAtEvent. Don't let it's name fool you, CeRunAppAtEvent can be used to both start programs and notify running programs of events.

The tag on your question indicates you are using the compact framework. With CeRunAppAtEvent being a native function you won't have direct access to it. You will need to do some P/Invokes. To speed things up I will refer you to another resource.

The following code was using CeRunAppAtEvent to start programs during certain events. I would use this as a starting point to see if you can get a program to start when you connect your USB device.

http://www.codeproject.com/KB/mobile/WiMoAutostart.aspx

Joel
A: 

Call RequestDeviceNotifications. It would work just like this blog post, except you'd look for a generic device instead of specifically for a file system.

ctacke