linux - 如何在运行 Node.js 的 Raspberry Pi (Debian) 上解决 LIBUSB_ERROR_BUSY

标签 linux node.js libusb raspberry-pi3

我在树莓派 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/

相关文章:

linux - Grep 到剪贴板

javascript - 在文件夹中运行所有浏览器化的 Mocha 测试

node.js - socket.to(socket.id).emit() 不起作用

python - 构建 Cython-HIDapi Python 2.7

c - 每 x 秒运行一次函数

linux - 有效地使命令超时并将输出捕获到 bash 脚本中的变量

linux - 为什么 "pstack"只打印一个线程的内容?

node.js - 为什么 Mongoose 验证器不验证字段类型?

usb - 使用 libusb : libusb_bulk_transfer() 在笔式驱动器上读/写