Exemplo n.º 1
0
        public SpectForm(ref OmniDriver.NETWrapper wrapper, bool loadDefaults)
        {
            wrapper.openAllSpectrometers();
            InitializeComponent();

            for (int i = 0; i < wrapper.getNumberOfSpectrometersFound(); ++i)
            {
                indexComboBox.Items.Add(wrapper.getSerialNumber(i) + "(Index: " + i + ")");
            }
            String[] ports = SerialPort.GetPortNames();
            valveComboBox.Items.AddRange(ports);
            FCComboBox.Items.AddRange(ports);

            //wczytaj default
            if (loadDefaults)
            {
                try
                {
                    XDocument doc     = XDocument.Load(path + "\\default.xml");
                    var       options = doc.Root;
                    indexComboBox.SelectedIndex = Int32.Parse(options.Element("Index").Value);
                    IntegrTTextBox.Text         = (string)options.Element("Integration_Time").Value;
                    AverageTTextBox.Text        = (string)options.Element("Average").Value;
                    BoxcarWidthTextBox.Text     = (string)options.Element("Boxcar_Width").Value;
                    valveComboBox.SelectedItem  = (string)options.Element("Valve_port_name").Value;
                    FCComboBox.SelectedItem     = (string)options.Element("FC_port_name").Value;
                }
                catch (Exception e)
                {
                    MessageBox.Show("Couldn't load default options.", "Default options error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        private void initializeSpectrometers()
        {
            // assume initialization will fail
            btnScan.Enabled = false;
            checkBoxEnableIrradiance.Enabled = false;

            // support re-entry
            if (numberOfSpectrometers > 0)
            {
                wrapper.closeAllSpectrometers();
            }

            // initialize everything
            specIndices       = null;
            pixels            = null;
            wavelengths       = null;
            newestSpectrum    = null;
            graphableSpectrum = null;
            serialNumbers     = null;
            modelNames        = null;
            backgroundWorkers = null;
            graphSeries       = null;
            chartSpectrum.Series.Clear();
            saveCounts      = null;
            scanning        = null;
            gpios           = null;
            bufferedSpectra = null;

            wrapper.openAllSpectrometers();
            numberOfSpectrometers = wrapper.getNumberOfSpectrometersFound();
            logger.display("Found {0} spectrometers", numberOfSpectrometers);
            if (numberOfSpectrometers < 1)
            {
                logger.display("ERROR: no spectrometers found");
                return;
            }

            specIndices              = new List <int>();
            scanning                 = new HashSet <int>();
            pixels                   = new Dictionary <int, int>();
            lampEnabled              = new Dictionary <int, bool>();
            saveCounts               = new Dictionary <int, int>();
            collectionAreas          = new Dictionary <int, double>();
            wavelengths              = new Dictionary <int, double[]>();
            newestSpectrum           = new Dictionary <int, double[]>();
            graphableSpectrum        = new Dictionary <int, double[]>();
            serialNumbers            = new Dictionary <int, string>();
            modelNames               = new Dictionary <int, string>();
            graphSeries              = new Dictionary <int, Series>();
            backgroundWorkers        = new Dictionary <int, BackgroundWorker>();
            integrationTimesMillisec = new Dictionary <int, int>();
            lastScanTimes            = new Dictionary <int, DateTime>();
            gpios           = new Dictionary <int, OmniDriver.NETGPIO>();
            bufferedSpectra = new Dictionary <int, List <Tuple <DateTime, double[]> > >();

            for (int specIndex = 0; specIndex < numberOfSpectrometers; specIndex++)
            {
                specIndices.Add(specIndex);

                // initialize metadata for each spectrometer
                integrationTimesMillisec.Add(specIndex, 100);
                serialNumbers.Add(specIndex, wrapper.getSerialNumber(specIndex));
                modelNames.Add(specIndex, wrapper.getName(specIndex));
                pixels.Add(specIndex, wrapper.getNumberOfPixels(specIndex));
                newestSpectrum.Add(specIndex, new double[pixels[specIndex]]);
                graphableSpectrum.Add(specIndex, new double[pixels[specIndex]]);
                backgroundWorkers.Add(specIndex, new BackgroundWorker());
                lampEnabled.Add(specIndex, false);
                wavelengths.Add(specIndex, wrapper.getWavelengths(specIndex));
                bufferedSpectra.Add(specIndex, new List <Tuple <DateTime, double[]> >());
                saveCounts[specIndex] = 0;

                // apply reasonable defaults
                logger.log("setting defaults for spectrometer {0}", specIndex);
                wrapper.setCorrectForElectricalDark(specIndex, 1);
                wrapper.setCorrectForDetectorNonlinearity(specIndex, 1);
                wrapper.setStrobeEnable(specIndex, 0);

                if (wrapper.isFeatureSupportedGPIO(specIndex) != 0)
                {
                    gpios.Add(specIndex, wrapper.getFeatureControllerGPIO(specIndex));

                    // initialize everything to zero (easiest way to match starting checkbox state)
                    OmniDriver.NETBitSet allBits = new OmniDriver.NETBitSet();
                    allBits.set(0);
                    gpios[specIndex].setDirectionAllBits(allBits);
                    gpios[specIndex].setMuxAllBits(allBits);
                    gpios[specIndex].setValueAllBits(allBits);
                }
                else
                {
                    gpios.Add(specIndex, null);
                }

                // create graph series
                logger.log("configuring graph for spectrometer {0}", specIndex);
                graphSeries.Add(specIndex, new Series());
                graphSeries[specIndex].ChartType = SeriesChartType.Line;
                graphSeries[specIndex].Name      = String.Format("{0}: {1} {2}", specIndex, modelNames[specIndex], serialNumbers[specIndex]);
                chartSpectrum.Series.Add(graphSeries[specIndex]);

                // create a background thread for each spectrometer (allows each to run at their own integration time, etc)
                logger.log("configuring BackgroundWorker for spectrometer {0}", specIndex);
                backgroundWorkers[specIndex].WorkerReportsProgress      = true;
                backgroundWorkers[specIndex].WorkerSupportsCancellation = true;
                backgroundWorkers[specIndex].DoWork             += backgroundWorker_DoWork;
                backgroundWorkers[specIndex].ProgressChanged    += backgroundWorker_ProgressChanged;
                backgroundWorkers[specIndex].RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;

                string firmwareVersion = wrapper.getFirmwareVersion(specIndex);

                double startWavelength = -1;
                double lastWavelength  = -1;
                if (wavelengths[specIndex] != null)
                {
                    startWavelength = wavelengths[specIndex][0];
                    lastWavelength  = wavelengths[specIndex][pixels[specIndex] - 1];
                }

                logger.display("Spectrometer at index {0} is a/n {1} with serial {2}, firmware {3} and {4} pixels from {5:0.00} to {6:0.00}nm",
                               specIndex, modelNames[specIndex], serialNumbers[specIndex], firmwareVersion,
                               pixels[specIndex], startWavelength, lastWavelength);
            }

            btnScan.Enabled = true;
            Refresh();
        }