newbee8
newbee8

Reputation: 31

HIdDevice.fromIdAsync always returns null

I spent way too much time trying to understand the problem here. I am working with a HID Barcode Scanner, and am able to get the device information. But I am unable to get a hold of the HidDevice object even with the right device id. It always return null. Here is what I have:

   var selector = Windows.Devices.HumanInterfaceDevice.HidDevice.getDeviceSelector(parseInt('0x1', 16), parseInt('0x6', 16));

        Windows.Devices.Enumeration.DeviceInformation.findAllAsync(selector, null).then(
               function (deviceInfoCollection) {
                   if (deviceInfoCollection.length > 0) {
                       for (var i = 0; i < deviceInfoCollection.length; i++) {
                           var id = deviceInfoCollection.getAt(i).id;
                           return Windows.Devices.HumanInterfaceDevice.HidDevice.fromIdAsync(id, Windows.Storage.FileAccessMode.readWrite);
                       }
                   }
                   else {
                       throw "No Devices Discovered.";
                   }
               })
        .done(function (device) {
            if (device != null)
                successCallback(device.name);
        });

I added these device capabilities in my manifest file:

<DeviceCapability Name="humaninterfacedevice">
    <Device Id="any">
      <Function Type="usage:0001 *"/>
    </Device>
  </DeviceCapability>

Upvotes: 1

Views: 522

Answers (1)

Dave Grabowski
Dave Grabowski

Reputation: 11

I'm going through the same issue now. The only thing I see in your code that strikes me as odd is the following manifest tag:

<Device Id="any">

Usually, the "any" value works. But I've had issues arise where the vendor and product id are required; I'm not quite sure why, but I think it's based off the type of device/usageid. I would try hardcoding the vendor and product id's to see if it makes a difference.

Another thought: I'm guessing by the usage tag that your scanner is configured as a keyboard. You can check to see if your scanner can be configured as a non-keyboard HID device, which helped me personally. I see other people on the internet having issues where an HidDevice is returned as null because another program is using that device; in your case, the OS might already be using the keyboard and locking it out somehow.

Best of luck!

Upvotes: 1

Related Questions