我从循环C#USB设备如何? [英] How can I cycle a USB device from C#?
问题描述
我想循环(模拟拔下并重新插入)特定事件后通过USB设备(调制解调器)已被解雇。我发现$ C $的CProject一个例子:
I'd like to cycle (simulate unplug and re-inserting) a USB device (modem) after a certain event has fired. I found a sample on codeproject:
<一个href=\"http://www.$c$cproject.com/KB/system/usbeject.aspx\">http://www.$c$cproject.com/KB/system/usbeject.aspx
这使我能够识别+弹出通过其非易失性串行设备,但我需要它来回收,而不是退出。
That allows me to identify+eject the device via its non-volatile serial, but I need it to recycle, not just eject.
我已阅读本:
<一个href=\"http://www.tech-archive.net/Archive/Development/microsoft.public.development.device.drivers/2005-02/1292.html\">http://www.tech-archive.net/Archive/Development/microsoft.public.development.device.drivers/2005-02/1292.html
我不明白它。
这在其他USB相关的帖子已经提到:
This has been mentioned in other USB related posts:
<一个href=\"http://www.$c$cproject.com/KB/system/DriveDetector.aspx\">http://www.$c$cproject.com/KB/system/DriveDetector.aspx
这是不相关的我的问题。
It is not relevant to my problem.
推荐答案
得到它使用名为DEVCON一个命令行工具,我再从code称为工作。
Got it working by using a commandline tool called devcon, which I then called from code.
Devcon.exe的投进系统路径之一,所以它的工作原理无处不在。
Dropped devcon.exe into one of the system paths so it works everywhere.
复康: DEVCON
称为:DEVCON删除的 USB的MI_01
called: DEVCON Remove usb"MI_01"
然后叫:DEVCON重新扫描
then called: DEVCON rescan
code:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "DEVCON";
proc.StartInfo.Arguments = "Remove *usb"*MI_01";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
这篇关于我从循环C#USB设备如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!