.NET BlinkStick on RPi

I developed application that uses BlinkStick .NET and works fine on Win7.
I installed Mono on Raspberry Pi 3 and without LED strip connected can run it fine.
However when I connect BlinkStrip it throws exception when it gets to device.SetColors:

                try
                {
                    device = BlinkStick.FindFirst();
                    if (device != null)
                    {
                        if (device.OpenDevice())
                        {
                            // set color initially to green
                            byte[] data = SetColorArray(0, 0, 255, false); // brg
                            
                           device.SetColors(0, data);
                        }
                    }
                    
                    mCurrentState = State.Green;

                    picBox.Image = semaphorImageList.Images["green.png"];
                    timerLabel.Text = greenCountMax.ToString();

                    // start timer
                    colorTimer.Tick += colorTimer_Tick;
                    colorTimer.Start();
                }
                catch (Exception ex)
                {
                    Log.Verbose(ex);

                    MessageBox.Show("Unable to find Blinkstick device. Verify that the device is connected.");

                    mCurrentState = State.None;

                    if (device != null)
                    {
                        device.CloseDevice();
                        device.Dispose();
                    }

                    colorTimer.Stop();
                    colorTimer.Tick -= colorTimer_Tick;
                    timerLabel.Text = "";
                }

Another strange part is the when exception is caught it supposed to display message box but it does not…
After the exception the app frame can be moved but content of the window is not updated as it is gone…

Here is the stack:

{MainForm.Start: entered
{MainForm.SetColorArray: entered
}MainForm.SetColorArray: exiting
Exception type: System.NullReferenceException
Message: Object reference not set to an instance of an object
Source: HidSharp
StackTrace:
at HidSharp.LibusbHidStream.SetFeature (System.Byte[] buffer, System.Int32 offset, System.Int32 count) <0x72703d30 + 0x001b0> in :0
at HidSharp.HidStream.SetFeature (System.Byte[] buffer) <0x72703ca0 + 0x0004f> in :0
at (wrapper remoting-invoke-with-check) HidSharp.HidStream:SetFeature (byte[])
at BlinkStickDotNet.BlinkStick.SetFeature (System.Byte[] buffer) <0x72703930 + 0x0005b> in :0
at BlinkStickDotNet.BlinkStick.SetColors (System.Byte channel, System.Byte[] colorData) <0x727035d8 + 0x001d7> in :0
at TrafficBlink.MainForm.Start () <0x72d51918 + 0x000fb> in :0

Somebody told me that the USB driver is not installed or not installed correctly and pointed me to this link:
https://www.blinkstick.com/help/raspberry-pi-integration

But my build is done with BlinkStick .NET so I don’t see how Python version is relevant here…

Any feedback is greatly appreciated…

P.S. I installed Python as specified in the above link but the results are the same…

Hey Leon,

could you please try a simple SetColor (for example device.SetColor(255,0,0); ) and see what happens?
I wonder what SetColorArray is. Is it part of the BlinkStick API?

@leon Did a very quick test to see if the library works fine on Linux and tested it on the latest version of Linux Mint. My code seems to work fine. Can you replace the lines:

    // set color initially to green
    byte[] data = SetColorArray(0, 0, 255, false); // brg
                                
    device.SetColors(0, data);

to this bit of code:

                    byte[] data = new byte[3*8] 
                        {0, 0, 255,    //GRB for led0
                         0, 128, 0,    //GRB for led1
                         128, 0, 0,    //...
                         128, 255, 0,
                         0, 255, 128,
                         128, 0, 128,
                         0, 128, 255,
                         128, 0, 0    //GRB for led7
                        };


                    device.SetColors (0, data);

I’m not sure what your functions SetColorArray does, but the code bit above correctly sets the colors on BlinkStick.

I found the solution late last night - there was a problem with the USB driver.
I ran commands detailed in the link below and that solved the problem.

Oh, I think you just needed the udev rule :smile: Glad to hear you got it sorted!