"could not send feature report to device"

I wrote a quick test to repeatedly switch on every third led attached to a BlinkStick Pro, starting at the first, then the second, then third LED, then back to the first. This creates the impression of running lights.

The program runs for a few cycles, but then I will get an error:

H:\dev\node\pWinStatusBlinkStick\test.js:42
    if (oError) throw oError;
                      ^
Error: could not send feature report to device
    at Error (native)
    at retryTransfer (H:\dev\node\pWinStatusBlinkStick\node_modules\blinkstick\blinkstick.js:1311:29)
    at BlinkStick.setFeatureReport (H:\dev\node\pWinStatusBlinkStick\node_modules\blinkstick\blinkstick.js:1337:5)
    at BlinkStick.setColors (H:\dev\node\pWinStatusBlinkStick\node_modules\blinkstick\blinkstick.js:688:10)
    at fSetColors (H:\dev\node\pWinStatusBlinkStick\test.js:41:15)
    at H:\dev\node\pWinStatusBlinkStick\test.js:31:5
    at Array.forEach (native)
    at fRun [as _onTimeout] (H:\dev\node\pWinStatusBlinkStick\test.js:17:17)
    at Timer.listOnTimeout (timers.js:110:15)

This is the code I’m using:

var mBlinkStick = require('blinkstick'),
    aoBlinkSticks = mBlinkStick.findAll();
var uBlinkSticksModeChanged = 0;
var uWalkerIndex = 0;

aoBlinkSticks.forEach(function (oBlinkStick) {
  oBlinkStick.setMode(2, function () {
    if (++uBlinkSticksModeChanged == aoBlinkSticks.length) {
      fRun();
    };
  });
});

function fRun() {
  uWalkerIndex++;
  var uBlinkSticksUpdated = 0;
  aoBlinkSticks.forEach(function (oBlinkStick) {
    var aauColors = [];
    for (var uChannel = 0; uChannel < 3; uChannel++) {
      var auColors = [];
      for (var uIndex = 0; uIndex < 64; uIndex++) {
        if (uIndex % 3 == uWalkerIndex % 3) {
          auColors.push(255, 255, 255);
        } else {
          auColors.push(0, 0, 0);
        };
      };
      aauColors.push(auColors);
    };
    console.log(uWalkerIndex);
    fSetColors(oBlinkStick, aauColors, function () {
      if (++uBlinkSticksUpdated == aoBlinkSticks.length) {
        setTimeout(fRun, 100);
      }
    });
  });
};
function fSetColors(oBlinkStick, aauColors, fCallback) {
  var auColors = aauColors.pop(),
      uChannel = aauColors.length;
  oBlinkStick.setColors(uChannel, auColors, function(oError) {
    if (oError) throw oError;
    if (aauColors.length > 0) {
      fSetColors(oBlinkStick, aauColors, fCallback);
    } else {
      fCallback();
    };
  });
};
setInterval("", 100000000); // do not exit!

This may be related to the slow findAll() issue: a reboot resolves both (for a while at least).

This happens to me on Windows machine occasionally. Could be related to OS, because I’m working with C#, so probably not API implementation related.

Have you thought about adding a retry for a few times before failing completely? Between retries add 20ms delay.

Yes, I already implemented that :). However, the blinkstick module code is sometimes hung for a while before reporting this error, (which is why it’s similar to the findAll() problem). This completely breaks the running light effect :frowning:. Adding another timeout would make it even worse, and from testing it doesn’t seem to be required or make a difference. It also doesn’t always hang…

EDIT: the hang appears to happen during the next setColors() after I get an error…

I have a suspicion that node-hid may be causing this. Will try to reproduce this today.

I’m currently running this test. How long does it take before it hangs for you?

I will get the error within seconds, maybe a minute if I’m lucky. trying the same thing again immediately normally works, so I’ve modified my code to retry up to 10 tens before giving up. That seems to work fine for me: there’s no noticeable delay in color updates when an error occurs.

The slow responses are harder to trigger: it may even be a problem with my motherboard’s USB hardware, since a reboot fixes it and since I also had that unexplained problem where two BlinkSticks were not recognized as valid USB devices until I plugged them into a port that a working BlinkStick had been connected to before… Also, I haven’t had that issue in a few days now, even though I am running tests on my BlinkSticks and swapping them around all the time: I doubt you’ll be able to trigger it at will. I’d advise you to focus on more important things, and I will see if I can find out where in the code exactly it is getting stuck should it happen again.

Got it. I’m now trying to set up a build environment to automatically rebuild all node-hid for all node versions. Apparently NW.js needs a separate setup too, but it seems to be to cool not to include it.