我花了太多時間試圖理解這裏的問題。我正在使用HID條形碼掃描儀,並能夠獲取設備信息。但即使使用正確的設備ID,我也無法獲得HidDevice對象的保留。它總是返回null。以下是我有:HIdDevice.fromIdAsync總是返回null
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);
});
我在清單文件中添加了這些設備的功能:
<DeviceCapability Name="humaninterfacedevice">
<Device Id="any">
<Function Type="usage:0001 *"/>
</Device>
</DeviceCapability>
您測試了[CustomHidDeviceAccess](https://github.com/Microsoft/Windows-universal-samples/tree/6370138b150ca8a34ff86de376ab6408c5587f5d/Samples/CustomHidDeviceAccess)示例嗎?如果沒有,請參考。 –
謝謝。我有,並且由於其中的選擇器已配置爲與SuperMUTT設備配合使用,因此我更改了usageID和usagePageID以讓它選取鍵盤式HID設備。當我看到列出的設備時,我無法連接到它們。另外,如果這對JavaScript有任何影響,我正在使用JavaScript。 – newbee8