im very new to C# and is working on a personal project to send a message from Arduino when a button is pressed to my C# code listening on the serial port and writing the message in the console.
This is so far I've gotten:
using System;
using System.IO.Ports;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static SerialPort _serialPort;
public static void Main()
{
_serialPort = new SerialPort();
_serialPort.PortName = "COM4";//Set your board COM
_serialPort.BaudRate = 9600;
_serialPort.Open();
while (true)
{
string a = _serialPort.ReadExisting();
Console.WriteLine(a);
Thread.Sleep(200);
}
}
}
}
In my console application I would also like to do other things not just wait on incoming data so i guess my option here is to use async?
I tried this: C# Async Serial Port Read But could not get it to work.
Does anyone have any recommendation on where to start, and sorry for this noobish question i have approx 10 hours of c# experiance :).