Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting USB Connection -- C# .Net CF 3.5

I have an application (.Net Compact Framework 3.5) running on a Windows Mobile 6.1 device and I want to detect when the USB connection changes (either something connects or disconnects).

I was originally using the SystemProperty.CradlePresent property to trigger an event but I am wondering if this only works if the device connecting has ActiveSync? I will be receiving a connection via USB from a Linux device that does not have ActiveSync running on it.

Can I still use SystemProperty.CradlePresent to detect the connect/disconnect from the USB? Or do I need to explore other options to detect the USB event? Thanks.

like image 749
Chris B Avatar asked Mar 23 '11 20:03

Chris B


People also ask

Why is my USB-C not recognized?

The device or dongle isn't connected to the correct USB-C port on your PC (or phone). The device or dongle is connected to your PC (or phone) using an external hub or dock. There are too many other devices or dongles connected to your PC (or phone) that use a USB-C connection.

Why is my USB not being detected?

This issue can be caused if any of the following situations exist: The currently loaded USB driver has become unstable or corrupt. Your PC requires an update for issues that may conflict with a USB external hard drive and Windows. Windows may be missing other important updates hardware or software issues.

How do I find USB-C in device Manager?

Under “Related settings,” click Device Manager to bring up a list of devices. Double-click Universal Serial Bus controllers in the list to reveal the actual controller. It should read something like “USB 3.0 eXtensible Host Controller.” Give that a right-click, then choose Properties.


2 Answers

Perhaps this previous question of mine may help:

How can I detect a USB disconnect event? (Windows, .NET C# application)

I ended up listening for and handling WM_DEVICECHANGE events. They are specified here: http://msdn.microsoft.com/en-us/library/aa363480(VS.85).aspx

Unfortunately I don't have a copy of the source code anymore so my memory on it is a bit hazy. I don't know if this solution applies in your context.

like image 138
Jon Avatar answered Sep 22 '22 05:09

Jon


Check this out, you might be able to grab part of the source code. Its written in C# with a GUI. Keep in mind every time you have a program running that is checking for new USB drives, it will take up memory and CPU so you might want to tone down the intervals at which it checks and then supply a "refresh" button for impatient users.

like image 22
llk Avatar answered Sep 18 '22 05:09

llk