How to programmatically unplug & replug an arbitrary USB device?

后端 未结 13 1595
南笙
南笙 2020-12-07 19:22

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

相关标签:
13条回答
  • 2020-12-07 19:25

    Here's some hands on guidance:

    http://digital.ni.com/public.nsf/allkb/1D120A90884C25AF862573A700602459

    This is more hardcore:

    http://support.microsoft.com/kb/311272

    I'd say that using devcon.exe may solve some problems, not mine though. Suppose that you can build a box with arrays of USB-ports, where the power line is interrupted with FETs controlled by a MCU. The MCU should talk something basic and reliable, like RS-232. There might be an arduino board that simplifies the scary hardware work.

    0 讨论(0)
  • 2020-12-07 19:26

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

    0 讨论(0)
  • 2020-12-07 19:30

    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.

    0 讨论(0)
  • 2020-12-07 19:30

    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.

    0 讨论(0)
  • 2020-12-07 19:31

    In Eject USB disks using C# (The Code Project) 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...

    0 讨论(0)
  • 2020-12-07 19:39

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

    DR

    0 讨论(0)
提交回复
热议问题