Пример #1
0
 private void StartBtn_Click(object sender, EventArgs e)//启停
 {
     if (Global.my_start == 0)
     {
         if (Global.bed_num == 0)
         {
             MessageBox.Show("计数为零,请从新设置张数!");
             return;
         }
         Global.my_start    = 1;
         StartBtn.Text      = "停止";
         StartBtn.BackColor = Color.Red;
         myThread           = new Thread(countThread);
         myThread.Start();
         SerialServer.send_start(0x01);
         workModeGroupBox.Enabled  = false;
         numPanel.Enabled          = false;
         bordLenthGroupBox.Enabled = false;
         colNumGroupBox.Enabled    = false;
         glueNumGroupBox.Enabled   = false;
     }
     else
     {
         Global.my_start = 0;
         StartBtn.Text   = "启动";
         myThread.Abort();//终止线程
         StartBtn.BackColor = Color.Green;
         SerialServer.send_start(0x00);
         workModeGroupBox.Enabled  = true;
         numPanel.Enabled          = true;
         bordLenthGroupBox.Enabled = true;
         colNumGroupBox.Enabled    = true;
         glueNumGroupBox.Enabled   = true;
     }
 }
Пример #2
0
        //private void timer1_Tick(object sender, EventArgs e)//定时器接收消息
        //{
        //    if (receiveMessage != "" && receiveMessage != null)
        //    {
        //        if (receiveMessage == "run over a sponge")//跑完一张,计数减
        //        {
        //            if (Global.bed_num > 0)
        //            {
        //                Global.bed_num -= 1;
        //                SerialServer.send_BedNum((short)(Global.bed_num));
        //            }
        //            if (info_textBox.Lines.Length >= 5) info_textBox.Text = "";
        //            info_textBox.Text += "完成一张棉" + "  " + DateTime.Now + "\r\n";//显示完成时间
        //        }
        //        receiveMessage = "";

        //        bedNumLabel.Text = Global.bed_num.ToString();//显示张数,计数
        //        if (Global.bed_num == 0)
        //        {
        //            StartBtn_Click(null, null);//停止流水线
        //        }
        //    }
        //    else
        //    {
        //        Thread.Sleep(10);
        //    }
        //}
        /// <summary>
        /// 窗口关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Global.my_start == 1)//机器人运行中
            {
                DialogResult result = MessageBox.Show("机器正在运行,确定关闭?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    SerialServer.send_start(0x00);
                    myThread.Abort();
                }
                else
                {
                    e.Cancel = true;
                    return;
                }
            }
            if (SerialServer.R485Port.IsOpen)
            {
                SerialServer.R485Port.Close();                               //关闭串口
            }
        }