1

I use the following code to receive data from an ANT+ dongle I used other software (Zwift, which shows that the dongle actually received data) (Using OS X):

/* Require the config */
require('dotenv').config()
/* require the usb class */
var usb = require('usb');

/* find the device */
var device = usb.findByIds(process.env.VENDOR_ID, process.env.PRODUCT_ID);
/* open the device */
device.open(true);
/* claim interface WHERE IS THIS FOR */
const [interface] = device.interfaces;
interface.claim();

/* Start Polling */
const [inEndpoint, outEndpoint] = interface.endpoints;
inEndpoint.startPoll();
// inEndpoint.transferType = 2;

inEndpoint.on('data', (d) => {
    console.log("usb data:", d, " len:", d.length)
});

inEndpoint.on('error', function (error) {
    console.log("on error", error);
});

Do I do something wrong?

Underneath you find some loggin, I think I do everything right but it has to do something with node.

[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.003821] [00000307] libusb: debug [libusb_get_device_list] 
[ 0.003925] [00000307] libusb: debug [libusb_get_device_descriptor] 
[ 0.004005] [00000307] libusb: debug [libusb_get_device_descriptor] 
[ 0.004021] [00000307] libusb: debug [libusb_get_device_descriptor] 
[ 0.004033] [00000307] libusb: debug [libusb_get_device_descriptor] 
[ 0.004125] [00000307] libusb: debug [libusb_open] open 20.9
[ 0.004269] [00000307] libusb: debug [usbi_add_pollfd] add fd 26 events 1
[ 0.004275] [00000307] libusb: debug [darwin_open] device open for access
[ 0.004301] [00004903] libusb: debug [handle_events] poll() returned 1
[ 0.004306] [00004903] libusb: debug [handle_events] caught a fish on the control pipe
[ 0.004319] [00004903] libusb: debug [libusb_get_next_timeout] no URBs, no timeout!
[ 0.004322] [00004903] libusb: debug [libusb_try_lock_events] someone else is modifying poll fds
[ 0.004324] [00004903] libusb: debug [libusb_event_handler_active] someone else is modifying poll fds
[ 0.004327] [00004903] libusb: debug [libusb_handle_events_timeout_completed] another thread is doing event handling
[ 0.004368] [00004903] libusb: debug [libusb_get_next_timeout] no URBs, no timeout!
[ 0.004380] [00004903] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.004384] [00004903] libusb: debug [handle_events] poll fds modified, reallocating
[ 0.004389] [00004903] libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
[ 0.004736] [00000307] libusb: debug [libusb_claim_interface] interface 0
[ 0.005084] [00000307] libusb: debug [get_endpoints] building table of endpoints.
[ 0.005100] [00000307] libusb: debug [get_endpoints] interface: 0 pipe 1: dir: 1 number: 1
[ 0.005107] [00000307] libusb: debug [get_endpoints] interface: 0 pipe 2: dir: 0 number: 1
[ 0.005133] [00000307] libusb: debug [darwin_claim_interface] interface opened
[ 0.005445] [00000307] libusb: debug [ep_to_pipeRef] converting ep address 0x81 to pipeRef and interface
[ 0.005454] [00000307] libusb: debug [ep_to_pipeRef] pipe 1 on interface 0 matches
[ 0.005540] [00000307] libusb: debug [ep_to_pipeRef] converting ep address 0x81 to pipeRef and interface
[ 0.005547] [00000307] libusb: debug [ep_to_pipeRef] pipe 1 on interface 0 matches
[ 0.005572] [00000307] libusb: debug [ep_to_pipeRef] converting ep address 0x81 to pipeRef and interface
[ 0.005576] [00000307] libusb: debug [ep_to_pipeRef] pipe 1 on interface 0 matches
[60.006611] [00004903] libusb: debug [handle_events] poll() returned 0
[60.006708] [00004903] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[60.006727] [00004903] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[60.006742] [00004903] libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
[120.011876] [00004903] libusb: debug [handle_events] poll() returned 0
[120.011973] [00004903] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[120.011994] [00004903] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[120.012007] [00004903] libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
[180.012077] [00004903] libusb: debug [handle_events] poll() returned 0
[180.012106] [00004903] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[180.012112] [00004903] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[180.012116] [00004903] libusb: debug [handle_events] poll() 3 fds with timeout in 60000ms
Jasper Fioole
  • 449
  • 1
  • 5
  • 25
  • 1
    I'm wondering why this even compiles... `const [interface] = device.interfaces;`, `interface` is a reserved keyword in typescript. – pascalpuetz Aug 17 '19 at 20:49
  • @pascalpuetz `interface` is only a reserved keyword in strict mode. That means as long as the above code doesn't export anything and escalate itself into a module (which are automatically strict), it's weird to read but legal grammar. – Etheryte Aug 17 '19 at 20:56
  • @Nit Thanks for the claryfication, I didn't know it was only reserved in strict mode. The more you know. – pascalpuetz Aug 17 '19 at 20:57
  • I'm not using strict mode and changing the variable name does not alter my result, unfortunately still stuck. – Jasper Fioole Aug 18 '19 at 20:55
  • There is a lot to debug here: what other interfaces and endpoints exist? Are you using the right ones? What are their descriptors? Did you try setting their timeout value? What are the device addresses? And so on. – B M Aug 19 '19 at 21:47
  • @BM in/out do exist like the docs, address is 9. Descriptors look fine, what do you want to know? – Jasper Fioole Aug 20 '19 at 15:51
  • If all those look like expected my next approach would be to set the timeout to an actual value (default should be infinity) and see if it is reached. If not, I would guess the polling never starts? You could try a `controlTransfer` on the `Device` or a manual `transfer` on the `InEndpoint`. Also, does the `release` function work? I would also recommend trying `usb.setDebugLevel` with a more detailed log level. Another option is the `usb.on('attach'...` listener to see if attaching the device triggers an event. Just my ideas, not sure if they help. – B M Aug 20 '19 at 16:54
  • @BM I have tried the things you said but no luck so far. setDebugLevel was already on 4, this is the highest right? – Jasper Fioole Aug 20 '19 at 17:33

0 Answers0