コード例 #1
0
 /// <summary>
 /// 开始运行
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnStart_Click(object sender, EventArgs e)
 {
     try
     {
         btnStart.Enabled = false;
         btnStop.Enabled  = true;
         port             = new SerialPort();
         port.PortName    = XmlTool.Read("Root/ComSensor");
         port.BaudRate    = Convert.ToInt32(XmlTool.Read("Root/BateRate"));
         port.Open();
         this.port.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
     }
     catch (Exception ex)
     {
         btnStart.Enabled = true;
         btnStop.Enabled  = false;
         MessageBox.Show(ex.Message);
     }
 }