我在树莓派 3 (debian) 上运行 node.js。
我有一个小原型(prototype)项目,它从我的涡轮教练机上的 ANT+ 发射器收集数据,这些数据是通过 Suunto Movestick USB 加密狗发送的。
我正在使用 Ant-Plus
Node 模块来管理 ANT+ 协议(protocol)和将数据输出到控制台并通过 REST API 发送到云存储的脚本。
无论如何,切入正题,一切正常,多个进程启动和停止都没有问题,直到我无意中通过按 ctrl + z
而不是 ctrl + 终止了进程c
现在我在尝试运行我的脚本时遇到以下错误:
/home/pi/ant-plus/node_modules/usb/usb.js:168 this.device.__claimInterface(this.id) ^
Error: LIBUSB_ERROR_BUSY
at Error (native)
at Interface.claim (/home/pi/ant-plus/node_modules/usb/usb.js:168:14)
at GarminStick2.USBDriver.open (/home/pi/ant-plus/build/ant.js:287:20)
at Object.<anonymous> (/home/pi/ant-plus/sample/cadence-sensor.js:39:12)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
经过四处搜索,似乎由于 Node 进程未正常关闭,某些进程仍连接到 USB。
我已经尝试了各种方法来终止进程:
ps | grep <something>
kill <somepid>
killall node
虽然不知何故,我不认为这是我需要杀死的 Node 进程,我“感觉”我需要以某种方式清理 USB 接口(interface),但我不知道该怎么做。
该项目使用 node-usb图书馆,但我不确定是否可以以某种方式使用它来清理东西。
最佳答案
我对此做了一些研究:原因是 Raspberry Pi
将内核驱动程序附加到连接的设备。在声明接口(interface)之前,您需要检查内核驱动程序并将其分离。
鉴于您正在使用 node-usb
,这里是一些伪代码:
device.open()
const deviceInterface = device.interfaces[0]
let driverAttached = false
if (printerInterface.isKernelDriverActive()) {
driverAttached = true
deviceInterface.detachKernelDriver()
}
deviceInterface.claim()
// ... use the device interface
deviceInterface.release(() => {
if (driverAttached) {
deviceInterface.attachKernelDriver()
}
device.close()
})
关于linux - 如何在运行 Node.js 的 Raspberry Pi (Debian) 上解决 LIBUSB_ERROR_BUSY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37309311/