C#CreateFile导致USB设备关闭 [英] C# CreateFile causes a USB device to close

查看:440
本文介绍了C#CreateFile导致USB设备关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010 C#编写程序,以使用DeviceIoControl检查COM到USB设备的状态,但这需要打开该设备的句柄.我发出CreateFIle以获取句柄.在WinXP下,它返回一个良好的句柄并执行 不会更改USB设备的状态,但是在Win7下它将重置/关闭设备并返回一个良好的句柄.该设备是Prolific PL2303HXD COM到USB GPIO设备.我尝试不更改基础设备驱动程序和DLL.出现 成为一个共享值设置为NULL的句柄共享问题,因为在WinXP中将其忽略,但在Win7中,它希望在此位置看到另一个值.现在,此调用会导致USB设备关闭电源插座的相同操作:

I am using Visual Studio 2010 C# to write a program to check the state of a COM-to-USB device using a DeviceIoControl but this requires an open handle to the device. I issue a CreateFIle to get a handle. Under WinXP it returns a good handle and does not change the state of the USB device but under Win7 it resets/closes the device and returns a good handle. The device is a Prolific PL2303HXD COM-to-USB GPIO device. I have tried changing out the underlying device drivers and DLLs with no change. This appears to be a handle sharing problem that has a value set NULL since it is ignored in WinXP but in Win7 it wants to see another value in this location.  Now this call causes the same action of the USB device turning off the electrical socket:

uint errorReturn = GetNamedSecurityInfo("\\\\.\\ COM5",SE_OBJECT_TYPE.SE_FILE_OBJECT,   SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION,out pSid, out,outPZero, pZero,  out psd);我开始觉得这个 可能与设备驱动程序未注册签名有关.我已经阅读了回复"中建议的所有材料,而HID设备与我的情况不相关,并且在发布此问题之前,我已经阅读了所有建议的材料. 到论坛.

uint errorReturn = GetNamedSecurityInfo("\\\\.\\COM5", SE_OBJECT_TYPE.SE_FILE_OBJECT,     SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION, out pSid, out pZero, out pZero,  out pZero, out psd); I am beginning to think this may be related to the device driver not being registered with a signature. I have read all of the material suggested in the Reply and the HID device does not pertain to my scenario and I have already read all of the suggested material before posting this question to the forum.

09/14/12与安捷伦的代表一起使用USB 2.0/3.0分析仪,发现使用WinXP没有错误,但在Win7下,在我使用代码之前和期间,分析仪上的错误指示灯一直亮着. Win7的执行跟踪显示出错后出现错误包 包.现在,这看起来更像是WinXP和Win7 Microsoft提供的设备驱动程序之间的区别. OEM安装的设备驱动程序是相同的.看到与USB电话设备有关的WinXP sp2和sp3之间发生了类似的异常情况.

09/14/12 Worked with rep from Agilent using a USB 2.0/3.0 Analyzer and found that using WinXP had no errors but under Win7 the error light on Analyzer stayed on before I used my code and during. The execution trace with Win7 showed error packet after error packet. This now looks even more like a difference between WinXP and Win7 Microsoft supplied device drivers. The installed device drivers from the OEM are the same. Saw a similar anomaly occur between WinXP sp2 and sp3 related to USB telephony devices.

推荐答案

John John Hare,

Hi John Hare,

 

 这是一个讨论如何获取USB设备并使用CreateFile异步读取和写入USB设备的教程.文章的名称是 在.NET和C#中使用USB设备.

  Here is a tutorial that is talking about how to get USB device and use CreateFile to asynchronously read and write into USB device. The name of article is Working with USB devices in .NET and C#.


这篇关于C#CreateFile导致USB设备关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆