예제 #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");
            }
        }