I am having issues with serial communication to an embedded device in Visual Studio C# environment, current solution is to communicate with a putty session with the following configs:
- baud > 9600
- data bits > 8
- stop bits > 1
- parity > none
- flow control > RTS/CTS
Every time the connection is established a menu is displayed on the putty terminal which shows the controller's available commands.
I have tried the following which I have borrowed from the MS example:
public class PortChat
{
static bool _continue;
static SerialPort _serialPort;
public static void Main()
{
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
_serialPort.PortName = "COM4";
_serialPort.BaudRate = 9600;
_serialPort.Parity = Parity.None;
_serialPort.DataBits = 8;
_serialPort.StopBits = StopBits.One;
_serialPort.Handshake = Handshake.RequestToSend;
// Set the read/write timeouts
_serialPort.ReadTimeout = 5000;
_serialPort.WriteTimeout = 5000;
_serialPort.Open();
Thread.Sleep(1000);
}
}
Reading from the port after "Port.Open" results in an exception, see 1st screenshot. Writing to the port also results in an exception, see 2nd screenshot. What am I missing here?
Thank you