The Digispark > Digispark Projects

[SOLVED] Managed library (C#) to talk to DigiUSB?

(1/2) > >>

SmeeAgain:
[EDIT] Code is linked in my next comment.

Hi,

I want to write a C# program to control my RGB LED. Is there a library or sample code for how to communicate with the digispark over usb from managed code? I understand what to do on the digispark side, and I understand how it would work from Python (although I haven't tested that yet).

If nobody has tried this yet I guess I'll start with Python and then maybe see if I can port it to managed code, but if you have got this working already please let me know!

Thanks,
T

digistump:
S-
A good start would be to take a look at libusb examples for c#

SmeeAgain:
Thanks for the hint!

It took some tinkering, but I\'ve  managed to port usbdevice.py to C# using LibUsbDotNet.

I can send values to the DigiBlink program and wrote a simple program that reads values from the usb port (e.g. from the echo sketch) and prints the data to the console.

This is the first time I\'ve used LibUsbDotNet or dealt with the USB port, so no guarantee that this is working for everyone. I\'ve only tested it on my machine (Win8, x64, VS2012, rev2 DigiSpark).

The code is shared on sourcepod. Code is provided \"as-is,\" without any express or implied warranty.

Port of usbdevice.py (basic read and write methods): http://www.sourcepod.com/vbfuim05-13526
[EDIT] Updated version with device notification here
http://www.sourcepod.com/jhjaxb65-13548

Some quick and dirty sample code (the read app is the second part that is currently commented out):
http://www.sourcepod.com/glcjqe34-13527

If you use this code (successfully or otherwise) let me know how you\'re getting on!
T

digistump:
Awesome - thanks for the wonderful contribution!

SmeeAgain:
No problem, I hope this will help some people and spawn more awesome projects.

I\'ve updated the code to include device change notification. Every time the DigiSpark is connected or disconnected it will raise an event that you can react to e.g. in your WinForms app. The code itself got a little smarter too, it\'ll only try to interact with the DigiSpark when it\'s actually present.
I have a little GUI that allows to change the colors on the DigiBlink and is aware of whether the DigiSpark is plugged in or not. If I have some time this week I\'ll try to clean that up and make it available as well.

For now here the updated library:
http://www.sourcepod.com/jhjaxb65-13548

T

Navigation

[0] Message Index

[#] Next page

Go to full version