private void InitPeak(COG peakToInit, double[] Wavelengths, NumericUpDown wLeft, NumericUpDown wRight, NumericUpDown thres)
 {
     peakToInit.SetWaveCof(Wavelengths);
     peakToInit.SetWaveLeft((float)wLeft.Value);
     peakToInit.SetWaveRight((float)wRight.Value);
     peakToInit.SetThresholde((float)thres.Value * (float)0.01);
 }
        private void InitSpectrometer()
        {
            //Close any previously used spectrometer (in case user clicks on the button more than once)
            if (spectrometer != null)
            {
                spectrometer.Close();
            }

            //This static method searches for devices and returns a list of driver for the available devices.
            Spectrometer[] devices = Qseries.SearchDevices();
            if (devices.Length == 0)
            {
                devices = RgbSpectrometer.SearchDevices();
            }
            if (devices.Length == 0)
            {
                devices = Qstick.SearchDevices();
            }

            //If no device was found:
            if (devices.Length == 0)
            {
                InitStatusLabel.Text = "No spectrometer found.";
                MessageBox.Show("No spectrometer found.", "Cannot initialize spectrometer",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Otherwise, take the first device and initialize it.
            spectrometer = devices[0];
            try
            {
                InitStatusLabel.Text = "Initializing spectrometer ...";
                statusStrip1.Update();

                spectrometer.Open();

                //Get the wavelength of each pixel (this is not actually used in this sample code)
                double[] wavelengths = spectrometer.GetWavelengths();

                //Initialize values in GUI
                ExpTimeNumericUpDown.Value = (decimal)spectrometer.ExposureTime;
                if (spectrometer is CalibratedSpectrometer)
                {
                    SensitivityCalibrationCheckBox.Checked = (spectrometer as CalibratedSpectrometer).UseSensitivityCalibration;
                    SensitivityCalibrationCheckBox.Enabled = true;
                    //checkBoxEksternTrigger.Checked = (spectrometer as CalibratedSpectrometer).UseExternalTrigger;
                }
                else
                {
                    SensitivityCalibrationCheckBox.Checked = false;
                    SensitivityCalibrationCheckBox.Enabled = false;
                }

                //      (spectrometer as CalibratedSpectrometer).UseExternalTrigger = true;


                peak1.SetWaveCof(spectrometer.WavelengthCoefficients);
                peak1.SetWaveLeft((float)numericUpDown1.Value);
                peak1.SetWaveRight((float)numericUpDown2.Value);
                peak1.SetThresholde((float)numericUpDowntr1.Value * (float)0.01);


                peak2.SetWaveCof(spectrometer.WavelengthCoefficients);  //overwrite doesnt happen here
                peak2.SetWaveLeft((float)numericUpDown3.Value);
                peak2.SetWaveRight((float)numericUpDown4.Value);
                peak2.SetThresholde((float)numericUpDowntr2.Value * (float)0.01);

                Debug.WriteLine($"WAVES PEAK 1 ------------ {numericUpDown1.Value} {numericUpDown2.Value}");
                Debug.WriteLine($"WAVES PEAK 2 ------------ {numericUpDown3.Value} {numericUpDown4.Value}");


                /*
                 * InitStatusLabel.Text = "Found " + spectrometer.DetailedDeviceName;
                 * MessageBox.Show("Device name: " + spectrometer.ModelName + Environment.NewLine
                 + "Manufacturer: " + spectrometer.Manufacturer + Environment.NewLine
                 + "Serial number: " + spectrometer.SerialNo + Environment.NewLine
                 + "Number of pixels: " + spectrometer.PixelCount,
                 +     "Spectrometer found and initialized", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 */
            }
            catch (Exception ex)
            {
                spectrometer         = null;
                InitStatusLabel.Text = "Initialization error.";
                MessageBox.Show(ex.Message, "Cannot initialize spectrometer",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }