我想制作一个可以访问 USB 智能卡读卡器(HID Global OmniKey 3121)的 Chrome 应用程序。
有人成功地做到了这一点吗?
不幸的是,我无法使用usb.getDevices
.
script.js(由index.html调用,它本身由background.js onLaunched
调用):
//dom elements
var findBtn = document.querySelector( "button#find-btn" )
var deviceInfo = document.querySelector( "p#device-info" )
//{click}
findBtn.addEventListener( "click", findDevice )
/*
* Try to find HID OmniKey 3x21
*/
function findDevice ()
{
var options = {
filters: [
{
vendorId: 1899, //OmniKey AG
productId: 12321 //CardMan 3121 but PID=0x3021
}
]
}
chrome.usb.getDevices( options, function ( devices )
{
console.log( devices )
deviceInfo.innerHTML = JSON.stringify( devices[0] )
} )
}
该设备在清单中声明,并在扩展页面中被 Chrome 识别。
预先感谢您的帮助。
编辑
这是我的manifest.json:
{
"manifest_version": 2,
"name": "Card Reader",
"description": "Smartcard reader",
"version": "0.0.2",
"minimum_chrome_version": "43",
"app": {
"background": {
"scripts": [ "js/background.js" ]
}
},
"permissions": [
"usb",
{
"usbDevices": [
{
"vendorId": 1057,
"productId": 1633
},
{
"vendorId": 1133,
"productId": 49271
},
{
"vendorId": 1899,
"productId": 12321
}
]
}
]
}
3 个允许的设备是:
- 诺基亚 Lumia 920
- 戴尔光电鼠标
- OmniKey 智能卡读卡器 3121
usb.getDevices
或仅识别鼠标usb.findDevices
。只有鼠标由 列出usb.getUserSelectedDevices
。