Giter Site home page Giter Site logo

Comments (5)

todbot avatar todbot commented on August 27, 2024 1

What is the issue you are having with node-hid? (I am one of the maintainers)

from hidapi.

Gayathri-Rajamanickam-MindTree avatar Gayathri-Rajamanickam-MindTree commented on August 27, 2024

We are using write method - device.write(data) from node-hid to write into hid device using windows 10.

We are appending first byte as '4' as per this fix reported here - node-hid/node-hid#187

Following is the example data buffer that we send to the device

4,103,73,72,48,115,67,105,65,103,73,109,108,107,73,106,111,103,73,106,65,121,79,68,89,53,78,71,81,119,76,87,69,53,78,68,89,116,77,84,70,108,79,83,49,104,78,122,82,104,76,84,100,107,89,50,73,119,89,106,81,121,78,122,73

For single write, it works fine.

But when we write in a loop for about 100/500 times without any delay, it hangs in the write method.

from hidapi.

todbot avatar todbot commented on August 27, 2024

How fast are you attempting to write data? How big is the HID report you are attempting to send and what is the size of your device's max packet size?

USB HID can only support one report every 1 millisecond. At best, and that depends on how many hubs are between the OS and the device and the HID driver on the OS. In practice it's usually much less.

It would be interesting to see if you could write a native C version of your loop (using hidapi, which node-hid is just a thin wrapper on) and see if you get the same hangs.

from hidapi.

Gayathri-Rajamanickam-MindTree avatar Gayathri-Rajamanickam-MindTree commented on August 27, 2024

We have tested hidapi with native C. we are able to reproduce this issue. so the issue seems to be with hidapi. For workaround, we tried to introduce a delay of 20 milliseconds between writes in native C. In that case, it doesn't hang.

Can you please let us know how to introduce this kind of delay in write operation when using node-hid module?

from hidapi.

todbot avatar todbot commented on August 27, 2024

That's more of a general Node.js question and depends on how your code is structured. But I might approach it using Node Timers:

const reportsToSend = [[]];  // array of byte arrays
const sentReportCount = 0;
const sendRateMillis = 100;  // send report once every 100 milliseconds
const sendTimer = setInterval( function() {
  const nextReport = reportsToSend[currentReport];
  hidDevice.write(nextReport);
  sentReportCount++;
  if( sentReportCount == reportsToSend.length ) {
    clearInterval(sendTimer);
  }
}, sendRateMillis);

from hidapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.