webusb - Google Chrome WebUSB API requestDevices() 看不到条形码扫描仪 Voyager 1450g
问题描述
我正在尝试访问通过 USB 连接的 Voyager 1450g 条形码扫描仪,但 navigator.usb.requestDevices() 看不到此设备。
let button = document.getElementById('request-device');
button.addEventListener('click', async () => {
let device;
try {
device = await navigator.usb.requestDevice({ filters: [{}]});
} catch (err) {
// No device was selected.
console.log('Error:', err);
}
解决方案
我有一台 Honeywell Voyagar 1202g 条码扫描仪,我设法在 Mac 和 Windows 上工作。
首先,您需要将条形码扫描仪界面更改为 CDC-ACM,方法是使用 EZConfig(霍尼韦尔软件)或扫描您可以在其网站上找到的条形码。
使其在 Windows 上运行的步骤:
- 安装 Zadig
- 安装 HSM USB 串行驱动程序包
- 在 Windows 设置中找到您的设备并更新 USB 复合设备驱动程序(让我从驱动程序列表中选择,取消选中兼容驱动程序)以使用 Honeywell->WinFlash Intermec 设备(没有这一步 Zadig 无法找到正确的接口)。
- 使用 Zadig,您现在应该可以看到您的设备,将驱动程序更新为 libusbk
- 重启电脑(重要)
代码:
const decoder = new TextDecoder();
const startDevice = async () => {
try {
// you should be able to discover your PRODUCT_ID and VENDOR_ID from
// chrome://device-log
const device = await navigator.usb.requestDevice({
filters: {
productId: PRODUCT_ID,
vendorId: VENDOR_ID
}
});
// log device data to see available configurations and interfaces
await device.open();
// only 1 configuration was available for me
await device.selectConfiguration(1);
// interface 1 was bulk transfer
await device.claimInterface(1);
readLoop(device);
} catch (error) {
console.error(error);
}
}
const readLoop = async (device) => {
try {
const result = await device.transferIn(1, 64);
// this is your incoming data
const data = decoder.decode(result.data).trim();
readLoop(device);
} catch (error) {
console.error(error);
}
}
推荐阅读
- db2 - 检查渐变维度 2
- excel - 如何将这行 VBA 转换为 LibreOffice Basic?
- javascript - 在 Electron 中支持 HEVC/H.265 视频
- python - 在 Python 3 中未找到 RPi.GPIO
- python - 用python提取正则表达式的数据
- python - 如何在 Django 日历中翻译星期几和月份的名称
- javascript - 尝试提交和验证表单,但它挂起并出现错误 - 标题:ValidatorError: Path `title` is required
- google-bigquery - BigQuery 如何以 30 分钟的延迟处理一个小时的数据?
- python - 写入设置为文件和格式
- python - 替换 tkinter 列表框中预定义的键绑定函数