Exemplo n.º 1
0
 /// <summary>
 /// 单例模式,使用getInstance获取实例
 /// </summary>
 /// <param name="portName"></param>
 /// <param name="baudRate"></param>
 private UrgPort(String portName, int baudRate = 115200)
 {
     if (urgPort != null && urgPort.isOpen)
     {
         urgPort.closePort();
     }
     // 初始化串口
     basePort = new SerialPort(portName, baudRate);
     // 绑定读取数据定时器
     timer           = new System.Timers.Timer(100);
     timer.Elapsed  += timer_Elapsed;
     timer.AutoReset = true;
 }
Exemplo n.º 2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (drport == null)
     {
         drport = new Smart_Car.DrPort();
         Console.WriteLine(drport.OpenPort("COM4", "115200"));
     }
     if (!urg.isOpen)
     {
         urg.openPort();
         Console.WriteLine("open");
     }
     else
     {
         urg.closePort();
     }
 }