\O/ It’s working!!
So - I started some debugging on the example.
There are actually two problems. Let’s take the “IndexedColors” Demo as an example. First of all, the SetMode call actually gets called before the device is opened, therefore it fails silently. (An Exception would be nice. ). So, when I first ran the info parameter in your debug application, it showed the device being still in mode “0”, which explained why I didn’t see anything on the matrix. It was in the wrong mode all the time.
However, that’s only half of it. On the other hand, the “SetMode” call itself throws an exception, which is thrown by HidSharp:
(I’ll try to translate the Exception - one of Microsofts biggest mistakes: Localized exceptions and stacktraces… head → wall)
Original:
Ausnahmefehler: System.IO.IOException: SetFeature failed. ---> System.ComponentModel.Win32Exception: Der Vorgang wurde erfolgreich beendet
--- Ende der internen Ausnahmestapelüberwachung ---
bei HidSharp.Platform.Windows.WinHidStream.SetFeature(Byte[] buffer, Int32 offset, Int32 count)
bei HidSharp.HidStream.SetFeature(Byte[] buffer)
bei BlinkStickDotNet.BlinkStick.SetMode(Byte mode)
bei BlinkStick.CLI.MainClass.Main(String[] args)
In English:
Exception: System.IO.IOException: SetFeature failed. ---> System.ComponentModel.Win32Exception: The operation completed successfully.
--- End of internal Stacktrace ---
at HidSharp.Platform.Windows.WinHidStream.SetFeature(Byte[] buffer, Int32 offset, Int32 count)
at HidSharp.HidStream.SetFeature(Byte[] buffer)
at BlinkStickDotNet.BlinkStick.SetMode(Byte mode)
at BlinkStick.CLI.MainClass.Main(String[] args)
Now, digging into the code of HidSharp, the method HidD_SetFeature is implemented as it should by the msdn, returning a boolean. And obviously, the method returns false, although it sets the mode correctly on the device (it does that.) - that’s a bit weird. However, I’ve modified the SetMode-Routine, so that it actually ignores Win32Exception with a NativeErrorCode being 0 (which means there hasn’t been a Win32 Error at all).
public void SetMode(byte mode)
{
if (connectedToDriver)
{
try
{
stream.SetFeature(new byte[2] { 4, mode });
}
catch (IOException exception)
{
Win32Exception win32Exception = exception.InnerException as Win32Exception;
if (win32Exception != null && win32Exception.NativeErrorCode == 0) return;
throw;
}
}
}
You might want to have a look at that, though, because I don’t quite understand why it returns false, although everything is fine. Hm.
I should have found that by myself, but I didn’t look at the code - I doubted my soldering skills more.^^
Thank you for your fast reply and your help.
//Edit: Wrong code… sigh