I have a USB modem and it often drops the signal. When this happens I pull unplug and re-plug it from the USB port and it gets the signal right back; Can I write a program that does that without having to physically disconnect the modem from the port?
3 Answers
I think the simplest way is the hardware way: if you cut the USB power then you will have a unplug/plug event.
Two solutions:
1/ A powered USB hub: most USB hub have an external power socket which mechanically cut the power from the host when the power plug is inserted. Cut power coming from the power adapter, and all devices under the hub will be disconnected.
2/ Just hack a regular USB cable: you just have to cut the power wire (the red one).
To cut the power you can use an USB relay plugged on a different USB port. You can find USB relays everywhere on the net, but here are some:
http://www.yoctopuce.com/EN/products/category/usb-actuators (driverless)

- 211
- 2
- 4
As hinted in a comment, programmatically resetting USB ports is an OS-specific feature.
In Windows the easiest approach is probably by leveraging WMI aka Windows Management Instrumentation. You can get several snippets that "mess" with USB ports, in various languages, by searching the web with "WMI", "USB" and such keywords.
This MSDN article is of broader interest than just USB controllers but provides a good overview of the CIM model and WMI interface.
Edit:
Indeed if this question pertains to Windows, I just discovered it is a duplicate on SO:
- Connect and disconnect usb programmaticaly without unplug and replug
- Windows power-off a usb device in software
BTW, both these links were identified automatically by SO, in the "Related" list on the right of the page
==> We need to remember to check thislist more systematically
==> In many cases, this list is damn good
Depends on the operating system. For example, with FreeBSD you can use "usbconfig ugenX.Y power_off" and then "power_on".

- 1,766
- 13
- 12