Crash in .NET with new Nano

I’m getting an inconsistent crash inside HidSharp.

The method in HidSharp is below:

public unsafe override void GetFeature(byte[] buffer, int offset, int count)
{
   Throw.If.OutOfRange(buffer, offset, count);
	      
      HandleAcquireIfOpenOrFail();
      try
      {
		 fixed (byte* ptr = buffer)
		 {
			if (!NativeMethods.HidD_GetFeature(_handle, ptr + offset, count))
			{ throw new IOException("GetFeature failed.", new Win32Exception()); }  <------------ exception here
		 }
      }
      finally
      {
         HandleRelease();
      }
} 

Here is my call stack at the time:

HidSharp.dll!HidSharp.Platform.Windows.WinHidStream.GetFeature(byte[] buffer, int offset, int count) Line 78
BlinkStickDotNet.dll!BlinkStickDotNet.BlinkStick.GetColors(out byte[] colorData) Line 790            
BlinkStickDotNet.dll!BlinkStickDotNet.BlinkStick.GetColor(byte index, out byte r, out byte g, out byte b) Line 824
BlinkStickDotNet.dll!BlinkStickDotNet.BlinkStick.Morph(byte channel, byte index, byte r, byte g, byte b, int duration, int steps) Line 1016     
BlinkStickDotNet.dll!BlinkStickDotNet.BlinkStick.Pulse(byte channel, byte index, byte r, byte g, byte b, int repeats, int duration, int steps) Line 1118C#
BlinkStickDotNet.dll!BlinkStickDotNet.BlinkStick.Pulse(byte channel, byte index, BlinkStickDotNet.RgbColor color, int repeats, int duration, int steps) Line 1137      
BlinkStickDotNet.dll!BlinkStickDotNet.BlinkStick.Pulse(byte channel, byte index, string color, int repeats, int duration, int steps) Line 1150     
CheckForMeetingReminders.exe!CheckForMeetingReminders.Program.AnimationForEmails() Line 270

And here is the code that I called that caused the issue:

Line 270: device.Pulse(0,1,"green");

Am I doing something wrong? Yes I’ve opened the device, and this is basically based on code in the .NET Examples.

Yes this is a Nano, and I was trying to access the second LED. If I use

device.Pulse("green");

I haven’t seen the issue.

Hey Aric,

please give us a few more lines of your code.
An error regarding “GetFeature” is often a missing delay between the commands.

For example do a

Thread.Sleep(20); 

before your pulse

That would explain it. I was trying to blink the front LED just before my Pulse call to the back LED. I will make sure to add a delay between the calls. Thanks.

BTW is that documented somewhere? I kind of feel like I’m missing some info that would avoid these newby questions.

Thanks!

Well, it is not really documented, so it isn´t your fault. In some wiki examples there is a thread.sleep and here in the forums there are often posts regarding this.

oh my, I’m having same issues with Blink Square.

device.SetMode (2);
Thread.Sleep (200);

  			int numberOfLeds = 8;
                for (byte t = 0; t < 10; t++)
                {
                    for (byte i = 0; i < numberOfLeds; i++)
                    {
                        device.Pulse(0,i,"#0000ff",1, 100,10);
                       
                        Console.WriteLine("Loop :" +t);
                        Thread.Sleep(100);
                        
                    }
                }

Please take a look at this post. I think there is currently no solution for your issue (not in the blinkstick library):

Wait, its been a year since this was posted and its still broken, i only just purchased this.

Now I find it has a known fault, Where does the problem lie? is it inside the micro-controller firmware?

@arvydas any update, its been a year since.

It’s a limitation of the library - it can’t animate multiple LEDs at the same time. I have a solution implemented with BlinkStick Client application and will add this feature to library this week. Will also update all other API implementations.

But the pulse command is one LED at a time isn’t it? once full pulse completes before next commences.

But i look forwards to your update.

Did you manage to get those libraries updated?