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

时间:2016-05-18 20:15:55

标签: linux node.js libusb raspberry-pi3

我在raspberry pi 3(debian)上运行node.js.

我有一个小型原型项目,它从我的涡轮增压训练机上的ANT +发射器收集数据,这是通过Suunto Movestick USB加密狗发送的。

我正在使用Ant-Plus节点模块来管理ANT +协议和一个脚本,该脚本将数据输出到控制台并通过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)

在搜索过周围,由于节点进程没有正常关闭,似乎某些进程仍然连接到USB。

我尝试过各种方法来杀死这个过程:

ps | grep <something>
kill <somepid>

killall node
但不知怎的,我不认为这是我需要杀死的节点进程,我“觉得”我需要以某种方式清理USB接口,但我不知道我会怎么做。

该项目使用node-usb库,但我不确定是否可以用某种方式清理它。

1 个答案:

答案 0 :(得分:2)

我对此做了一些研究:原因是Raspberry Pi将内核驱动程序附加到连接的设备上。您需要检查内核驱动程序并在声明界面之前将其分离。

看到你正在使用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()
})