Author Topic: [SOLVED] Managed library (C#) to talk to DigiUSB?  (Read 10814 times)

SmeeAgain

  • Newbie
  • *
  • Posts: 10
[SOLVED] Managed library (C#) to talk to DigiUSB?
« on: January 18, 2013, 10:49:29 am »
[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
« Last Edit: January 21, 2013, 10:15:43 am by SmeeAgain »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
[SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #1 on: January 18, 2013, 01:18:54 pm »
S-
A good start would be to take a look at libusb examples for c#

SmeeAgain

  • Newbie
  • *
  • Posts: 10
[SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #2 on: January 19, 2013, 11:31:02 pm »
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
« Last Edit: January 20, 2013, 07:04:01 pm by SmeeAgain »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
[SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #3 on: January 20, 2013, 01:19:26 am »
Awesome - thanks for the wonderful contribution!

SmeeAgain

  • Newbie
  • *
  • Posts: 10
[SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #4 on: January 20, 2013, 07:02:58 pm »
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

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Re: [SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #5 on: October 18, 2013, 08:27:33 pm »
Take a look at  Examples->DigiUSB->
You need to use the DigiUSB library (which is what implements HID on the Digispark), not serial.

ngoline

  • Newbie
  • *
  • Posts: 3
Re: [SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #6 on: October 18, 2013, 08:54:22 pm »
Thanks so much for this!!

nGoline

skuffle

  • Newbie
  • *
  • Posts: 5
Re: [SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #7 on: February 24, 2015, 09:02:16 am »
Thank you for all your work on this - I've been able to use it to write a Windows desktop app to control a relay via the Digispark :)

PWBarrett

  • Newbie
  • *
  • Posts: 1
Re: [SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #8 on: June 15, 2015, 07:15:49 pm »
Is SourcePod.com gone?  Even the homepage gives an Access Denied error.
Can anyone re-post this?
-- thanks

dougal

  • Sr. Member
  • ****
  • Posts: 289
Re: [SOLVED] Managed library (C#) to talk to DigiUSB?
« Reply #9 on: June 16, 2015, 08:23:36 am »
Through some creative Googling, I think I might have found a copy of that code:

stlk/DigiSparkDotNet