Error when trying to use pulse() multiple times

Hey there,
i bought a BlinkStick Flex about a week ago, and it is absolutely awesome!

My problem now:
I have tried to pulse a random LED (of 32 total) with the C# function Pulse().

The first LED does its task perfectly, but the second time i try to call Pulse() the app crashes with this Exception:

System.IO.IOException: "GetFeature failed."

(in the WinHidStream.cs file)

What am I missing here?

My test-code:

 BlinkStick BStick = BlinkStick.FindFirst();
 BStick.OpenDevice(); 
 BStick.Pulse(0, *random number*, 255, 255, 255, 1, 500,50);
 BStick.Pulse(0, *random number*, 255, 255, 255, 1, 500,50);
 BStick.Pulse(0, *random number*, 255, 255, 255, 1, 500,50);
 BStick.CloseDevice();

btw: this happens completly random. Sometimes it works sometimes it crashes on the second Pulse().

Thank you and greetings from Germany :slight_smile:

Hi Bennet an welcome to the forums.

You need a delay between the different pulse command lines like:

Thread.Sleep(20);

This avoids sending the signals to fast to the device and should do the trick for you.

Hey p0ke,
thank you for this quick reply.

I have tried this out. With Window’s Thread.Sleep() and with the BlinkStick.WaitThread()
And again… first LED pulse runs through,then Error…

So it looks like this now?

BStick.Pulse(0, *random number*, 255, 255, 255, 1, 500,50);
Thread.Sleep(20);
BStick.Pulse(0, *random number*, 255, 255, 255, 1, 500,50);
Thread.Sleep(20);
BStick.Pulse(0, *random number*, 255, 255, 255, 1, 500,50);
Thread.Sleep(20);

There is definitely still something wrong with your code.

More like this:

private static void InfiniteRandomPulse()
{
  BStick.OpenDevice();
  while (RunThread)
  {
    RandomPulse(BStick);
    Thread.Sleep(25);
  }
  BStick.CloseDevice();
}

Function RandomPulse:

private static void RandomPulse(BlinkStick BlinkStickHandle)
    {
  Random random = new Random();
  int LEDIndex = random.Next(31);
  BlinkStickHandle.Pulse(0, (byte)LEDIndex, (byte)random.Next(254), (byte)random.Next(254), (byte)random.Next(254));
  BlinkStickHandle.WaitThread(1000);
    }

OK, it´s not your code.
Pulse does not seem to work for a single LED at the moment. This must be a problem in the library or maybe with the device firmware itself. The pulse function needs to get back the current color of the LED and this seems to work only once.

There is a similar problem with the python lib: Blinkstick Nano bottom led morph and pulse cause error

So I fear I cannot help here and we need to wait for @arvydas

Ahh thank you!

No Problem, I will create a Pulse Methode myself :wink:

@bennet_2013 did you create a non crashy pulse method?