我试图访问通过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);
}

答案 0 :(得分:2)
我有一台霍尼韦尔Voyagar 1202g条形码扫描仪,设法在Mac和Windows上正常工作。
首先,您需要通过使用EZConfig(霍尼韦尔软件)或扫描在其网站上找到的条形码,将条形码扫描仪的界面更改为CDC-ACM。
使其在Windows上运行的步骤:
代码:
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);
}
}
答案 1 :(得分:1)
我的猜测是虚拟串口驱动程序(将其安装为COM3)捕获了设备。也许卸载驱动程序再试一次?