Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

c# - Cannot create UsbDevice from DeviceInformation.Id

I'm trying to connect to a device (SecuGen Hamster Pro 20) through Windows.Devices.Usb APIs using Universal Windows App for PC only (no phones)(WinRT).

The device is a fingerprint scanner.

I've done all the steps found online to do that:

I've looked for all devices using:

var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync();

This returns about 1400 devices. After some filteration using:

 var resultList = myDevices.Where(s => s.Name.ToLower().Contains("secu")).ToList<DeviceInformation>();

resultList contains 3 devices in my machine (I've tried it on other machine and found 10 results on some).

I didn't use the overload for finding devices DeviceInformation.FindAllAsync(String aqsFilter) because it returns 0 results althought I'm sure I've done it right (used correct VID & PID)

The problem here is when I try to create a UsbDevice object from any of the 3 results using:

UsbDevice device = await UsbDevice.FromIdAsync(resultList[0].Id);

The return value is null, I've tried all of them (resultList[0] , resultList[1] , resultList[2]) with no luck.

I configured the capabilities using:

 <DeviceCapability Name="usb">
      <Device Id="vidpid:1162 2200">
        <Function Type="name:vendorSpecific"/>
      </Device>
    </DeviceCapability> 

I also tried to create a UsbDevice object from any of the 1400 devices returned from DeviceInformation.FindAllAsync() but all returned null and even some throw an exception that says the system cannot find the file specified 0x80070002

I tried to read DeviceAccessInformation for the device it returned DeviceAccessStatus.Unspecified

Anyone can lead me to what am I missing here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to use UsbDevice.GetDeviceSelector and then use the selector when searching for the device. If that returns nothing, then the device isn't properly 'configured' to use the WinUSB.sys driver. (And from what I understand, it must use that driver to be used with the usbdevice class).

If you manually told it to use that driver in the device manager, then, in theory, you still have to change a key with regedit before that works (Note: I did that and it still wouldn't work). I found a solution that solved it here: http://www.lewisbenge.net/2013/09/20/integrating-windows-8-1-with-owi-535-robotic-arm/ Basically, you have to install the driver using an inf file. use the one linked on that site and replace the NTamd64 with NTarm depending on the target platform


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...