Beispiel #1
0
    private void btnOpenPort_Click(object sender, EventArgs e)
    {
			bool error = false;
            /* The following code is for testing GUI without hardware */
            // Open GUI Window
             GUIWin = new GUIform(this);
             GUIWin.Show();
            // Open Avionics Instrument Window
            //InstrumentWin = new DemoWinow(this);
            //InstrumentWin.Show();

      // If the port is open, close it.
      if (comport.IsOpen) comport.Close();
      else
      {
        // Set the port's settings
        comport.BaudRate = int.Parse(cmbBaudRate.Text);
        comport.DataBits = int.Parse(cmbDataBits.Text);
        comport.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cmbStopBits.Text);
        comport.Parity = (Parity)Enum.Parse(typeof(Parity), cmbParity.Text);
        comport.PortName = cmbPortName.Text;

				try
				{
					// Open the port
					comport.Open();
				}
				catch (UnauthorizedAccessException) { error = true; }
				catch (IOException) { error = true; }
				catch (ArgumentException) { error = true; }

				if (error) MessageBox.Show(this, "Could not open the COM port.  Most likely it is already in use, has been removed, or is unavailable.", "COM Port Unavalible", MessageBoxButtons.OK, MessageBoxIcon.Stop);
				else
				{
					// Show the initial pin states
					UpdatePinState();
					chkDTR.Checked = comport.DtrEnable;
					chkRTS.Checked = comport.RtsEnable;

                    // Open GUI Window
                    GUIWin = new GUIform(this);
                    GUIWin.Show();

                    InstrumentWin = new DemoWinow(this);
                    InstrumentWin.Show();
				}
      }

      // Change the state of the form's controls
      EnableControls();

      // If the port is open, send focus to the send data box
			if (comport.IsOpen)
			{
				txtSendData.Focus();
				if (chkClearOnOpen.Checked) ClearTerminal();
			}
    }
Beispiel #2
0
        private void btnOpenPort_Click(object sender, EventArgs e)
        {
            bool error = false;

            /* The following code is for testing GUI without hardware */
            // Open GUI Window
            GUIWin = new GUIform(this);
            GUIWin.Show();
            // Open Avionics Instrument Window
            //InstrumentWin = new DemoWinow(this);
            //InstrumentWin.Show();

            // If the port is open, close it.
            if (comport.IsOpen)
            {
                comport.Close();
            }
            else
            {
                // Set the port's settings
                comport.BaudRate = int.Parse(cmbBaudRate.Text);
                comport.DataBits = int.Parse(cmbDataBits.Text);
                comport.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cmbStopBits.Text);
                comport.Parity   = (Parity)Enum.Parse(typeof(Parity), cmbParity.Text);
                comport.PortName = cmbPortName.Text;

                try
                {
                    // Open the port
                    comport.Open();
                }
                catch (UnauthorizedAccessException) { error = true; }
                catch (IOException) { error = true; }
                catch (ArgumentException) { error = true; }

                if (error)
                {
                    MessageBox.Show(this, "Could not open the COM port.  Most likely it is already in use, has been removed, or is unavailable.", "COM Port Unavalible", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    // Show the initial pin states
                    UpdatePinState();
                    chkDTR.Checked = comport.DtrEnable;
                    chkRTS.Checked = comport.RtsEnable;

                    // Open GUI Window
                    GUIWin = new GUIform(this);
                    GUIWin.Show();

                    InstrumentWin = new DemoWinow(this);
                    InstrumentWin.Show();
                }
            }

            // Change the state of the form's controls
            EnableControls();

            // If the port is open, send focus to the send data box
            if (comport.IsOpen)
            {
                txtSendData.Focus();
                if (chkClearOnOpen.Checked)
                {
                    ClearTerminal();
                }
            }
        }