【发布时间】:2015-09-23 10:30:11
【问题描述】:
我想制作一个可以访问 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 仅列出鼠标。
【问题讨论】:
-
见this crbug issue。还要添加
manifest.json(或仅相关部分:权限、后台页面声明等)和该代码片段的文件名。 -
@wOxxOm 再次感谢您提供的链接。它让我找到了zadig.akeo.ie 替代 USB 驱动程序,它们被
chrome.usbAPI 识别。现在可以了!
标签: javascript html google-chrome-app smartcard-reader winusb