示例#1
0
        //点击开始或停止采集按钮执行的操作
        private void btn_Engage_Click(object sender, EventArgs e)
        {
            //判断串口已打开并且为开始采集状态
            if (btn_Engage.Text == "开始采集" && ObjPort.IsOpen)
            {
                //开启定时器
                TimerCollect.Interval = Convert.ToInt16(txt_Cycle.Text) * 1000;
                TimerCollect.Start();
                btn_Engage.Text = "停止采集";
            }

            else if (!ObjPort.IsOpen)
            {
                MessageBox.Show("串口未连接,请连接串口", "提示:");
            }

            else if (btn_Engage.Text == "停止采集")
            {
                //关闭定时器
                TimerCollect.Stop();
                btn_Engage.Text = "开始采集";
            }
        }
示例#2
0
 //点击连接或者断开串口按钮的操作
 private void btn_Switch_Click(object sender, EventArgs e)
 {
     if (btn_Switch.Text == "连接")
     {
         //判断串口是否为断开状态
         if (Start(false, cmb_PortName.SelectedItem.ToString(), cmb_BaudRate.SelectedItem.ToString()) == true)
         {
             btn_Switch.Text = "断开";
             MessageBox.Show("连接成功", "提示:");
         }
     }
     else if (btn_Switch.Text == "断开")
     {
         //判断串口是否为开启状态
         if (Start(true, cmb_PortName.SelectedItem.ToString(), cmb_BaudRate.SelectedItem.ToString()) == true)
         {
             btn_Switch.Text = "连接";
             TimerCollect.Stop();
             btn_Engage.Text = "开始采集";
             MessageBox.Show("断开成功", "提示:");
         }
     }
 }