linux – Re-attaching kernel driver for the usb interface (Node.js)

I have some issue with usb library in NodeJS. I try to send some command via usb to some device from Armbian Linux. My code looks like this

const usb = require("usb");
const elzabUSB = usb.findByIds(1155, 22336);

elzabUSB.open();

let interface = elzabUSB.interfaces[1];
let flag = false;

if (interface.isKernelDriverActive()) {
    flag = true;
    interface.detachKernelDriver();
}

interface.claim();

let out = interface.endpoints[0];

let cmd; // some data to be send 

out.transfer(cmd, function (err) { //
    if (err) console.log(err);
    console.log("OK");
});

setTimeout(() => {
    interface.release((err) => {
        if (err) console.log(err);
        try {
            if (flag) interface.attachKernelDriver(); // error here
            elzabUSB.close();
        } catch (err) {
            console.log(err);
        }
    });
}, 500);

Because my host is Armbian Linux I must detach kernel driver from my usb to do at least something with Endpoints. And when i try to reset settings to default values using Interface function .attachKernelDriver() I got this error…

{ Error: LIBUSB_ERROR_NOT_FOUND
    at Interface.attachKernelDriver (/home/felg/node_modules/usb/usb.js:330:21)
    at Interface.interface.release (/home/felg/usb.js:74:62)
    at Device.<anonymous> (/home/felg/node_modules/usb/usb.js:316:7) errno: -5 }

If someone had this error and knows how to solve it, then please response.

best regards

Read more here: Source link