【发布时间】:2020-10-09 12:23:14
【问题描述】:
我正在尝试从 Node JS 中的条形码扫描仪中检索扫描的数据。我不确定这是否是正确的问题。如果问题错了,请见谅。
条形码扫描仪型号是 Honeywell MS 9540。我不知道如何实现它。 Node JS 发现它是一个 USB 设备。有什么方法可以实现吗?
我正在 Electron 中为 Windows 构建一个应用程序,并考虑使用本地 Node JS 服务器从设备中检索数据。
我在 Node JS 中使用了 usb-barcode-scanner 包。它可以在其他 USB 设备中找到条码扫描器。但我收到一个错误:
Error: cannot open device with vendor id 0xc2e and product id 0x200
这是我的代码:
const express = require('express')
const app = express()
const { getDevices, UsbScanner } = require('usb-barcode-scanner')
console.log(getDevices())
let scanner = new UsbScanner({
vendorId: 3118,
productId: 512,
path: '\\\\?\\hid#vid_0c2e&pid_0200#6&24268576&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\\kbd'
/** You could also initialize the scanner by giving entering the path variable:
* path: 'IOService:/AppleACPI etc...'
**/
});
scanner.on('data', (data) => {
console.log(data);
});
app.listen(8000, function () {
console.log(`Express listening on port ` + 8000)
});
【问题讨论】:
-
这篇文章可能会有所帮助。 Can't get hidraw0 device to open in nodeJS app 或者尝试使用另一个类似的库。 node-usb-barcode-scanner, HID Scanner 或者将扫描仪改为串口模式。 device hunt, serial port based barcode scanner #1498
-
感谢您的回答。我已经意识到条码扫描仪就像键盘一样工作。只有一些输入应该被聚焦,扫描结果将是聚焦输入的值。
标签: node.js barcode-scanner honeywell