【问题标题】:How to solve LIBUSB_ERROR_BUSY on Raspberry Pi (Debian) running Node.js如何在运行 Node.js 的 Raspberry Pi (Debian) 上解决 LIBUSB_ERROR_BUSY
【发布时间】:2016-05-18 20:15:54
【问题描述】:

我在树莓派 3 (debian) 上运行 node.js。

我有一个小型原型项目,它从我的 turbo 训练器上的 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 库,但我不确定是否可以以某种方式使用它来清理。

【问题讨论】:

    标签: linux node.js libusb raspberry-pi3


    【解决方案1】:

    我对此进行了一些研究:原因是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()
    })
    

    【讨论】:

    • 感谢,完全错过了回复,有一段时间没有回项目了!
    猜你喜欢
    • 2012-05-21
    • 2023-04-04
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多