Exemplo n.º 1
0
        private void SetRFSB1Button_Click(object sender, EventArgs e)
        {
            int   Frequency = (int)SB1RFFreq.Value;
            float Amplitude = (float)SB1RFAmp.Value;

            GPIB.InitDevice(20);
            GPIB.SetAmplitude(Amplitude);
            GPIB.SetFrequency(Frequency);
            GPIB.CloseDevice();
        }
Exemplo n.º 2
0
        // Method to respond to user clicking start button
        private void StartButton_Click(object sender, EventArgs e)
        {
            // If we are restarting the experiment after it being paused, just reset the PauseExperiment flag
            if (PauseExperiment == true)
            {
                PauseExperiment       = false;  // Set flag
                PauseButton.Enabled   = true;   // Re-enable pause button
                StartButton.Enabled   = false;  // Disable start button
                OpenUSBButton.Enabled = false;  // Disable open USB button
            }
            else
            {                 // Otherwise, start experiment
                this.Reset(); // Reset first

                if (FPGA.bUSBPortIsOpen == false)
                {
                    WriteMessage("Can't Send Start Signal to FPGA: USB port is not open", true);
                    return;
                }
                else
                {
                    //Grab all scan and trap parameters from form:
                    specType   = specTypeBox.SelectedItem.ToString();
                    specDir    = specDirBox.SelectedItem.ToString();
                    trapV      = (float)(1000 * trapVBox.Value); //Trap voltage stored in millivolts
                    axFreq     = (int)(1000 * axFreqBox.Value);
                    modcycFreq = (int)(1000 * modcycFreqBox.Value);
                    magFreq    = (int)(1000 * magFreqBox.Value);
                    startFreq  = (int)(1000000 * startFreqBox.Value);
                    carFreq    = (int)(1000000 * carFreqBox.Value);
                    stepSize   = (int)(1000 * stepSizeBox.Value);
                    sbToScan   = (int)sbToScanBox.Value;
                    sbWidth    = (int)sbWidthBox.Value;
                    rfAmp      = (float)rfAmpBox.Value;

                    // Metadata ordering in array:
                    // 0: Date
                    // 1: Spectrum type
                    // 2: 729 direction
                    // 3: Trap voltage
                    // 4: Axial freq (kHz)
                    // 5: Modified cyc freq (kHz)
                    // 6: Magnetron freq (kHz)
                    // 7: AOM start freq (MHz)
                    // 8: Carrier freq (MHz)
                    // 9: Step size (kHz or ticks)
                    // 10: Sidebands/side
                    // 11: Sideband width (steps)
                    // 12: 729 RF amplitude
                    // 13: Number of repeats
                    // 14: Number interleaved
                    // 15: Which sideband
                    // 16: Starting pulse length (fixed)
                    // 17: Number of steps (fixed)
                    // 18 + i: spectrum i name



                    // Create new dialog to get data from user before starting the experiment
                    StartExperimentDialog myExperimentDialog = new StartExperimentDialog();
                    myExperimentDialog.ShowDialog();
                    if (myExperimentDialog.DialogResult != DialogResult.Cancel)
                    {
                        // Create & fill in metadata
                        string[] metadata = new string[23];
                        metadata[0] = DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm:ss");
                        // This is all from the CoreForm
                        metadata[1]  = specType;
                        metadata[2]  = specDir;
                        metadata[3]  = this.trapVBox.Value.ToString();
                        metadata[4]  = this.axFreqBox.Value.ToString();
                        metadata[5]  = this.modcycFreqBox.Value.ToString();
                        metadata[6]  = this.magFreqBox.Value.ToString();
                        metadata[7]  = this.startFreqBox.Value.ToString();
                        metadata[8]  = this.carFreqBox.Value.ToString();
                        metadata[9]  = this.stepSizeBox.Value.ToString();
                        metadata[10] = this.sbToScanBox.Value.ToString();
                        metadata[11] = this.sbWidthBox.Value.ToString();
                        metadata[12] = this.rfAmpBox.Value.ToString();
                        // Fill in remaining metadata from form
                        metadata[13] = myExperimentDialog.NumberOfRepeats.Value.ToString();
                        metadata[14] = myExperimentDialog.NumberOfSpectra.Value.ToString();
                        metadata[15] = "N/A";
                        metadata[16] = "N/A";   // For fixed spectra only
                        metadata[17] = "N/A";   // For fixed spectra only

                        int numberOfSpectra = (int)myExperimentDialog.NumberOfSpectra.Value;
                        for (int i = 0; i < numberOfSpectra; i++)
                        {
                            metadata[i + 18] = myExperimentDialog.SpectrumNames[i].Text;
                        }

                        metadata[18 + numberOfSpectra] = myExperimentDialog.NotesBox.Text;

                        // Retrieve the folder path selected by the user
                        string FolderPath = myExperimentDialog.getFilePath();
                        // Make sure the
                        if (FolderPath != null)
                        {
                            TextWriter[] myFile;        // Declare array of files

                            // If "Continuous" experiment type has been selected
                            if (specType == "Continuous")
                            {
                                //Turn on frequency generator
                                bIsFreqGenEnabled = true;

                                //Start frequency is the value taken directly from the form, no windowing
                                startFreqArray    = new int[1];
                                startFreqArray[0] = startFreq;

                                // Create a single file and put all readings in there
                                myFileName = new string[1];
                                myFile     = new TextWriter[1];

                                // Create empty RabiSelector object to pass to writeMetadataToFile (not used)
                                RabiSelector myRabiSelector = new RabiSelector();

                                // Create the file with appropriate name & write metadata to it
                                writeMetadataToFile(ref myExperimentDialog, ref myRabiSelector, ref FolderPath, ref myFile, 1);
                            }
                            else if (specType == "Windowed")
                            {
                                //Turn on frequency generator
                                bIsFreqGenEnabled = true;

                                //Calculate frequency offset of sideband start frequencies from sideband centres
                                int offsetFreq = (int)stepSize * sbWidth / 2;
                                //Determine window spacing from trap frequencys and the type of spectrum selected

                                int windowSpace = 0;
                                if (specDir == "Axial")
                                {
                                    windowSpace = (int)(axFreq / 2);
                                }
                                else if (specDir == "Radial")
                                {
                                    windowSpace = (int)(modcycFreq / 2);
                                }

                                //Array of start frequencies for each sideband (from furthest red to furthest blue)
                                startFreqArray = new int[sbToScan * 2 + 1];
                                for (int sb = 0; sb < (sbToScan * 2 + 1); sb++)
                                {
                                    startFreqArray[sb] = carFreq - offsetFreq - (windowSpace * (sbToScan - sb));
                                }

                                // We want a file for each sideband with appropriate naming
                                // Calculate how many files we will need - one for each R/B sideband plus one for carrier
                                int numberOfFiles = (int)(sbToScan * 2 + 1);
                                // Create array of filenames & array of files
                                myFileName = new string[numberOfFiles];
                                myFile     = new TextWriter[numberOfFiles];

                                // Create empty RabiSelector object to pass to writeMetadataToFile (not used)
                                RabiSelector myRabiSelector = new RabiSelector();

                                // Generate filenames and actually create files
                                writeMetadataToFile(ref myExperimentDialog, ref myRabiSelector, ref FolderPath, ref myFile, numberOfFiles);
                            }
                            else if (specType == "Fixed")
                            {
                                // Maybe put a box for user to input which pulses are varied in length

                                //Start frequency is the value taken directly from the form, no windowing
                                startFreqArray    = new int[1];
                                startFreqArray[0] = startFreq;

                                // Show form for user to enter details about fixed frequency sequence
                                // (need starting pulse length & step size)
                                RabiSelector myRabiSelector = new RabiSelector();
                                myRabiSelector.generateSequenceButton.Enabled = false;
                                myRabiSelector.pulseSelectBox.Enabled         = false;
                                myRabiSelector.repeatsSelect.Enabled          = false;
                                myRabiSelector.ShowDialog();

                                // Get starting pulse length & step size from user form
                                fixed_startLength = (int)myRabiSelector.startLengthSelect.Value;
                                fixed_stepSize    = (int)myRabiSelector.stepSizeSelect.Value;
                                // Change step size in metadata
                                metadata[9]  = fixed_stepSize.ToString();
                                metadata[16] = fixed_startLength.ToString();
                                metadata[17] = myRabiSelector.stepsSelect.Value.ToString();

                                // Create a single file and put all readings in there
                                myFileName = new string[1];
                                myFile     = new TextWriter[1];

                                writeMetadataToFile(ref myExperimentDialog, ref myRabiSelector, ref FolderPath, ref myFile, 1);

                                bIsFreqGenEnabled = false;
                            }

                            // If myViewer is not open
                            if (IsViewerOpen)
                            {
                                myViewer.Close();
                                IsViewerOpen = false;
                            }
                            // Create new instance of viewer
                            myViewer = new Spectroscopy_Viewer.SpectroscopyViewerForm(ref metadata);
                            // Set up event handler to deal with viewer closing - must be done after it is constructed
                            myViewer.FormClosing += new FormClosingEventHandler(myViewer_FormClosing);
                            // Set up event handler to deal with event raised when pause button on viewer is clicked
                            // This should trigger the pause button in the main window
                            myViewer.PauseEvent += new SpectroscopyViewerForm.PauseEventHandler(PauseButton_Click);
                            // Show viewer
                            myViewer.Show();
                            // Set boolean  to indicate that viewer is open
                            IsViewerOpen = true;
                        }
                        else
                        {
                            MessageBox.Show("Error selecting folder. Please try again.");
                        }

                        // Code required to start the experiment running:
                        bShouldQuitThread = false;

                        GPIB.InitDevice(19);
                        GPIB.SetAmplitude(rfAmp);
                        GPIB.SetFrequency(startFreq);

                        SendSetupFinish();

                        // Start experiment
                        StartReadingData();
                    }
                }
            }
        }