Hi. I have a 2-LED BlinkStick Nano and I’m editing the SetColor instruction in the C-sharp code below to turn off LED1 and experiment with different LED2 colors. On the first run, the program worked. However, the program now outputs the following when run in debug mode in Visual Studio 2022:
Device BS044857-3.0 opened successfully
Exception thrown: ‘System.IO.IOException’ in HidSharp.dll
Device col 0: #000000
Device col 1: #FFFFFF
Serial: BS044857-3.0
What might be causing the exception when the program reaches device.SetColor, please? When the exception occurs, the LED color doesn’t change to the desired RGB settings in SetColor. Is the syntax correct?
private void TestNano()
{
Console.WriteLine("Test for BlinkStick Nano.\r\n");
BlinkStick device = BlinkStick.FindFirst();
if (device != null && device.OpenDevice())
{
Console.WriteLine(String.Format("Device {0} opened successfully", device.Serial));
// Use the function SetColor(byte channel, byte index, byte r, byte g, byte b) to set the colour
device.SetColor(0, 0, 0, 0, 0); //Turns off the first LED
// device.SetColor(0, 1, 255, 255, 255); //Sets colour of the second LED white for first debug
device.SetColor(0, 1, 255, 0, 0); //Sets colour red on second debug start
byte cr0;
byte cg0;
byte cb0;
byte cr1;
byte cg1;
byte cb1;
device.GetColor(0, out cr0, out cg0, out cb0);
device.GetColor(1, out cr1, out cg1, out cb1);
Console.WriteLine(String.Format(" Device col 0: #{0:X2}{1:X2}{2:X2}", cr0, cg0, cb0));
Console.WriteLine(String.Format(" Device col 1: #{0:X2}{1:X2}{2:X2}", cr1, cg1, cb1));
Console.WriteLine(" Serial: " + device.Serial);
Thread.Sleep(5000);
device.TurnOff();
}
device.Dispose();
}