I have a .NET application utilizing the BlinkStickDotNet library, and I need to be able to react when the device is disconnected and connected. I found the UsbMonitor class has events for that (BlinkStickConnected and BlinkStickDisconnected, perfect!) but whenever the device is disconnected, a NullPointerException occurs in UsbMonitor.cs (line 100):
because “devices” is null. The same error occurs if I start the application (which includes a UsbMonitor object with event handlers assigned to both events) without the device connected then connect it.
Hi Steve,
This is what I did for handling Insert and remove events.
using HidLibrary;
class clsBlinkStick
{
private HidDevice m_stick;
public event DeviceInsert DInsert;
public delegate void DeviceInsert(string sEqpID, EventArgs e);
public event DeviceRemove DRemove;
public delegate void DeviceRemove(string sEqpID, EventArgs e);
public void Init(HidDevice device)
{
m_stick = device;
m_stick.Removed += new HidDevice.RemovedEventHandler(clsBlinkStick_Remove);
m_stick.Inserted += new HidDevice.InsertedEventHandler(clsBlinkStick_Insert);
}
private void clsBlinkStick_Insert()
{
//Code here
}
private void clsBlinkStick_Remove()
{
//Code here
}
}
Thanks
Rick