views:

4018

answers:

13

I'm trying to fix a non-responsive USB device that's masquerading as a virtual com port. Manual replugging works, but there may be up to 12 of these units. Is there an API command to do the programatic equivalent of the unplug/replug cycle?

+1  A: 

Unfortunately, there isn't one that I know of. Physically unplugging the USB connection does specific electronic things with pullup resistors, such that the device knows it's unplugged. I haven't encountered a host that attempts to be able to simulate this condition without physical unplugging.

Greg Hewgill
A: 

If you have more than one of these on any particular host machine, you might save some time/frustration by plugging them into their own dedicated USB hub out from the machine - at least it's only one cable to unplug/plug to restart a couple of devices at a time.

You've probably thought of that, of course. :-)

robsoft
not a programming solution, but it will surely work :)
jop
A: 

Programmatically unmounting a USB drive can be done, however, I don't know if remounting can be done via code.

jop
A: 

in http://www.codeproject.com/KB/system/usbeject.aspx look for this:

*CM_Request_Device_Eject* function

This is the SetupApi function that ejects a device (any device that can be ejected). It takes a device instance handle (or devInst) as input...

Treb
Can a device that's "...masquerading as a virtual com port." be ejected?
Andrew Edgecombe
+3  A: 

@Dean,

I've asked the same question some days ago and got lots of great answers (including links to source and links to some utilities as well).

http://stackoverflow.com/questions/85649/safe-remove-usb-drive-using-win32-api

Nils Pipenbrinck
Safe remove and enumeration is completely different processes ...
Ilya
a virtual comm port can't be ejected
Serge - appTranslator
+1  A: 

As Greg Hewgill said, I don't think that it's possible.

Initiation of the whole usb startup is triggered by the usb slave (in your case your device). The usb host (the pc) can send a message to the device to tell it to shut down, but once it's done that it's up to the device to start back up again. The host can't force it to.

To make matters worse you'll quite possibly find that the usb device is detecting the plug being inserted (by detecting the usb voltage on the power lines) to start up. This is particularly true of bus powered devices.


It sounds like there are differences from your situation and the case of trying to unmount/remount usb drives. When the usb drive is unmounted there is no reason that it can't stay enumerated on the pc. You're not actually reseting the usb drive, just making it's filesystem inactive.

Andrew Edgecombe
+1  A: 

I've looked at this for automated tests. The best solution we came up with seems to be the ability of USB hubs to disconnect devices when they draw too much power. From a USB pserspective, it appears the USB host may instruct a hub to do so. With 12 devices, you will have hubs, so I'd suggest to investigate that path.

MSalters
+1  A: 

We used this to programmable disconnect usb devices.

Ilya
+1  A: 

Thought: under Device Manager, you can right-click your computer icon (top of the device tree) and "scan for changes". I'm not 100% sure, but I think if you "eject" a USB device (software "unplug" equivalent), then Scan for Hardware Changes, it will show back up even though it never actually left the port.

If I'm right about that, you might be able to use the Microsoft.Win32.Shell class to emulate opening Control Panel --> Administrative Tools --> Device Manager and running the context-menu item. It's worth a shot, anyway.

Coderer
A: 

The device itself may be able to do this (ie, perform a USB disconnect/reconnect sequence).

Have you contacted the device manufacturer, or if you are the manufacturer, the EE's that designed it?

I had to do this when I designed a USB embedded device - programming could be accomplished through USB, but the device had to be able to disconnect and reconnect at several points to complete the process.

Beyond that there's the brute force method of disabling the USB host device in device manager (I assume this can be done in software) and then re-enabling it.

If nothing else, Phidget has USB controlled relay boards which you can use to connect power or the USB lines themselves to hubs or individual devices.

Adam Davis
+2  A: 

What about using Devcon.exe to "remove" and then "rescan"?

DR

Second this, devcon is a part of the Windows Driver Kit and the source is also provided.
djp
A: 

See how-can-i-cycle-a-usb-device

to cycle a usb device with code

callisto
A: 

I had to do this for my car computer project a while back. The touchscreen drivers didn't like going into hibernate and needed to be replugged when the computer came back from hibernate. The way I ended up solving it was to use Devcon.exe like DigitalRacer suggested. The trick however, was that remove/rescan on the controller didn't work. I had to do the remove/rescan on a HUB upstream from the device (which subsequently disconnected all attached devices).

Dolphin