Programmatically restart USB device in Windows

吃可爱长大的小学妹 提交于 2019-12-10 15:33:37

问题


Some software I am developing requires the presence of a USB device (which I interact with as a SerialPort, with a USB-to-UART bridge).

Sometimes, after a computer is being restarted from hibernation, the device is not being detected, and I can no longer write to, or read from, the device through its serial port. Having read/write access to the device is necessary.

I cannot rely on the user to take any action (physical or otherwise), so I need a way to restart the device programmatically.

How should I approach restarting a USB device programatically in Windows XP/Vista/7 using the .NET framework?


回答1:


You could use the WDK (Windows Driver Kit). Lots of source code examples provided, but expect a steep learning curve.

Devcon is a program developed by MS for demonstration purposes that sometimes works and does what you want. But be aware that it is weird and wild. Anyway, the source code is provided, so if you like to mess with device drivers, you can roll your own "Devcon" code.

From the MS site:

DevCon (Devcon.exe), the Device Console, is a command-line tool that displays detailed information about devices. Using DevCon, you can search for and manipulate devices from the command line. DevCon enables, disables, installs, configures, and removes devices on the local computer and displays detailed information about devices on local and remote computers.

HTH!



来源:https://stackoverflow.com/questions/3146370/programmatically-restart-usb-device-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!