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