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