PInvokeSerialPort main class. Borrowed from http://msdn.microsoft.com/en-us/magazine/cc301786.aspx ;)
Inheritance: IDisposable
Exemple #1
0
 private void startComPort()
 {
     ComPort               = new PInvokeSerialPort.SerialPort(COM, baudrate);
     ComPort.AutoReopen    = true;
     ComPort.DataReceived += ReciveByte;
     ComPort.Open();
 }
Exemple #2
0
 protected override void Dispose(bool disposing)
 {
     if (ComPort != null)
     {
         ComPort.Close();
         ComPort = null;
     }
 }
Exemple #3
0
 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);
     }
 }