Esempio n. 1
0
        /// <summary>
        /// Initializes all equipment.
        /// </summary>
        public void Open(bool useDatalogger = false)
        {
            // Remember what equipment to use.
            _useDatalogger = useDatalogger;

            // Configure the mass flow controllers.
            if ((UseGasMixer) && (_mfcAnalyte != null) && (_mfcDiluent != null))
            {
                _mfcAnalyte?.Open(_settings.GasMixer.AnalyteMFC.SerialPort);
                _mfcDiluent?.Open(_settings.GasMixer.DiluentMFC.SerialPort);
            }

            // Configure the datalogger.
            if ((_useDatalogger == true) && (_datalogger != null))
            {
                _datalogger.Bank = _settings.Datalogger.Bank;
                _datalogger.Open();
            }

            // Configure the power supply.
            if (UsePowerSupply && (_powerSupply != null))
            {
                _powerSupply.Channel = 1;
                _powerSupply.Open(_settings.PowerSupply.SerialPort, _settings.PowerSupply.BaudRate);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Open the serial port.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RadioButton_CheckedChanged(object sender, EventArgs e)
        {
            // Do stuff only if the radio button is checked.
            // (Otherwise the actions will run twice.)
            if (((RadioButton)sender).Checked)
            {
                try
                {
                    // If the "Open" radio button has been checked...
                    if (((RadioButton)sender) == radioButtonOpen)
                    {
                        // Alert the user.
                        toolStripStatusLabel1.Text = "Opening serial port...";

                        // Open the Mass Flow Controller (and let it know what serial port to use).
                        _powerSupply.Open(Properties.Settings.Default.Port, 9600);

                        // Update the user interface.
                        comboBoxSerialPort.Enabled  = false;
                        groupBoxOutput.Enabled      = true;
                        groupBoxPowerSupply.Enabled = true;
                        toolStripStatusLabel1.Text  = "Port open.";
                    }
                    else if (((RadioButton)sender) == radioButtonClosed)
                    {
                        // Alert the user.
                        toolStripStatusLabel1.Text = "Closing serial port...";

                        // Close the serial port.
                        _powerSupply.Close();

                        // Update user interface.
                        comboBoxSerialPort.Enabled  = true;
                        groupBoxOutput.Enabled      = false;
                        groupBoxPowerSupply.Enabled = false;
                        toolStripStatusLabel1.Text  = "Port closed.";
                    }
                }
                // If an error occurs...
                catch (Exception ex)
                {
                    // Alert the user.
                    MessageBox.Show(ex.Message, ex.GetType().Name.ToString());

                    // Undo the user action.
                    radioButtonClosed.Checked = true;
                }
            }
        }