private void startComPort() { ComPort = new PInvokeSerialPort.SerialPort(COM, baudrate); ComPort.AutoReopen = true; ComPort.DataReceived += ReciveByte; ComPort.Open(); }
protected override void Dispose(bool disposing) { if (ComPort != null) { ComPort.Close(); ComPort = null; } }
public void ForceReconnect() { ComPort.Close(); ComPort.Dispose(); ComPort = null; Thread.Sleep(1000); startComPort(); }
static void Main(string[] args) { var serialPort = new SerialPort("com1", 14400); serialPort.DataReceived += x => Console.Write((char)x); serialPort.Open(); while (true) { serialPort.Write(Console.ReadKey().KeyChar); } }