Loghorn / ant-plus

A node module for ANT+
MIT License
138 stars 70 forks source link

Stick not found #29

Closed pbrickell closed 4 years ago

pbrickell commented 4 years ago

I am getting stick not found but I can see the device using lsusb...

Bus 001 Device 007: ID 0fcf:1008 Dynastream Innovations, Inc. ANTUSB2 Stick.

Are there any options I might need to add to calls that might help?

clough360 commented 4 years ago

I've just run into this one myself and am currently investigating. Looking at the code it filters based on product / vendor id, and whether the device is in use:

    private getDevices() {
        const allDevices = usb.getDeviceList();
        return allDevices
            .filter((d) => d.deviceDescriptor.idVendor === this.idVendor && d.deviceDescriptor.idProduct === this.idProduct)
            .filter(d => USBDriver.deviceInUse.indexOf(d) === -1);
    }

One possibility is because we are (certainly I am) not using a garmin stick, but the code, as written, is looking specifically for Garmin vendor id .

As you can see it is looking for a specific vendor and product. When you create a garmin stick, it creates it with a specific vendor, and if this doesn't match the actual stick vendor, it will not work:

    constructor(dbgLevel = 0) {
        super(0x0fcf, 0x1008, dbgLevel);
    }
}

However, for my Anself device, they do match (according to device manager's 'Device Instance Path' property:

USB\VID_0FCF&PID_1008\123

The other option, therefore is that it is in use somehow.

if I run a js script like this:

var usb = require('usb');
usb.getDeviceList().filter(d => d.deviceDescriptor.idProduct === 0x1008).forEach(d => console.log("dev", d));

then my device is shown in the list;

clough360 commented 4 years ago

It goes wrong here for me:

public open(): boolean {
        const devices = this.getDevices();
        while (devices.length) {
            try {
                this.device = devices.shift();
                this.device.open();
                this.iface = this.device.interfaces[0];
                try {
=====>>>>>      if (this.iface.isKernelDriverActive()) {
                        this.detachedKernelDriver = true;
                        this.iface.detachKernelDriver();
                    }
                } catch {
                    // Ignore kernel driver errors;
                }
                this.iface.claim();
                break;
            } catch {
                // Ignore the error and try with the next device, if present
                this.device.close();
                this.device = undefined;
                this.iface = undefined;
            }
        }

If I change the code to output the error, I get: kernel error Error: LIBUSB_ERROR_NOT_SUPPORTED

I have installed the WinUSB driver (several times!). I am on Windows 10

pbrickell commented 4 years ago

I am running this on ubuntu with node 14.0. I have tried 18.04 and 20.04. Its curious, if I run the sample code on my desktop It works. If I run on either of may laptops (one is 18 the other is 20) I get a problem.

For me it's the open that fails...

usb.Device.open (/home/paul/workspace/ride/node_modules/usb/usb.js:38) USBDriver.open (/home/paul/workspace/ride/node_modules/ant-plus/src/ant.ts:343) (anonymous function) (/home/paul/workspace/ride/index.js:29) listOnTimeout (timers.js:549) processTimers (timers.js:492) [ Timeout ] init (inspector_async_hook.js:25) emitInitNative (async_hooks.js:144) emitInitScript (async_hooks.js:350) initAsyncResource (timers.js:153) Timeout (timers.js:186) setTimeout (timers.js:144) (anonymous function) (/home/paul/workspace/ride/index.js:28) Module._compile (loader.js:1182) Module._extensions..js (loader.js:1205) Module.load (loader.js:1034) Module._load (loader.js:923) executeUserEntryPoint (run_main.js:71) (anonymous function) (run_main_module.js:17)

It calls __open() which throws an error. If I run the code with the stick removed It never executes this.

pbrickell commented 4 years ago

It must be some characteristic of the laptops. Both are hp but have different OS and different specs.

clough360 commented 4 years ago

I'm on a dell laptop. I can try on my desktop.

pbrickell commented 4 years ago

Both of my laptops are recent ubuntu installs, one is 18 the other is 20. My desktop is running ubuntu 18 but it is a dev machine and has had many and varied installs of libs. I wonder if I have some missing USB libraries.

pbrickell commented 4 years ago

OK success. The problem on both my laptops was with the USB susbsytem. The following steps were required...

  1. sudo usermod -a -G dialout paul
  2. Reboot (logout didn't seem to work)
  3. sudo edit /etc/udev/rules.d/90-usbpermission.rules
  4. Add line SUBSYSTEM=="usb",GROUP="users",MODE="0666"
  5. sudo service udev restart

Also everything worked running as root with no changes required. For Windows maybe running as administrator may help.