Esempio n. 1
0
        private void start_Click(object sender, EventArgs e)
        {
            button7.Enabled  = true;
            button6.Enabled  = true;
            label8.ForeColor = Color.Red;
            label9.ForeColor = Color.White;
            if (th != null)
            {
                if (th.IsAlive)
                {
                    th.Abort();
                    th = null;
                }
            }
            if (_sps != null)
            {
                _sps.StopService();
            }

            if (Ports.SelectedIndex > -1)
            {
                MessageBox.Show(String.Format("你选择了串口 '{0}'", Ports.SelectedItem));
                try
                {
                    _sps = new PeriodicModeDriver(Ports.SelectedItem.ToString());
                    _sps.ReceiveError   += refresh;
                    _sps.ReceiveSuccess += ReceiveRequest;
                    _sps.StartService();
                    if (_sps.IsOnService == true)
                    {
                        label8.ForeColor = Color.LightGreen;
                    }
                    else
                    {
                        label8.ForeColor = Color.Red;
                    }
                }
                catch (Exception)
                {
                }
            }
            else
            {
                MessageBox.Show("Please select a port first");
            }
        }
Esempio n. 2
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (Ports.SelectedIndex > -1)
     {
         MessageBox.Show(String.Format("你选择了串口 '{0}'", Ports.SelectedItem));
         button7.Enabled  = true;
         label9.ForeColor = Color.White;
         string port      = Ports.SelectedItem.ToString();
         int    portindex = Ports.SelectedIndex;
         if (portindex > -1)
         {
             button6.Enabled = false;
             try
             {
                 label8.ForeColor = Color.Blue;
                 th = new Thread(() =>
                 {
                     try
                     {
                         _sps = new RegularModeDriver(port);
                         _sps.ReceiveError   += refresh;
                         _sps.ReceiveSuccess += ReceiveRequest;
                         _sps.StartService();
                     }
                     catch (Exception)
                     {
                     }
                 });
                 th.Start();
             }
             catch (Exception)
             {
             }
         }
         else
         {
             MessageBox.Show("Please select a port first");
         }
     }
     else
     {
         MessageBox.Show("Please select a port first");
     }
 }