Question

I'm trying to get the node-hid (https://github.com/node-hid/node-hid) module working on Windows 7. I can open a device and write to it, but no data ever arrives.

I've verified the device is sending data. I've dug through the node-hid code (HID.cc) and tried several things to get it working:

  • Modified the HID::recvAsync function to use an hid_read_timeout in a loop to see if that would return anything.
  • Set both blocking and non-blocking.
  • Changed buffer sizes to exactly fit what the device sends.

On Windows 8, with the hid_read_timeout call change, this all works fine. I'm not sure what may have changed between the two systems, but I plan on using this on windows XP as well, so I can't just call it good.

I'm struggling to come up with more ideas as to how to debug this issue. Has anyone successfully done this before? Is there a better option to use Node.js with an HID device?

Was it helpful?

Solution

After some serious debugging, I found that for some reason I have as of yet not been able to determine, the source file, HID.cc for the node module node-hid needed a call to hid_init() within the constructor before the hid_open call. I'm assuming that somehow this is getting hit with multiple threads, making the safety of calling hid_init before hid_open necessary.

I now have this working on both windows 7 and windows 8.

Summary of changes I had to make: Add hid_init before the hid_open call I'm using. Change hid_read to hid_read_timeout in a loop. (Since reads won't return on windows XP when shutting down otherwise.)

Once I've cleaned it up, I'll send the author my changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top