2016-08-19 19 views
0

код 1.myКак перечислить устройства USB? Позволяет UWP API для Node.js (чакре)

var uwp=require("uwp"); 

    uwp.projectNamespace("Windows"); 
    var deviceInformation = Windows.Devices.Enumeration.DeviceInformation; 
    var VID=0x10C4; 
    var PID=0x81B9; 
    deviceInformation.findAllAsync().done(
     function(devices){ 
     console.log(devices); 
     }, 
     function(err){ 
     console.log(err); 
     } 
    ); 

2.result: Windows.Devices.Enumeration.DeviceInformationCollection {

'0': Windows.Devices.Enumeration.DeviceInformation {}, 

'1': Windows.Devices.Enumeration.DeviceInformation {}, 

'2': Windows.Devices.Enumeration.DeviceInformation {}, 

'3': Windows.Devices.Enumeration.DeviceInformation {}, 

.......... 

'785': Windows.Devices.Enumeration.DeviceInformation {} } 

3.Reference: Windows API reference for Windows Runtime apps

Я alerady использование:

Windows.Devices.Enumeration

Windows.Devices.Enumeration.Pnp

Windows.Devices.HumanInterfaceDevice

Windows.Devices.Usb

, но по-прежнему возвращают пустой объект

ОС:. Windows, 10 Enterprise nodejs : Node.js (Chakra) [email protected]

Устройство может отображаться в диспетчере устройств

информация:

USB \ VID_10C4 & PID_81B9 \ 5 & 369d87d2 1.

Guid: {745A17A0-74D3-11D0-B6FE-00A0C90F57DA}

ответ

0

Вы должны перебирать устройства , попробуйте следующий код, чтобы получить идентификатор устройства.

var uwp = require("uwp"); 
uwp.projectNamespace("Windows"); 
var deviceInformation = Windows.Devices.Enumeration.DeviceInformation; 
deviceInformation.findAllAsync().done(
function (devices) { 
    for (var i = 0; i < devices.length; i++) { 
     console.log(devices[i].id); 
    } 
}, 
function (err) { 
    console.log(err); 
} 
);