// ********** Initialize the spectrometer ********** private void InitializeButton_Click(object sender, EventArgs e) { // Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 7 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); //Close any previously used spectrometer (in case user clicks on the button more than once) if (spectrometer != null) { spectrometer.Close(); } // Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 8 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); //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(); } //Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 9 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); //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]; //Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 10 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); try { InitStatusLabel.Text = "Initializing spectrometer ..."; statusStrip1.Update(); spectrometer.Open(); //Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 11 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); //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; } peaksTable.RowCount = numberOfPeaks; // Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 12 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); for (int i = 0; i < numberOfPeaks; i++) { peaks.Add(new COG(0, 0, 0, 0, 0)); peaksTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 26F)); } // (spectrometer as CalibratedSpectrometer).UseExternalTrigger = true; for (int i = 0; i < numberOfPeaks; i++) { //Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 13 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); wLeft.Add(new NumericUpDown()); wRight.Add(new NumericUpDown()); threshList.Add(new NumericUpDown()); labelPList.Add(new System.Windows.Forms.Label()); labelCOG.Add(new System.Windows.Forms.Label()); SetWaves(wLeft[i]); wLeft[i].Name = $"waveLengthLeft {(i + 1).ToString()}"; peaksTable.Controls.Add(wLeft[i], 2, i); SetWaves(wRight[i]); wRight[i].Name = $"waveLengthRight {(i + 1).ToString()}"; peaksTable.Controls.Add(wRight[i], 3, i); SetThres(threshList[i]); threshList[i].Name = $"threshold {(i + 1).ToString()}"; peaksTable.Controls.Add(threshList[i], 4, i); SetLabelP(labelPList[i]); labelPList[i].Text = $"Peak {(i+1).ToString()}"; peaksTable.Controls.Add(labelPList[i], 1, i); //PeakTrackBox.Controls.Add(waveLengths[i]); } for (int i = 0; i < peaks.Count; i++) { InitPeak(peaks[i], spectrometer.WavelengthCoefficients, wLeft[i], wRight[i], threshList[i]); Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 16 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); } // Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 15 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); //peak1.SetWaveCof(spectrometer.WavelengthCoefficients); //peak1.SetWaveLeft((float)numericUpDown1.Value); // peak1.SetWaveRight((float)numericUpDown2.Value); //peak1.SetThresholde((float)numericUpDowntr1.Value * (float)0.01); //peak1.waveLeft = (float)numericUpDown1.Value; //peak1.waveRight = (float)numericUpDown2.Value; //peak1.waveLeft = (float)waveLengths[0].Value; //peak1.waveRight = (float)waveLengths[1].Value; //peak1.thresholde = (float)numericUpDowntr1.Value * (float)0.01; // peak2.SetWaveCof(spectrometer.WavelengthCoefficients); //the overwriting happens here. //peak2.SetWaveLeft((float)numericUpDown3.Value); // peak2.SetWaveRight((float)numericUpDown4.Value); //peak2.SetThresholde((float)numericUpDowntr2.Value * (float)0.01); // peak2.waveLeft = (float)waveLengths[2].Value; // peak2.waveRight = (float)waveLengths[3].Value; // peak2.thresholde = (float)numericUpDowntr2.Value * (float)0.01; Debug.WriteLine($"¤¤¤¤¤¤¤¤¤¤¤¤¤ DEBUG 17 ¤¤¤¤¤¤¤¤¤¤¤¤¤"); 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); } }
// ********** 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); } }