Hey guys, I'm new here, just bought a couple of Arduino to play around with.
I'm a C# programmer at heart, so I'd like to learn how to use the Arduino with C# so I can write GUI programs and such for it.
My programming would be pretty simple. I saw a video on youtube a C# program controlling a couple LEDs... when you click on the program, it turns on the LEDs on the Arduino. Sounds simple... but how do I control the Arduino with C#????
The website for the project was no help since it was in Chinese...
Anyhelp would be appreciated... or at least point me in the right direction. I've done quite a bit of searching and hasn't found much.
Serial with C# is pretty easy. No need to hunt around for libraries -- .NET is already there!
using System.IO.Ports;
// to open a port
SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
port.Open();
// example: forever displaying incoming characters
while (true)
if (port.BytesToRead > 0)
{
char c = (char)port.ReadByte();
Console.Write(c);
}
// example: writing a few bytes to the port
byte[] arr = new byte[4];
arr[0] = arr[1] = arr[2] = arr[3] = c;
port.Write(arr, 0, 4); // write the 4 bytes
// example: writing a string
port.Write("Hello, world!");
Just look in the documentation for System.IO.Ports.SerialPort for more goodies.