Esempio n. 1
0
        // Method to write the metadata to files
        // Gets filenames from private member myFileName
        private void writeMetadataToFile(ref StartExperimentDialog myExperimentDialog, ref RabiSelector myRabiSelector,
                                         ref string FolderPath, ref TextWriter[] myFile, int numberOfFiles)
        {
            // These variables are needed for windowed files only
            // But need to create them anyway else C# will complain...
            //*****************//
            // Store the number sideband we are on
            int sbCurrent = sbToScan;
            // Store whether we are on a red or blue sideband
            char sbRedOrBlue = 'R';
            // Store the current sideband in readable format e.g. 001R
            string sbCurrentString = "";

            //*****************//

            // Go through each file (this will only be run once for continuous & fixed files)
            for (int i = 0; i < numberOfFiles; i++)
            {
                // Generating the current filename:
                //*******************************//
                // This line happens for both continuous & windowed files
                myFileName[i] = FolderPath + @"\" + myExperimentDialog.ExperimentName.Text + "_readings";

                // These bits only need adding to windowed files
                if (specType == "Windowed")
                {
                    myFileName[i] += "_";

                    // Add preceding 0s to keep format of sideband number as XXX
                    if (sbCurrent < 10)
                    {
                        sbCurrentString = "00";
                    }
                    else if (sbCurrent < 100)
                    {
                        sbCurrentString = "0";
                    }
                    else
                    {
                        sbCurrentString = "";
                    }

                    // Add current sideband number to filename
                    sbCurrentString += sbCurrent;
                    // If not on carrier, add R or B
                    if (sbCurrent != 0)
                    {
                        sbCurrentString += sbRedOrBlue;
                    }

                    // Add string to filename
                    myFileName[i] += sbCurrentString;
                }
                myFileName[i] += ".txt";
                //*******************************//

                // Now we get to actually create the file!
                myFile[i] = new StreamWriter(myFileName[i]);

                //*********************************//
                // Write the metadata to the file
                //
                myFile[i].WriteLine("Spectroscopy data file");
                myFile[i].WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
                // Spectrum type
                myFile[i].WriteLine("Spectrum Type:");
                myFile[i].WriteLine(specType);
                // 729 direction
                myFile[i].WriteLine("729 Direction:");
                myFile[i].WriteLine(specDir);
                // Trap voltage
                myFile[i].WriteLine("Trap Voltage (V):");
                myFile[i].WriteLine(this.trapVBox.Value);
                // Axial frequency
                myFile[i].WriteLine("Axial Frequency (kHz):");
                myFile[i].WriteLine(this.axFreqBox.Value);
                // Modified cyc freq
                myFile[i].WriteLine("Modified Cyclotron Frequency (kHz):");
                myFile[i].WriteLine(this.modcycFreqBox.Value);
                // Magnetron freq
                myFile[i].WriteLine("Magnetron Frequency (kHz):");
                myFile[i].WriteLine(this.magFreqBox.Value);
                // AOM start freq
                myFile[i].WriteLine("AOM Start Frequency (MHz):");
                double startFreqMHz = (double)(startFreqArray[i] / 1000000d);       // Calculate in MHz (stored in Hz)
                myFile[i].WriteLine(startFreqMHz);
                // Carrier frequency
                myFile[i].WriteLine("Carrier Frequency (MHz):");
                myFile[i].WriteLine(this.carFreqBox.Value);
                // Step size
                myFile[i].WriteLine("Step Size (kHz or ticks):");
                // For fixed spectra, put in step size of pulse length variation
                if (specType == "Fixed")
                {
                    myFile[i].WriteLine(fixed_stepSize);
                }
                else
                {
                    myFile[i].WriteLine(this.stepSizeBox.Value);    // Othewise, take from core form
                }
                // Sidebands/side
                myFile[i].WriteLine("Sidebands to scan / side:");
                if (specType == "Windowed")
                {
                    myFile[i].WriteLine(sbToScan);
                }
                else
                {
                    myFile[i].WriteLine("N/A");
                }
                // Sideband width
                myFile[i].WriteLine("Sideband Width (steps):");
                if (specType == "Windowed")
                {
                    myFile[i].WriteLine(sbWidth);
                }
                else
                {
                    myFile[i].WriteLine("N/A");
                }
                // 729 RF amplitude
                myFile[i].WriteLine("729 RF Amplitude (dBm):");
                myFile[i].WriteLine(rfAmp);
                // Number of repeats
                myFile[i].WriteLine("Number of repeats per frequency:");
                myFile[i].WriteLine(myExperimentDialog.NumberOfRepeats.Value);
                // Number interleaved
                myFile[i].WriteLine("File contains interleaved spectra:");
                myFile[i].WriteLine(myExperimentDialog.NumberOfSpectra.Value);
                // Sideband number
                myFile[i].WriteLine("This is sideband:");
                if (specType == "Windowed")
                {
                    myFile[i].WriteLine(sbCurrentString);                           // Windowed spectrum, print out readable string
                }
                else
                {
                    myFile[i].WriteLine("N/A");             // Non-windowed spectra, print "N/A"
                }
                // Fixed spectrum - pulse start length
                myFile[i].WriteLine("Pulse Start Length (fixed freq):");
                if (specType == "Fixed")
                {
                    myFile[i].WriteLine(fixed_startLength);
                }
                else
                {
                    myFile[i].WriteLine("N/A");
                }
                // Fixed spectrum - number of steps
                myFile[i].WriteLine("Number of Steps (fixed freq):");
                if (specType == "Fixed")
                {
                    myFile[i].WriteLine(myRabiSelector.stepsSelect.Value.ToString());
                }
                else
                {
                    myFile[i].WriteLine("N/A");
                }
                // Name for each spectrum
                for (int j = 0; j < myExperimentDialog.NumberOfSpectra.Value; j++)
                {
                    myFile[i].WriteLine("Spectrum " + (j + 1) + " name:");
                    myFile[i].WriteLine(myExperimentDialog.SpectrumNames[j].Text);
                }
                // Notes section
                myFile[i].WriteLine("Notes:");
                myFile[i].WriteLine("#" + myExperimentDialog.NotesBox.Text);
                // Title for data
                myFile[i].WriteLine("Data:");

                // Flush & close the file
                myFile[i].Flush();
                myFile[i].Close();
                //*********************************//

                // For the next filename:
                // Only needs to happen for windowed files
                //*********************//
                if (specType == "Windowed")
                {
                    // If we are still on the red side, just decrease the sideband number
                    if (i < sbToScan)
                    {
                        sbCurrent--;
                    }
                    else if (i == sbToScan)
                    // If we have reached the carrier
                    {
                        // Change R to B
                        sbRedOrBlue = 'B';
                        // Increase sideband number
                        sbCurrent++;
                    }
                    // If we are on the blue side, just increase the sideband number
                    else
                    {
                        sbCurrent++;
                    }
                }
            } //End of loop which goes through each file
        }
Esempio 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();
                    }
                }
            }
        }
Esempio n. 3
0
        private void CreateFromTemplateButton_Click(object sender, EventArgs e)
        {
            if (PulseTree.Nodes.Count == 0)
            {
                WriteMessage("Can't create pulse sequence: No laser states have been set", true);
                return;
            }

            RabiSelector myRabiSelector = new RabiSelector(PulseTree.Nodes);

            myRabiSelector.startExperimentButton.Enabled = false;
            myRabiSelector.ShowDialog();

            // If user did not press OK, don't do anything else in this method
            if (myRabiSelector.DialogResult != DialogResult.OK)
            {
                return;
            }

            // Create new treeview object to build new pulse tree into
            TreeView newPulseTree = new TreeView();

            // Grab sweep parameters from form
            int startLength = (int)myRabiSelector.startLengthSelect.Value;
            int stepSize    = (int)myRabiSelector.stepSizeSelect.Value;
            int steps       = (int)myRabiSelector.stepsSelect.Value;
            int repeats     = (int)myRabiSelector.repeatsSelect.Value;

            int pulseLength = new int();

            // Create the Rabi-type sequence using data from form
            LoopState[]  myLoopStates  = new LoopState[steps];
            TreeNode[]   myLoopNodes   = new TreeNode[steps];
            LaserState[] myLaserStates = new LaserState[steps];
            TreeNode[]   myLaserNodes  = new TreeNode[steps];

            // For each step
            for (int i = 0; i < steps; i++)
            {
                // Calculate pulse length
                pulseLength = startLength + i * stepSize;
                // Add a new loop with this pulse length
                addRabiLoop(newPulseTree, myLoopStates[i], myLoopNodes[i], myLaserStates[i], myLaserNodes[i], pulseLength, repeats);
            }

            // Create 'Stop Experiment' state
            LaserState stop = new LaserState();

            stop.Name      = "Stop Experiment";
            stop.StateType = LaserState.PulseType.STOP;
            // Add 'Stop Experiment' state as a node to new pulse tree
            TreeNode stopNode = newPulseTree.Nodes.Add(stop.Name);

            stopNode.Tag = stop;

            // Disable redrawing while we update
            PulseTree.BeginUpdate();
            // Clear old nodes from PulseTree
            PulseTree.Nodes.Clear();
            // Clone nodes from newPulseTree into main PulseTree control
            for (int i = 0; i < newPulseTree.Nodes.Count; i++)
            {
                PulseTree.Nodes.Add((TreeNode)newPulseTree.Nodes[i].Clone());
            }
            PulseTree.CollapseAll();
            PulseTree.EndUpdate();      // Re-enable redrawing
        }
Esempio n. 4
0
        // Method to write the metadata to files
        // Gets filenames from private member myFileName
        private void writeMetadataToFile(   ref StartExperimentDialog myExperimentDialog, ref RabiSelector myRabiSelector,
            ref string FolderPath, ref TextWriter[] myFile, int numberOfFiles)
        {
            // These variables are needed for windowed files only
            // But need to create them anyway else C# will complain...
            //*****************//
            // Store the number sideband we are on
            int sbCurrent = sbToScan;
            // Store whether we are on a red or blue sideband
            char sbRedOrBlue = 'R';
            // Store the current sideband in readable format e.g. 001R
            string sbCurrentString = "";
            //*****************//

            // Go through each file (this will only be run once for continuous & fixed files)
            for (int i = 0; i < numberOfFiles; i++)
            {
                // Generating the current filename:
                //*******************************//
                // This line happens for both continuous & windowed files
                myFileName[i] = FolderPath + @"\" + myExperimentDialog.ExperimentName.Text + "_readings";

                // These bits only need adding to windowed files
                if (specType == "Windowed")
                {
                    myFileName[i] += "_";

                    // Add preceding 0s to keep format of sideband number as XXX
                    if (sbCurrent < 10) sbCurrentString = "00";
                    else if (sbCurrent < 100) sbCurrentString = "0";
                    else sbCurrentString = "";

                    // Add current sideband number to filename
                    sbCurrentString += sbCurrent;
                    // If not on carrier, add R or B
                    if (sbCurrent != 0) sbCurrentString += sbRedOrBlue;

                    // Add string to filename
                    myFileName[i] += sbCurrentString;
                }
                myFileName[i] += ".txt";
                //*******************************//

                // Now we get to actually create the file!
                myFile[i] = new StreamWriter(myFileName[i]);

                //*********************************//
                // Write the metadata to the file
                //
                myFile[i].WriteLine("Spectroscopy data file");
                myFile[i].WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
                // Spectrum type
                myFile[i].WriteLine("Spectrum Type:");
                myFile[i].WriteLine(specType);
                // 729 direction
                myFile[i].WriteLine("729 Direction:");
                myFile[i].WriteLine(specDir);
                // Trap voltage
                myFile[i].WriteLine("Trap Voltage (V):");
                myFile[i].WriteLine(this.trapVBox.Value);
                // Axial frequency
                myFile[i].WriteLine("Axial Frequency (kHz):");
                myFile[i].WriteLine(this.axFreqBox.Value);
                // Modified cyc freq
                myFile[i].WriteLine("Modified Cyclotron Frequency (kHz):");
                myFile[i].WriteLine(this.modcycFreqBox.Value);
                // Magnetron freq
                myFile[i].WriteLine("Magnetron Frequency (kHz):");
                myFile[i].WriteLine(this.magFreqBox.Value);
                // AOM start freq
                myFile[i].WriteLine("AOM Start Frequency (MHz):");
                double startFreqMHz = (double)(startFreqArray[i] / 1000000d);       // Calculate in MHz (stored in Hz)
                myFile[i].WriteLine(startFreqMHz);
                // Carrier frequency
                myFile[i].WriteLine("Carrier Frequency (MHz):");
                myFile[i].WriteLine(this.carFreqBox.Value);
                // Step size
                myFile[i].WriteLine("Step Size (kHz or ticks):");
                // For fixed spectra, put in step size of pulse length variation
                if (specType == "Fixed") myFile[i].WriteLine(fixed_stepSize);
                else  myFile[i].WriteLine(this.stepSizeBox.Value);  // Othewise, take from core form
                // Sidebands/side
                myFile[i].WriteLine("Sidebands to scan / side:");
                if (specType == "Windowed") myFile[i].WriteLine(sbToScan);
                else myFile[i].WriteLine("N/A");
                // Sideband width
                myFile[i].WriteLine("Sideband Width (steps):");
                if (specType == "Windowed") myFile[i].WriteLine(sbWidth);
                else myFile[i].WriteLine("N/A");
                // 729 RF amplitude
                myFile[i].WriteLine("729 RF Amplitude (dBm):");
                myFile[i].WriteLine(rfAmp);
                // Number of repeats
                myFile[i].WriteLine("Number of repeats per frequency:");
                myFile[i].WriteLine(myExperimentDialog.NumberOfRepeats.Value);
                // Number interleaved
                myFile[i].WriteLine("File contains interleaved spectra:");
                myFile[i].WriteLine(myExperimentDialog.NumberOfSpectra.Value);
                // Sideband number
                myFile[i].WriteLine("This is sideband:");
                if (specType == "Windowed") myFile[i].WriteLine(sbCurrentString);   // Windowed spectrum, print out readable string
                else myFile[i].WriteLine("N/A");            // Non-windowed spectra, print "N/A"
                // Fixed spectrum - pulse start length
                myFile[i].WriteLine("Pulse Start Length (fixed freq):");
                if (specType == "Fixed") myFile[i].WriteLine(fixed_startLength);
                else myFile[i].WriteLine("N/A");
                // Fixed spectrum - number of steps
                myFile[i].WriteLine("Number of Steps (fixed freq):");
                if (specType == "Fixed") myFile[i].WriteLine(myRabiSelector.stepsSelect.Value.ToString());
                else myFile[i].WriteLine("N/A");
                // Name for each spectrum
                for (int j = 0; j < myExperimentDialog.NumberOfSpectra.Value; j++)
                {
                    myFile[i].WriteLine("Spectrum " + (j+1) + " name:");
                    myFile[i].WriteLine(myExperimentDialog.SpectrumNames[j].Text);
                }
                // Notes section
                myFile[i].WriteLine("Notes:");
                myFile[i].WriteLine("#" + myExperimentDialog.NotesBox.Text);
                // Title for data
                myFile[i].WriteLine("Data:");

                // Flush & close the file
                myFile[i].Flush();
                myFile[i].Close();
                //*********************************//

                // For the next filename:
                // Only needs to happen for windowed files
                //*********************//
                if (specType == "Windowed")
                {

                    // If we are still on the red side, just decrease the sideband number
                    if (i < sbToScan) sbCurrent--;
                    else if (i == sbToScan)
                    // If we have reached the carrier
                    {
                        // Change R to B
                        sbRedOrBlue = 'B';
                        // Increase sideband number
                        sbCurrent++;
                    }
                    // If we are on the blue side, just increase the sideband number
                    else sbCurrent++;
                }

            } //End of loop which goes through each file
        }
Esempio n. 5
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();

                    }

                }

            }
        }
Esempio n. 6
0
        private void CreateFromTemplateButton_Click(object sender, EventArgs e)
        {
            if (PulseTree.Nodes.Count == 0)
            {
                WriteMessage("Can't create pulse sequence: No laser states have been set", true);
                return;
            }

            RabiSelector myRabiSelector = new RabiSelector(PulseTree.Nodes);
            myRabiSelector.startExperimentButton.Enabled = false;
            myRabiSelector.ShowDialog();

            // If user did not press OK, don't do anything else in this method
            if (myRabiSelector.DialogResult != DialogResult.OK) return;

            // Create new treeview object to build new pulse tree into
            TreeView newPulseTree = new TreeView();

            // Grab sweep parameters from form
            int startLength = (int)myRabiSelector.startLengthSelect.Value;
            int stepSize = (int)myRabiSelector.stepSizeSelect.Value;
            int steps = (int)myRabiSelector.stepsSelect.Value;
            int repeats = (int)myRabiSelector.repeatsSelect.Value;

            int pulseLength = new int();

            // Create the Rabi-type sequence using data from form
            LoopState[] myLoopStates = new LoopState[steps];
            TreeNode[] myLoopNodes = new TreeNode[steps];
            LaserState[] myLaserStates = new LaserState[steps];
            TreeNode[] myLaserNodes = new TreeNode[steps];

            // For each step
            for (int i = 0; i < steps; i++)
            {
                // Calculate pulse length
                pulseLength = startLength + i * stepSize;
                // Add a new loop with this pulse length
                addRabiLoop(newPulseTree, myLoopStates[i], myLoopNodes[i], myLaserStates[i], myLaserNodes[i], pulseLength, repeats);
            }

            // Create 'Stop Experiment' state
            LaserState stop = new LaserState();
            stop.Name = "Stop Experiment";
            stop.StateType = LaserState.PulseType.STOP;
            // Add 'Stop Experiment' state as a node to new pulse tree
            TreeNode stopNode = newPulseTree.Nodes.Add(stop.Name);
            stopNode.Tag = stop;

            // Disable redrawing while we update
            PulseTree.BeginUpdate();
            // Clear old nodes from PulseTree
            PulseTree.Nodes.Clear();
            // Clone nodes from newPulseTree into main PulseTree control
            for (int i = 0; i < newPulseTree.Nodes.Count; i++)
            {
                PulseTree.Nodes.Add((TreeNode)newPulseTree.Nodes[i].Clone());
            }
            PulseTree.CollapseAll();
            PulseTree.EndUpdate();      // Re-enable redrawing
        }