示例#1
0
        private void ComPortComboBox_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            ComboBox comboBox = (ComboBox)sender;

            if (comboBox.SelectedIndex == -1)
            {
                return;
            }
            string portName = (string)comboBox.SelectedItem;

            if (portName.Equals(""))
            {
                comboBox.SelectedItem = oldPort;
            }
            else
            {
                if (transmitter != null)
                {
                    transmitter.close();
                }
                try
                {
                    transmitter = new ComPortTransmitter(portName, this);
                    oldPort     = portName;
                }
                catch (Exception ex)
                {
                    comboBox.SelectedIndex = -1;
                    oldPort     = "";
                    transmitter = null;
                    MessageBox.Show("Try choose another port");
                }
            }
        }
示例#2
0
        private void ComPortComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comPortsComboBox = (ComboBox)sender;

            if (transmitter != null)
            {
                transmitter.DataRecived -= Transmitter_DataRecived;
                transmitter.close();
            }
            if (comPortsComboBox.SelectedIndex == -1)
            {
                return;
            }
            try
            {
                transmitter = new ComPortTransmitter(comPortsComboBox.SelectedItem.ToString(), this);
            }catch (Exception ex)
            {
                comPortsComboBox.SelectedIndex = -1;
                MessageBox.Show("Can't open this port. Please try another.", "ERROR!!!!!!");
                return;
            }
            transmitter.DataRecived += Transmitter_DataRecived;
        }