Ejemplo n.º 1
0
        private void btnNewCalibration_Click(object sender, EventArgs e)
        {
            // Show the raw data series
            (pltTemperature.Model.Series[0] as LineSeries).IsVisible = true;
            pltTemperature.Model.InvalidatePlot(false);

            Calibration  newCalibration = new Calibration();
            DialogResult result         = newCalibration.ShowDialog();

            if (result == DialogResult.OK)
            {
                _calibration = newCalibration;
            }
            DisplayCalibration();

            // Hide the raw data series
            (pltTemperature.Model.Series[0] as LineSeries).IsVisible = false;
            pltTemperature.Model.InvalidatePlot(false);
        }
Ejemplo n.º 2
0
        private void LoadAppConfiguration()
        {
            // Load configuration
            // First get the settings file to load
            _configPath = Properties.Settings.Default.AppConfiguration;
            if (!Path.IsPathRooted(_configPath))
            {
                _configPath = Path.GetFullPath(Path.Combine(BASE_DIR, _configPath));
            }
            // Load settings either saved by user or default ones
            if (File.Exists(_configPath))
            {
                _config = JObject.Parse(File.ReadAllText(_configPath));
            }
            else
            {
                // config file was not found - load default one
                _configPath = Path.GetFullPath(Path.Combine(BASE_DIR, (string)Properties.Settings.Default.Properties["AppSettings"].DefaultValue));
                _config     = JObject.Parse(File.ReadAllText(_configPath));
            }

            // Display current config
            toolStripCurrentConfig.Text = "Current Configuration: " + Path.GetFileName(_configPath);

            // Set dialogs
            ofdLoadConfig.InitialDirectory   = Path.GetDirectoryName(_configPath);
            sfdSaveConfigAs.InitialDirectory = ofdLoadConfig.InitialDirectory;

            saveCurrentConfigWhenClosingToolStripMenuItem.Checked = (bool)_config["save_settings_on_closing"];

            // get information about sensors and select the indicated one
            _selectedSensorIndex = (int)_config["selected_sensor_index"] - 1;
            FindSensors((string)_config["sensors_path"], (JArray)_config["user_added_sensors"], _selectedSensorIndex);

            // get information about lasers and select the indicated one
            _selectedLaserIndex = (int)_config["selected_laser_index"] - 1;
            FindLasers((string)_config["lasers_path"], (JArray)_config["user_added_lasers"], _selectedLaserIndex);

            // calibration
            string calibrationFile = (string)_config["calibration"];

            try
            {
                calibrationFile = Path.GetFullPath(calibrationFile);
                _calibration    = new Calibration(calibrationFile);
                ofdLoadCalibration.InitialDirectory = Path.GetDirectoryName(calibrationFile);
            }
            catch (ArgumentException)
            {
                // file does not exist of path is in the wrong format
                _calibration = new Calibration();
            }
            cbUseCalibration.Checked = (bool)_config["use_calibration"];
            DisplayCalibration();
            cbUseCalibration_CheckedChanged(cbUseCalibration, new EventArgs());

            nudTargetTemp.Minimum           = (decimal)_config["min_target_temperature"];
            nudTargetTemp.Maximum           = (decimal)_config["max_target_temperature"];
            cmbExperimentType.SelectedIndex = (int)_config["experiment_type_index"] - 1;
            cmbStopCondition.SelectedIndex  = (int)_config["selected_stop_condition_index"] - 1;
            _pid = new PID(
                (double)_config["pid"]["proportional"],
                (double)_config["pid"]["integral"],
                (double)_config["pid"]["differential"],
                (double)nudTargetTemp.Maximum, // Max temperature that can be set and achieved
                (double)nudTargetTemp.Minimum, // Min temperature that can be set and achieved
                1.0,                           // PID gives output in the [0, 1] interval of relative laser power
                0);                            // The final laser power to be calculated by the laser part
            nudPropGain.Value = (decimal)_pid.PropGain;
            nudIntGain.Value  = (decimal)_pid.IntGain;
            nudDiffGain.Value = (decimal)_pid.DiffGain;

            // Initialization for Experiment
            // directory to save files of the experiment
            _expBaseDir = Path.GetFullPath((string)_config["experiment_path"]);
            if ((bool)_config["create_experiment_folder_with_current_date"])
            {
                _expDir = Path.Combine(_expBaseDir, DateTime.Now.ToString("yyyy-MM-dd"));
            }
            else
            {
                _expDir = _expBaseDir;
            }
            txtExpDir.Text           = _expDir;
            txtExpDir.SelectionStart = txtExpDir.Text.Length;
            txtExpDir.ScrollToCaret();

            // if header needs to be saved
            cbSaveHeader.Checked = (bool)_config["save_header_data"];

            // if data needs to be saved
            cbSaveData.Checked      = (bool)_config["save_experiment_data"];
            txtExpFileName.Enabled  = cbSaveData.Checked;
            txtExpDir.Enabled       = cbSaveData.Checked;
            btnSelectExpDir.Enabled = cbSaveData.Checked;
            txtDescription.Enabled  = cbSaveData.Checked;
            txtOperator.Enabled     = cbSaveData.Checked;
            cbSaveHeader.Enabled    = cbSaveData.Checked;
            txtExpFileName.Text     = _expFileName;

            // generate file name
            if ((bool)_config["create_experiment_file_with_current_time"])
            {
                _expFileName = "Record_" + DateTime.Now.ToString("hh-mm-ss") + ".txt";
            }
            else
            {
                _expFileName = "";
            }
            txtExpFileName.Text = _expFileName;

            txtOperator.Text = (string)_config["operator"];

            // time and thermal dose
            nudExpTime.Value     = (decimal)_config["experiment_time_min"];
            nudThermalDose.Value = (decimal)_config["experiment_thermal_dose"];

            // get information about experiment and set values
            _discretizationTime    = (int)_config["discretization_ms"];
            _discretizationTimeMin = (double)_discretizationTime / (1000 * 60);
            _expTimer.Interval     = _discretizationTime;
            _expTimer.Tick        += new EventHandler(this.experimentTimer_Tick);
        }