Error when trying to use pulse() multiple times


#1

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:


#2

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.


#3

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…


#4

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.


#5

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);
    }

#6

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


Using morph on blinkstick pro with smart pixels
#7

Ahh thank you!

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