简体   繁体   English

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

[英]How to solve LIBUSB_ERROR_BUSY on Raspberry Pi (Debian) running Node.js

I am running node.js on a raspberry pi 3 (debian). 我在树莓派3(debian)上运行node.js。

I have a little prototype project which gathers data from an ANT+ transmitter on my turbo trainer, which is being sent via a Suunto Movestick USB dongle. 我有一个小的原型项目,该项目从我的涡轮训练器上的ANT +发射器收集数据,该数据通过Suunto Movestick USB加密狗发送。

I am using the Ant-Plus node module to manage the ANT+ protocol and a script which outputs the data to the console and sends via REST API to cloud storage. 我正在使用Ant-Plus节点模块来管理ANT +协议和一个脚本,该脚本将数据输出到控制台并通过REST API发送到云存储。

Anyhow, cutting to the chase, it was all working fine, multiple process start and stops with no problems, until I inadvertently killed the process by hitting ctrl + z instead of ctrl + c 无论如何,顺其自然,一切正常,多个进程启动和停止都没有问题,直到我无意中按下ctrl + z而不是ctrl + c杀死了该进程

Now I just get the following error, when trying to run my script: 现在,当我尝试运行脚本时,出现以下错误:

/home/pi/ant-plus/node_modules/usb/usb.js:168 this.device.__claimInterface(this.id) ^ /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)

It would appear, having searched around, that due to the node process not being shut down gracefully, that some process is still connected to the USB. 进行搜索后,似乎发现由于节点进程未正常关闭,某些进程仍连接到USB。

I have tried all sorts of ways to kill the process: 我尝试了各种方法来终止进程:

ps | grep <something>
kill <somepid>

killall node

Somehow though, I don't think it's the node process I need to kill, I "feel" like I need to somehow clean the USB interface, but I don't have a clue how I would do that. 尽管不知何故,我不认为这是我需要杀死的节点进程,我“感觉”到需要某种方式清理USB接口,但是我不知道该怎么做。

The project uses the node-usb library, but I'm not sure if can use that in some way to clean things up. 该项目使用node-usb库,但是我不确定是否可以以某种方式使用它来清理内容。

I did some research into this: The reason is that the Raspberry Pi attaches a kernel driver to connected devices. 我对此进行了一些研究:原因是Raspberry Pi将内核驱动程序附加到连接的设备。 You need to check for a kernel driver and detach it before claiming the interface. 您需要在声明接口之前检查内核驱动程序并将其分离。

Seeing as you are using node-usb , here is some pseudo code: 看到您正在使用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()
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM