/// <summary> /// Close all equipment. /// </summary> public void Close() { _mfcAnalyte?.Close(); _mfcDiluent?.Close(); _datalogger?.Close(); _powerSupply?.Close(); }
/// <summary> /// Connect or disconnect from the instrument. /// </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 action 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 VISA connection..."; // Open the connection. _datalogger.Open(comboBoxResources.Text); // Update the user interface. groupBoxConfiguration.Enabled = true; toolStripStatusLabel1.Text = "VISA connection opened."; } // If the "Closed" radio button has been checked... else if (((RadioButton)sender) == radioButtonClosed) { // Alert the user. toolStripStatusLabel1.Text = "Closing serial port..."; // Close the connection. _datalogger.Close(); // Update user interface. groupBoxConfiguration.Enabled = false; toolStripStatusLabel1.Text = "VISA connection closed."; } } // If an error occurs... catch (Exception ex) { // Alert the user. MessageBox.Show(ex.Message, "Error"); toolStripStatusLabel1.Text = ex.Message; // Undo the user action. radioButtonClosed.Checked = true; } } }