【发布时间】:2021-12-08 10:05:20
【问题描述】:
我有一个应用程序需要保持与 USB 设备的长时间(无限期)连接,并可能无限次地向其打印。所以,它需要在同一个设备接口上做很多声明。
最终我的应用程序崩溃了,因为在第 65 次声明中我收到了 LIBUSB_ERROR_ACCESS 错误。可以用node-usb 解决这个问题吗?可能与
- https://github.com/libusb/libusb/issues/16
- https://github.com/node-usb/node-usb/issues/302#issuecomment-988657538
环境和硬件
windows 11 home insider preview
nodejs v11.0.0
node-usb v1.5.0
node-escpos v2
代码
function testClaim() {
const d = new USB();
const p = new Printer(d, { encoding: 'Shift-JIS' });
const loop = (curr = 0) => {
console.log('LOOP', curr)
if (curr === 50) {
setTimeout(() => {
d.open(() => d.reset(() => {
console.log('RESET', curr)
// should not require the user to do anything, needs to be able to print indefinitely
loop(0)
}))
}, 1000);
return;
}
d.open(() => {
p.close(() => {
loop(curr + 1)
})
})
}
loop();
}
testClaim();
【问题讨论】:
标签: node.js windows usb libusb