// ********** Take a spectrum *********

        private void TakeSpectrumButton_Click(object sender, EventArgs e)
        {
            if (spectrometer == null)
            {
                return;
            }
            try
            {
                spectrometer.StartExposure();

                while (spectrometer.Status > SpectrometerStatus.Idle) //this could be SpectrometerStatus.TakingSpectrum or SpectrometerStatus.WaitingForTrigger
                {
                    System.Threading.Thread.Sleep(50);
                    //Taking a spectrum could be aborted with: spectrometer.CancelExposure()
                }

                IntensitiesDrawing();

                labelPeak1.Text = "Peak [nm]: " + peak1.GetCOGinWaveLength();
                label7.Text     = $"Peak [nm]: {peak1.GetCOGinWaveLength()}";
                label8.Text     = $"Temp [°C]: {GetTemperature(a, b, c, peak1)}";
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Cannot take spectrum",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void LabelPlacering(COG peakToLabel, System.Windows.Forms.Label peakLabel, System.Windows.Forms.Label peakLabel2, System.Windows.Forms.Label temp)
 {
     peakLabel.Text  = "Peak [nm]: " + peakToLabel.GetCOGinWaveLength();
     peakLabel2.Text = $"Peak [nm]: {peakToLabel.GetCOGinWaveLength()}";
     temp.Text       = $"Temp [°C]: {GetTemperature(a, b, c, peakToLabel)}";
 }
        private float GetTemperature(float a, float b, float c, COG peakMeasured)
        {
            float temp = a * (peakMeasured.GetCOGinWaveLength() - c) + b;

            return(temp);
        }
        // ********** Initialize the spectrometer **********

        private void InitializeButton_Click(object sender, EventArgs e)
        {
            //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;
                }
                else
                {
                    SensitivityCalibrationCheckBox.Checked = false;
                    SensitivityCalibrationCheckBox.Enabled = false;
                }

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

                // InitPeak(peak1, spectrometer.WavelengthCoefficients, numericUpDown1, numericUpDown2, numericUpDowntr1);
                //InitPeak(peak2, spectrometer.WavelengthCoefficients, numericUpDown3, numericUpDown4, numericUpDowntr2);

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

                Debug.WriteLine($"WAVES PEAK 1 OVERWRITE DEBUG ------- {peak1.GetWaveLeft()} {peak1.GetWaveRight()} {peak1.GetCOGinWaveLength()}");

                /* peak2.SetWaveCof(spectrometer.WavelengthCoefficients);   //the overwriting happens here.
                 * peak2.SetWaveLeft((float)numericUpDown5.Value);
                 * peak2.SetWaveRight((float)numericUpDown6.Value);
                 * peak2.SetThresholde((float)numericUpDowntr2.Value * (float)0.01);
                 */

                Debug.WriteLine($"WAVES PEAK 1 OVERWRITE DEBUG ------- {peak1.GetWaveLeft()} {peak1.GetWaveRight()} {peak1.GetCOGinWaveLength()}");
                Debug.WriteLine($"WAVES PEAK 2 OVERWRITE DEBUG ------- {peak2.GetWaveLeft()} {peak2.GetWaveRight()} {peak2.GetCOGinWaveLength()}");

                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);
            }
        }