Ejemplo n.º 1
0
        void WriteStateToBinary(LaserState State, BinaryWriter Writer)
        {
            if (State.StateType == LaserState.PulseType.STOP)
            {
                if (bStopSignalPresent)
                {
                    WriteMessage("Warning: Multiple stop signals written to Binary file", true);
                }
                else //first stop signal written
                {
                    bStopSignalPresent = true;
                }
            }

            // Write 3 bytes of data for Ticks
            byte[] Data  = new byte[4];
            byte[] Ticks = BitConverter.GetBytes(State.Ticks * 32);

            if (BitConverter.IsLittleEndian) //Least significant bits are at start of array
            {
                for (int i = 2; i >= 0; i--)
                {
                    Data[i + 1] = Ticks[i];
                }
            }
            else
            {
                MessageBox.Show("Byte Conversion Problem (Are you big endian?)");
            }

            //Fill last 5 bits of Data[1] with laser state logic
            Data[1] += (byte)(GetIntFromBool(State.Laser729P2) << 4);
            Data[1] += (byte)(GetIntFromBool(State.LaserAux1) << 3);
            Data[1] += (byte)(GetIntFromBool(State.Laser854FREQ) << 2);
            Data[1] += (byte)(GetIntFromBool(State.Laser854POWER) << 1);
            Data[1] += (byte)(GetIntFromBool(State.Laser729P1));

            // Write one more byte (Data[0]) for lasers (bits 7:3)...
            Data[0]  = 0;
            Data[0] += (byte)(GetIntFromBool(State.Laser729P0) << 7);
            Data[0] += (byte)(GetIntFromBool(State.Laser854) << 6);
            Data[0] += (byte)(GetIntFromBool(State.Laser729) << 5);
            Data[0] += (byte)(GetIntFromBool(State.Laser397B2) << 4);
            Data[0] += (byte)(GetIntFromBool(State.Laser397B1) << 3);
            //...and pulse type (bits 2:0)
            Data[0] += (byte)State.StateType;

            //Write Data[] byte array to the hex file (in reverse order, MSB first)
            for (int i = 3; i >= 0; i--)
            {
                Writer.Write(Data[i]);
            }

            InstructionsWritten++;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called after OpenXMLFileDialog has closed successfully. Clears then populates PulseTree based on contents of chosen XML File.
        /// </summary>
        void OpenXMLFile()
        {
            XmlTextReader XMLFile = new XmlTextReader(openXMLFileDialog.FileName);

            List <TreeNode> NodeList = new List <TreeNode>();

            PulseTree.BeginUpdate();
            PulseTree.Nodes.Clear();

            while (XMLFile.Read())
            {
                if (XMLFile.NodeType == XmlNodeType.Element)
                {
                    if (XMLFile.Name.ToUpper() == "Pulse".ToUpper())
                    {
                        LaserState State = CreateStateFromXMLLine(XMLFile);
                        TreeNode   Node  = new TreeNode();
                        Node.Text = State.Name;
                        Node.Tag  = State;
                        NodeList.Add(Node);
                    }
                    else if (XMLFile.Name.ToUpper() == "Loop".ToUpper())
                    {
                        LoopState Loop = new LoopState();
                        while (XMLFile.MoveToNextAttribute())
                        {
                            if (XMLFile.Name.ToUpper() == "LoopCount".ToUpper())
                            {
                                Loop.LoopCount = System.Int32.Parse(XMLFile.Value);
                            }
                            else if (XMLFile.Name.ToUpper() == "Name".ToUpper())
                            {
                                Loop.Name = XMLFile.Value;
                            }
                            else if (XMLFile.Name.ToUpper() == "FPGALoop".ToUpper())
                            {
                                Loop.bIsFPGALoop = System.Boolean.Parse(XMLFile.Value);
                            }
                        }
                        TreeNode Node = ReadLoopIntoNode(new TreeNode(), XMLFile);

                        Node.Text  = Loop.Name;
                        Node.Text += " (Loop x" + Loop.LoopCount + ")";
                        Node.Tag   = Loop;
                        NodeList.Add(Node);
                    }
                }
            }
            PulseTree.Nodes.AddRange(NodeList.ToArray());
            PulseTree.CollapseAll();
            PulseTree.EndUpdate();
            XMLFile.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes a LaserState XML element to file.
        /// </summary>
        /// <param name="State">LaserState to write.</param>
        /// <param name="Writer">Open XmlWriter representing XML File to write to.</param>
        void WriteLaserStateToFile(LaserState State, XmlWriter Writer)
        {
            Writer.WriteStartElement("Pulse");

            Writer.WriteAttributeString("Laser397B1", GetStringFromBool(State.Laser397B1));
            Writer.WriteAttributeString("Laser397B2", GetStringFromBool(State.Laser397B2));
            Writer.WriteAttributeString("Laser729", GetStringFromBool(State.Laser729));
            Writer.WriteAttributeString("Laser854", GetStringFromBool(State.Laser854));
            Writer.WriteAttributeString("Laser729RF1", GetStringFromBool(State.Laser729RF1));
            Writer.WriteAttributeString("Laser729RF2", GetStringFromBool(State.Laser729RF2));
            Writer.WriteAttributeString("Laser854POWER", GetStringFromBool(State.Laser854POWER));
            Writer.WriteAttributeString("Laser854FREQ", GetStringFromBool(State.Laser854FREQ));
            Writer.WriteAttributeString("LaserAux1", GetStringFromBool(State.LaserAux1));
            Writer.WriteAttributeString("LaserAux2", GetStringFromBool(State.LaserAux2));


            if (State.StateType == LaserState.PulseType.STARTLOOP)
            {
                Writer.WriteAttributeString("Type", "Other");
            }
            else if (State.StateType == LaserState.PulseType.NORMAL)
            {
                Writer.WriteAttributeString("Type", "Normal");
            }
            else if (State.StateType == LaserState.PulseType.WAIT_LABVIEW)
            {
                Writer.WriteAttributeString("Type", "Wait_Labview");
            }
            else if (State.StateType == LaserState.PulseType.WAIT_MAINSPHASE)
            {
                Writer.WriteAttributeString("Type", "Wait_MainsPhase");
            }
            else if (State.StateType == LaserState.PulseType.COUNT)
            {
                Writer.WriteAttributeString("Type", "Count");
            }
            else if (State.StateType == LaserState.PulseType.STOP)
            {
                Writer.WriteAttributeString("Type", "Stop");
            }
            else if (State.StateType == LaserState.PulseType.SENDDATA)
            {
                Writer.WriteAttributeString("Type", "SendData");
            }

            Writer.WriteAttributeString("Ticks", State.Ticks.ToString());
            Writer.WriteAttributeString("TargetLength", State.TargetLength.ToString());
            Writer.WriteAttributeString("Name", State.Name);
            Writer.WriteEndElement();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes a LaserState XML element to file.
        /// </summary>
        /// <param name="State">LaserState to write.</param>
        /// <param name="Writer">Open XmlWriter representing XML File to write to.</param>
        void WriteLaserStateToFile(LaserState State, XmlWriter Writer)
        {
            Writer.WriteStartElement("Pulse");

            Writer.WriteAttributeString("Laser397B1", GetStringFromBool(State.Laser397B1));
            Writer.WriteAttributeString("Laser397B2", GetStringFromBool(State.Laser397B2));
            Writer.WriteAttributeString("Laser729", GetStringFromBool(State.Laser729));
            Writer.WriteAttributeString("Laser854", GetStringFromBool(State.Laser854));
            Writer.WriteAttributeString("Laser729RF1", GetStringFromBool(State.Laser729P0));
            Writer.WriteAttributeString("Laser729RF2", GetStringFromBool(State.Laser729P1));
            Writer.WriteAttributeString("Laser854POWER", GetStringFromBool(State.Laser854POWER));
            Writer.WriteAttributeString("Laser854FREQ", GetStringFromBool(State.Laser854FREQ));
            Writer.WriteAttributeString("LaserAux1", GetStringFromBool(State.LaserAux1));
            Writer.WriteAttributeString("LaserAux2", GetStringFromBool(State.Laser729P2));


            if (State.StateType == LaserState.PulseType.STARTLOOP)
            {
                Writer.WriteAttributeString("Type", "Other");
            }
            else if (State.StateType == LaserState.PulseType.NORMAL)
            {
                Writer.WriteAttributeString("Type", "Normal");
            }
            else if (State.StateType == LaserState.PulseType.WAIT_LABVIEW)
            {
                Writer.WriteAttributeString("Type", "Wait_Labview");
            }
            else if (State.StateType == LaserState.PulseType.WAIT_MAINSPHASE)
            {
                Writer.WriteAttributeString("Type", "Wait_MainsPhase");
            }
            else if (State.StateType == LaserState.PulseType.COUNT)
            {
                Writer.WriteAttributeString("Type", "Count");
            }
            else if (State.StateType == LaserState.PulseType.STOP)
            {
                Writer.WriteAttributeString("Type", "Stop");
            }
            else if (State.StateType == LaserState.PulseType.SENDDATA)
            {
                Writer.WriteAttributeString("Type", "SendData");
            }

            Writer.WriteAttributeString("Ticks", State.Ticks.ToString());
            Writer.WriteAttributeString("TargetLength", State.TargetLength.ToString());
            Writer.WriteAttributeString("Name", State.Name);
            Writer.WriteEndElement();
        }
Ejemplo n.º 5
0
        private void addRabiLoop(TreeView newPulseTree, LoopState loop, TreeNode loopNode,
                                 LaserState oldState, TreeNode laserNode, int pulseLength, int repeats)
        {
            // Create loop state for this pulse length
            loop             = new LoopState();
            loop.Name        = "Pulse length: " + (float)pulseLength * 0.64 / 1000 + "ms";
            loop.LoopCount   = repeats;
            loop.bIsFPGALoop = true;            // Always make it an FPGA loop

            // Add loop to top level of nodes on new pulse tree
            loopNode     = newPulseTree.Nodes.Add(loop.Name);
            loopNode.Tag = loop;
            // Select the loop node so that we can add children to it
            newPulseTree.SelectedNode = loopNode;

            LaserState[] newState = new LaserState[PulseTree.Nodes.Count];

            for (int i = 0; i < PulseTree.Nodes.Count; i++)
            {
                newState[i] = new LaserState();

                oldState = (LaserState)PulseTree.Nodes[i].Tag;
                copyState(oldState, newState[i]);
                // If we want to sweep this state, set the pulse length
                if (newState[i].toSweep)
                {
                    // Set correct ticks & target length
                    newState[i].Ticks        = pulseLength;
                    newState[i].TargetLength = pulseLength * 640;
                }
                // If not to sweep, just leave it as it is

                // Add the state as a child of the loop
                laserNode     = newPulseTree.SelectedNode.Nodes.Add(newState[i].Name);
                laserNode.Tag = newState[i];
            }

            // Create 'Send Data' LaserState
            LaserState sendData = new LaserState();

            sendData.Name      = "Send Data";
            sendData.StateType = LaserState.PulseType.SENDDATA;
            // Add 'Send Data' LaserState as a node to new pulse tree
            TreeNode sendDataNode = newPulseTree.Nodes.Add(sendData.Name);

            sendDataNode.Tag = sendData;
        }
Ejemplo n.º 6
0
 private void generateSequenceButton_Click(object sender, EventArgs e)
 {
     LaserState state = new LaserState();
     // Loop through each pulse
     for (int i = 0; i < pulseTemplate.Count; i++)
     {
         state = (LaserState)pulseTemplate[i].Tag;
         if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
         {
             // Call method to find out if that item is checked in pulseSelectBox
             if ( isItemChecked(state.Name) )
             {
                 // Set property in the state to say we should sweep this
                 state.toSweep = true;
             }
         }
     }
 }
Ejemplo n.º 7
0
 // Copies all the properties of one state into another (without any funny linking!)
 private void copyState(LaserState oldState, LaserState newState)
 {
     newState.Laser397B1    = oldState.Laser397B1;
     newState.Laser397B2    = oldState.Laser397B2;
     newState.Laser729      = oldState.Laser729;
     newState.Laser729RF1   = oldState.Laser729RF1;
     newState.Laser729RF2   = oldState.Laser729RF2;
     newState.Laser854      = oldState.Laser854;
     newState.Laser854FREQ  = oldState.Laser854FREQ;
     newState.Laser854POWER = oldState.Laser854POWER;
     newState.LaserAux1     = oldState.LaserAux1;
     newState.LaserAux2     = oldState.LaserAux2;
     newState.Name          = oldState.Name;
     newState.StateType     = oldState.StateType;
     newState.TargetLength  = oldState.TargetLength;
     newState.Ticks         = oldState.Ticks;
     newState.toSweep       = oldState.toSweep;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Recursive method to read nodes from XML File. Should be called after reading Loop opening element.
 /// </summary>
 /// <param name="Node">Node that childen are added to.</param>
 /// <param name="XMLFile">Open XmlTextReader representing XML File to read from.</param>
 /// <returns></returns>
 TreeNode ReadLoopIntoNode(TreeNode Node, XmlTextReader XMLFile)
 {
     while (XMLFile.Read())
     {
         if (XMLFile.NodeType == XmlNodeType.Element)
         {
             if (XMLFile.Name.ToUpper() == "Pulse".ToUpper())
             {
                 LaserState State = CreateStateFromXMLLine(XMLFile);
                 TreeNode   T     = Node.Nodes.Add(State.Name);
                 T.Tag = State;
             }
             else if (XMLFile.Name.ToUpper() == "Loop".ToUpper())
             {
                 LoopState Loop = new LoopState();
                 while (XMLFile.MoveToNextAttribute())
                 {
                     if (XMLFile.Name.ToUpper() == "LoopCount".ToUpper())
                     {
                         Loop.LoopCount = System.Int32.Parse(XMLFile.Value);
                     }
                     else if (XMLFile.Name.ToUpper() == "Name".ToUpper())
                     {
                         Loop.Name = XMLFile.Value;
                     }
                 }
                 TreeNode T = ReadLoopIntoNode(new TreeNode(), XMLFile);
                 T.Text  = Loop.Name;
                 T.Text += " (Loop x" + Loop.LoopCount + ")";
                 T.Tag   = Loop;
                 Node.Nodes.Add(T);
             }
         }
         else if (XMLFile.NodeType == XmlNodeType.EndElement)
         {
             if (XMLFile.Name.ToUpper() == "Loop".ToUpper())
             {
                 break;
             }
         }
     }
     return(Node);
 }
Ejemplo n.º 9
0
        private void generateSequenceButton_Click(object sender, EventArgs e)
        {
            LaserState state = new LaserState();

            // Loop through each pulse
            for (int i = 0; i < pulseTemplate.Count; i++)
            {
                state = (LaserState)pulseTemplate[i].Tag;
                if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                {
                    // Call method to find out if that item is checked in pulseSelectBox
                    if (isItemChecked(state.Name))
                    {
                        // Set property in the state to say we should sweep this
                        state.toSweep = true;
                    }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Recursive method to parse a collection of Nodes and writes to binary file.
        /// </summary>
        /// <param name="Nodes"></param>
        /// <param name="Writer"></param>
        void ParseNodeCollection(TreeNodeCollection Nodes, BinaryWriter Writer)
        {
            foreach (TreeNode Node in Nodes)
            {
                if (Node.Tag is LaserState)
                {
                    WriteStateToBinary((LaserState)Node.Tag, Writer);
                }
                else
                {
                    int LoopCount = ((LoopState)Node.Tag).LoopCount;
                    if (LoopCount < 0)
                    {
                        WriteMessage("Warning: Loop state found zero loops", true);
                    }

                    if (((LoopState)Node.Tag).bIsFPGALoop == true)
                    {
                        LaserState Startloop = new LaserState();
                        Startloop.StateType = LaserState.PulseType.STARTLOOP;
                        Startloop.Ticks     = LoopCount; //put loop number into ticks field.

                        WriteStateToBinary(Startloop, Writer);

                        ParseNodeCollection(Node.Nodes, Writer);

                        LaserState Endloop = new LaserState();
                        Endloop.StateType = LaserState.PulseType.ENDLOOP;

                        WriteStateToBinary(Endloop, Writer);
                    }
                    else
                    {
                        for (int i = 0; i < LoopCount; i++)
                        {
                            ParseNodeCollection(Node.Nodes, Writer);
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public RabiSelector(TreeNodeCollection pulseTemplatePassed)
        {
            InitializeComponent();
            pulseTemplate = pulseTemplatePassed;
            LaserState state = new LaserState();

            // Loop through each pulse
            for (int i = 0; i < pulseTemplate.Count; i++)
            {
                state = (LaserState)pulseTemplate[i].Tag;
                // If the state type is NORMAL or COUNT
                if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                {
                    // Add the name of the pulse to a list, for displaying on the form
                    pulseNameList.Add(state.Name);
                }
            }

            // Make list of pulse names the data source for checkbox list on form
            // This may not work....
            this.pulseSelectBox.DataSource = pulseNameList;
        }
Ejemplo n.º 12
0
        public RabiSelector(TreeNodeCollection pulseTemplatePassed)
        {
            InitializeComponent();
            pulseTemplate = pulseTemplatePassed;
            LaserState state = new LaserState();

            // Loop through each pulse
            for (int i = 0; i < pulseTemplate.Count; i++)
            {
                state = (LaserState)pulseTemplate[i].Tag;
                // If the state type is NORMAL or COUNT
                if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                {
                    // Add the name of the pulse to a list, for displaying on the form
                    pulseNameList.Add(state.Name);
                }
            }

            // Make list of pulse names the data source for checkbox list on form
            // This may not work....
            this.pulseSelectBox.DataSource = pulseNameList;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a new class of type Pulse based on current form input.
        /// </summary>
        /// <param name="bIsLoop">Set to true to create a Loop, false to create a LaserState.</param>
        /// <returns>Returns newly created Pulse.</returns>
        Pulse CreatePulseFromForm(bool bIsLoop)
        {
            if (bIsLoop)
            {
                LoopState L = new LoopState();
                if (NameBox.Text != "") //don't add a blank slot.
                {
                    L.Name = NameBox.Text;
                }
                L.LoopCount = (int)LoopNumberBox.Value;
                L.bIsFPGALoop = FPGALoopSelect.Checked;
                return L;
            }
            else
            {
                LaserState State = new LaserState();
                if (NameBox.Text != "") //don't add a blank slot.
                {
                    State.Name = NameBox.Text;
                }

                State.Laser397B1 = LaserBox397B1.Checked;
                State.Laser397B2 = LaserBox397B2.Checked;
                State.Laser729 = LaserBox729.Checked;
                State.Laser854 = LaserBox854.Checked;
                State.Laser854POWER = LaserBox854POWER.Checked;
                State.Laser854FREQ = LaserBox854FREQ.Checked;
                State.LaserAux1 = LaserBoxAux1.Checked;                
                
                switch ((int)SourceSelect729.Value)
                {
                    case 0:
                        State.Laser729P0 = true;
                        State.Laser729P1 = true;
                        State.Laser729P2 = true;
                        break;
                    case 1:
                        State.Laser729P0 = false;
                        State.Laser729P1 = true;
                        State.Laser729P2 = true;                        
                        break;
                    case 2:
                        State.Laser729P0 = true;
                        State.Laser729P1 = false;
                        State.Laser729P2 = true;
                        break;
                    case 3:
                        State.Laser729P0 = false;
                        State.Laser729P1 = false;
                        State.Laser729P2 = true;
                        break;
                    case 4:
                        State.Laser729P0 = true;
                        State.Laser729P1 = true;
                        State.Laser729P2 = false;
                        break;
                    case 5:
                        State.Laser729P0 = false;
                        State.Laser729P1 = true;
                        State.Laser729P2 = false;
                        break;
                    case 6:
                        State.Laser729P0 = true;
                        State.Laser729P1 = false;
                        State.Laser729P2 = false;
                        break;
                    case 7:
                        State.Laser729P0 = false;
                        State.Laser729P1 = false;
                        State.Laser729P2 = false;
                        break;
                }

                //Set pulse length to nearest number of ticks
                State.Ticks = tickRounder();
                State.TargetLength = (int)TicksBox.Value;

                if (PulseTypeBox.SelectedIndex == 0)
                {
                    State.StateType = LaserState.PulseType.STARTLOOP;
                }
                else if (PulseTypeBox.SelectedIndex == 1)
                {
                    State.StateType = LaserState.PulseType.WAIT_LABVIEW;
                }
                else if (PulseTypeBox.SelectedIndex == 2)
                {
                    State.StateType = LaserState.PulseType.WAIT_MAINSPHASE;
                }
                else if (PulseTypeBox.SelectedIndex == 3)
                {
                    State.StateType = LaserState.PulseType.NORMAL;
                }
                else if (PulseTypeBox.SelectedIndex == 4)
                {
                    State.StateType = LaserState.PulseType.COUNT;
                }
                else if (PulseTypeBox.SelectedIndex == 5)
                {
                    State.StateType = LaserState.PulseType.STOP;
                }
                else if (PulseTypeBox.SelectedIndex == 6)
                {
                    State.StateType = LaserState.PulseType.SENDDATA;
                }

                return State;
            }
        }
Ejemplo n.º 14
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
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Returns a LaserState from XML Line. Should be called after reading Pulse opening element.
        /// </summary>
        /// <param name="XMLFile">Open XmlTextReader representing XML File to read from.</param>
        /// <returns></returns>
        LaserState CreateStateFromXMLLine(XmlTextReader XMLFile)
        {
            LaserState State        = new LaserState();
            bool       bNameDefined = false; //If no name defined in the file then create one based on the pulse type

            #region XMLParseLine
            while (XMLFile.MoveToNextAttribute()) // Read every attribute
            {
                if (XMLFile.Name.ToUpper() == "Ticks".ToUpper())
                {
                    State.Ticks = System.Int32.Parse(XMLFile.Value);
                }
                else if (XMLFile.Name.ToUpper() == "TargetLength".ToUpper())
                {
                    State.TargetLength = System.Int32.Parse(XMLFile.Value);
                }
                else if (XMLFile.Name.ToUpper() == "Laser397B1".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser397B1 = true;
                    }
                    else
                    {
                        State.Laser397B1 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser397B2".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser397B2 = true;
                    }
                    else
                    {
                        State.Laser397B2 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser729".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729 = true;
                    }
                    else
                    {
                        State.Laser729 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser854".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser854 = true;
                    }
                    else
                    {
                        State.Laser854 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser729RF1".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729RF1 = true;
                    }
                    else
                    {
                        State.Laser729RF1 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser729RF2".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729RF2 = true;
                    }
                    else
                    {
                        State.Laser729RF2 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser854POWER".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser854POWER = true;
                    }
                    else
                    {
                        State.Laser854POWER = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser854FREQ".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser854FREQ = true;
                    }
                    else
                    {
                        State.Laser854FREQ = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "LaserAux1".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.LaserAux1 = true;
                    }
                    else
                    {
                        State.LaserAux1 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "LaserAux2".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.LaserAux2 = true;
                    }
                    else
                    {
                        State.LaserAux2 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Type".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "wait_labview".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.WAIT_LABVIEW;
                        if (!bNameDefined)
                        {
                            State.Name = "Wait_Labview";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "wait_mainsphase".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.WAIT_MAINSPHASE;
                        if (!bNameDefined)
                        {
                            State.Name = "Wait_MainsPhase";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "normal".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.NORMAL;
                        if (!bNameDefined)
                        {
                            State.Name = "Normal";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "count".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.COUNT;
                        if (!bNameDefined)
                        {
                            State.Name = "Count";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "stop".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.STOP;
                        if (!bNameDefined)
                        {
                            State.Name = "Stop";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "other".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.STARTLOOP;
                        if (!bNameDefined)
                        {
                            State.Name = "Other";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "senddata".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.SENDDATA;
                        if (!bNameDefined)
                        {
                            State.Name = "SendData";
                        }
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Name".ToUpper())
                {
                    State.Name   = XMLFile.Value;
                    bNameDefined = true;
                }
            }
            #endregion

            return(State);
        }
Ejemplo n.º 16
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
        }
Ejemplo n.º 17
0
        public RabiSelector(TreeNodeCollection pulseTemplatePassed)
        {
            InitializeComponent();
            pulseTemplate = pulseTemplatePassed;
            LaserState state     = new LaserState();
            LoopState  loopState = new LoopState();

            // Loop through each pulse
            for (int i = 0; i < pulseTemplate.Count; i++)
            {
                if (typeof(LaserState).IsAssignableFrom(pulseTemplate[i].Tag.GetType()))
                {
                    state = (LaserState)pulseTemplate[i].Tag;
                    // If the state type is NORMAL or COUNT
                    if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                    {
                        // Add the name of the pulse to a list, for displaying on the form
                        for (int k = 0; k < pulseNameList.Count; k++)
                        {
                            // Compare the item in the list to the desired item (both strings)
                            if (pulseNameList[k] == state.Name)
                            {
                                MessageBox.Show("Sequence creation failed. Template contains multiple pulses with same name. Please fix and try again.");
                                return;
                            }
                        }
                        pulseNameList.Add(state.Name);
                    }
                }
                if (typeof(LoopState).IsAssignableFrom(pulseTemplate[i].Tag.GetType()))
                {
                    loopState = (LoopState)pulseTemplate[i].Tag;
                    for (int k = 0; k < pulseNameList.Count; k++)
                    {
                        // Compare the item in the list to the desired item (both strings)
                        if (pulseNameList[k] == loopState.Name)
                        {
                            MessageBox.Show("Sequence creation failed. Template contains multiple pulses with same name. Please fix and try again.");
                            return;
                        }
                    }

                    pulseNameList.Add(loopState.Name);
                    for (int j = 0; j < pulseTemplate[i].Nodes.Count; j++)
                    {
                        if (typeof(LaserState).IsAssignableFrom(pulseTemplate[i].Nodes[j].Tag.GetType()))
                        {
                            state = (LaserState)pulseTemplate[i].Nodes[j].Tag;
                            // If the state type is NORMAL or COUNT
                            if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                            {
                                // Add the name of the pulse to a list, for displaying on the form
                                for (int k = 0; k < pulseNameList.Count; k++)
                                {
                                    // Compare the item in the list to the desired item (both strings)
                                    if (pulseNameList[k] == state.Name)
                                    {
                                        MessageBox.Show("Sequence creation failed. Template contains multiple pulses with same name. Please fix and try again.");
                                        return;
                                    }
                                }
                                pulseNameList.Add(state.Name);
                            }
                        }
                    }
                }
            }

            // Make list of pulse names the data source for checkbox list on form
            // This may not work....

            this.pulseSelectBox.DataSource = pulseNameList;
            this.ShowDialog();
        }
Ejemplo n.º 18
0
        void WriteStateToBinary(LaserState State, BinaryWriter Writer)
        {
            if (State.StateType == LaserState.PulseType.STOP)
            {
                if (bStopSignalPresent)
                {
                    WriteMessage("Warning: Multiple stop signals written to Binary file", true);
                }
                else //first stop signal written
                {
                    bStopSignalPresent = true;
                }
            }

            // Write 3 bytes of data for Ticks
            byte[] Data = new byte[4];
            byte[] Ticks = BitConverter.GetBytes(State.Ticks*32);
            if (BitConverter.IsLittleEndian) //Least significant bits are at start of array
            {
                for (int i = 2; i >= 0; i--)
                {
                    Data[i + 1] = Ticks[i];
                }
            }
            else MessageBox.Show("Byte Conversion Problem (Are you big endian?)");

            //Fill last 5 bits of Data[1] with laser state logic
            Data[1] += (byte)(GetIntFromBool(State.LaserAux2) << 4);
            Data[1] += (byte)(GetIntFromBool(State.LaserAux1) << 3);
            Data[1] += (byte)(GetIntFromBool(State.Laser854FREQ) << 2);
            Data[1] += (byte)(GetIntFromBool(State.Laser854POWER) << 1);
            Data[1] += (byte)(GetIntFromBool(State.Laser729RF2));

            // Write one more byte (Data[0]) for lasers (bits 7:3)...
            Data[0] = 0;
            Data[0] += (byte)(GetIntFromBool(State.Laser729RF1) << 7);
            Data[0] += (byte)(GetIntFromBool(State.Laser854) << 6);
            Data[0] += (byte)(GetIntFromBool(State.Laser729) << 5);
            Data[0] += (byte)(GetIntFromBool(State.Laser397B2) << 4);
            Data[0] += (byte)(GetIntFromBool(State.Laser397B1) << 3);
            //...and pulse type (bits 2:0)
            Data[0] += (byte)State.StateType;

            //Write Data[] byte array to the hex file (in reverse order, MSB first)
            for (int i = 3; i >= 0; i--)
            {
                Writer.Write(Data[i]);
            }

            InstructionsWritten++;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Recursive method to parse a collection of Nodes and writes to binary file.
        /// </summary>
        /// <param name="Nodes"></param>
        /// <param name="Writer"></param>
        void ParseNodeCollection(TreeNodeCollection Nodes, BinaryWriter Writer)
        {
            foreach (TreeNode Node in Nodes)
            {
                if (Node.Tag is LaserState)
                {
                    WriteStateToBinary((LaserState)Node.Tag, Writer);
                }
                else
                {
                    int LoopCount = ((LoopState)Node.Tag).LoopCount;
                    if (LoopCount < 0)
                    {
                        WriteMessage("Warning: Loop state found zero loops", true);
                    }

                    if (((LoopState)Node.Tag).bIsFPGALoop == true)
                    {
                        LaserState Startloop = new LaserState();
                        Startloop.StateType = LaserState.PulseType.STARTLOOP;
                        Startloop.Ticks = LoopCount; //put loop number into ticks field.

                        WriteStateToBinary(Startloop, Writer);

                        ParseNodeCollection(Node.Nodes, Writer);

                        LaserState Endloop = new LaserState();
                        Endloop.StateType = LaserState.PulseType.ENDLOOP;

                        WriteStateToBinary(Endloop, Writer);
                    }
                    else
                    {
                        for (int i = 0; i < LoopCount; i++)
                        {
                            ParseNodeCollection(Node.Nodes, Writer);
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
        private void generateSequenceButton_Click(object sender, EventArgs e)
        {
            /*
             * LaserState state = new LaserState();
             * // Loop through each pulse
             *
             *  for (int i = 0; i < pulseTemplate.Count; i++)
             *  {
             *  if (typeof(LaserState).IsAssignableFrom(pulseTemplate[i].Tag.GetType()))
             *  {
             *      state = (LaserState)pulseTemplate[i].Tag;
             *      if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
             *      {
             *          // Call method to find out if that item is checked in pulseSelectBox
             *          if (isItemChecked(state.Name))
             *          {
             *              // Set property in the state to say we should sweep this
             *              state.toSweep = true;
             *          }
             *      }
             *  }
             * }*/

            LaserState state     = new LaserState();
            LoopState  loopState = new LoopState();

            // Loop through each pulse
            for (int i = 0; i < pulseTemplate.Count; i++)
            {
                if (typeof(LaserState).IsAssignableFrom(pulseTemplate[i].Tag.GetType()))
                {
                    state = (LaserState)pulseTemplate[i].Tag;
                    // If the state type is NORMAL or COUNT
                    if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                    {
                        if (isItemChecked(state.Name))
                        {
                            // Set property in the state to say we should sweep this
                            state.toSweep = true;
                        }
                    }
                }
                if (typeof(LoopState).IsAssignableFrom(pulseTemplate[i].Tag.GetType()))
                {
                    loopState = (LoopState)pulseTemplate[i].Tag;
                    if (isItemChecked(loopState.Name))
                    {
                        // Set property in the state to say we should sweep this
                        loopState.toSweep = true;
                    }
                    for (int j = 0; j < pulseTemplate[i].Nodes.Count; j++)
                    {
                        if (typeof(LaserState).IsAssignableFrom(pulseTemplate[i].Nodes[j].Tag.GetType()))
                        {
                            state = (LaserState)pulseTemplate[i].Nodes[j].Tag;
                            // If the state type is NORMAL or COUNT
                            if (state.StateType == LaserState.PulseType.NORMAL || state.StateType == LaserState.PulseType.COUNT)
                            {
                                if (isItemChecked(state.Name))
                                {
                                    // Set property in the state to say we should sweep this
                                    state.toSweep = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
 // Copies all the properties of one state into another (without any funny linking!)
 private void copyState(LaserState oldState, LaserState newState)
 {
     newState.Laser397B1 = oldState.Laser397B1;
     newState.Laser397B2 = oldState.Laser397B2;
     newState.Laser729 = oldState.Laser729;
     newState.Laser729RF1 = oldState.Laser729RF1;
     newState.Laser729RF2 = oldState.Laser729RF2;
     newState.Laser854 = oldState.Laser854;
     newState.Laser854FREQ = oldState.Laser854FREQ;
     newState.Laser854POWER = oldState.Laser854POWER;
     newState.LaserAux1 = oldState.LaserAux1;
     newState.LaserAux2 = oldState.LaserAux2;
     newState.Name = oldState.Name;
     newState.StateType = oldState.StateType;
     newState.TargetLength = oldState.TargetLength;
     newState.Ticks = oldState.Ticks;
     newState.toSweep = oldState.toSweep;
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Returns a LaserState from XML Line. Should be called after reading Pulse opening element.
        /// </summary>
        /// <param name="XMLFile">Open XmlTextReader representing XML File to read from.</param>
        /// <returns></returns>
        LaserState CreateStateFromXMLLine(XmlTextReader XMLFile)
        {
            LaserState State = new LaserState();
            bool bNameDefined = false; //If no name defined in the file then create one based on the pulse type
            #region XMLParseLine
            while (XMLFile.MoveToNextAttribute()) // Read every attribute
            {
                if (XMLFile.Name.ToUpper() == "Ticks".ToUpper())
                {
                    State.Ticks = System.Int32.Parse(XMLFile.Value);
                }
                else if (XMLFile.Name.ToUpper() == "TargetLength".ToUpper())
                {
                    State.TargetLength = System.Int32.Parse(XMLFile.Value);
                }
                else if (XMLFile.Name.ToUpper() == "Laser397B1".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser397B1 = true;
                    }
                    else
                    {
                        State.Laser397B1 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser397B2".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser397B2 = true;
                    }
                    else
                    {
                        State.Laser397B2 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser729".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729 = true;
                    }
                    else
                    {
                        State.Laser729 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser854".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser854 = true;
                    }
                    else
                    {
                        State.Laser854 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser729RF1".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729P0 = true;
                    }
                    else
                    {
                        State.Laser729P0 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser729RF2".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729P1 = true;
                    }
                    else
                    {
                        State.Laser729P1 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser854POWER".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser854POWER = true;
                    }
                    else
                    {
                        State.Laser854POWER = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Laser854FREQ".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser854FREQ = true;
                    }
                    else
                    {
                        State.Laser854FREQ = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "LaserAux1".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.LaserAux1 = true;
                    }
                    else
                    {
                        State.LaserAux1 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "LaserAux2".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "on".ToUpper())
                    {
                        State.Laser729P2 = true;
                    }
                    else
                    {
                        State.Laser729P2 = false;
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Type".ToUpper())
                {
                    if (XMLFile.Value.ToUpper() == "wait_labview".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.WAIT_LABVIEW;
                        if (!bNameDefined)
                        {
                            State.Name = "Wait_Labview";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "wait_mainsphase".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.WAIT_MAINSPHASE;
                        if (!bNameDefined)
                        {
                            State.Name = "Wait_MainsPhase";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "normal".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.NORMAL;
                        if (!bNameDefined)
                        {
                            State.Name = "Normal";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "count".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.COUNT;
                        if (!bNameDefined)
                        {
                            State.Name = "Count";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "stop".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.STOP;
                        if (!bNameDefined)
                        {
                            State.Name = "Stop";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "other".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.STARTLOOP;
                        if (!bNameDefined)
                        {
                            State.Name = "Other";
                        }
                    }
                    else if (XMLFile.Value.ToUpper() == "senddata".ToUpper())
                    {
                        State.StateType = LaserState.PulseType.SENDDATA;
                        if (!bNameDefined)
                        {
                            State.Name = "SendData";
                        }
                    }
                }
                else if (XMLFile.Name.ToUpper() == "Name".ToUpper())
                {
                    State.Name = XMLFile.Value;
                    bNameDefined = true;
                }
            }
            #endregion

            return State;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a new class of type Pulse based on current form input.
        /// </summary>
        /// <param name="bIsLoop">Set to true to create a Loop, false to create a LaserState.</param>
        /// <returns>Returns newly created Pulse.</returns>
        Pulse CreatePulseFromForm(bool bIsLoop)
        {
            if (bIsLoop)
            {
                LoopState L = new LoopState();
                if (NameBox.Text != "") //don't add a blank slot.
                {
                    L.Name = NameBox.Text;
                }
                L.LoopCount   = (int)LoopNumberBox.Value;
                L.bIsFPGALoop = FPGALoopSelect.Checked;
                return(L);
            }
            else
            {
                LaserState State = new LaserState();
                if (NameBox.Text != "") //don't add a blank slot.
                {
                    State.Name = NameBox.Text;
                }

                State.Laser397B1    = LaserBox397B1.Checked;
                State.Laser397B2    = LaserBox397B2.Checked;
                State.Laser729      = LaserBox729.Checked;
                State.Laser854      = LaserBox854.Checked;
                State.Laser854POWER = LaserBox854POWER.Checked;
                State.Laser854FREQ  = LaserBox854FREQ.Checked;
                State.LaserAux1     = LaserBoxAux1.Checked;

                switch ((int)SourceSelect729.Value)
                {
                case 0:
                    State.Laser729P0 = true;
                    State.Laser729P1 = true;
                    State.Laser729P2 = true;
                    break;

                case 1:
                    State.Laser729P0 = false;
                    State.Laser729P1 = true;
                    State.Laser729P2 = true;
                    break;

                case 2:
                    State.Laser729P0 = true;
                    State.Laser729P1 = false;
                    State.Laser729P2 = true;
                    break;

                case 3:
                    State.Laser729P0 = false;
                    State.Laser729P1 = false;
                    State.Laser729P2 = true;
                    break;

                case 4:
                    State.Laser729P0 = true;
                    State.Laser729P1 = true;
                    State.Laser729P2 = false;
                    break;

                case 5:
                    State.Laser729P0 = false;
                    State.Laser729P1 = true;
                    State.Laser729P2 = false;
                    break;

                case 6:
                    State.Laser729P0 = true;
                    State.Laser729P1 = false;
                    State.Laser729P2 = false;
                    break;

                case 7:
                    State.Laser729P0 = false;
                    State.Laser729P1 = false;
                    State.Laser729P2 = false;
                    break;
                }

                //Set pulse length to nearest number of ticks
                State.Ticks        = tickRounder();
                State.TargetLength = (int)TicksBox.Value;

                if (PulseTypeBox.SelectedIndex == 0)
                {
                    State.StateType = LaserState.PulseType.STARTLOOP;
                }
                else if (PulseTypeBox.SelectedIndex == 1)
                {
                    State.StateType = LaserState.PulseType.WAIT_LABVIEW;
                }
                else if (PulseTypeBox.SelectedIndex == 2)
                {
                    State.StateType = LaserState.PulseType.WAIT_MAINSPHASE;
                }
                else if (PulseTypeBox.SelectedIndex == 3)
                {
                    State.StateType = LaserState.PulseType.NORMAL;
                }
                else if (PulseTypeBox.SelectedIndex == 4)
                {
                    State.StateType = LaserState.PulseType.COUNT;
                }
                else if (PulseTypeBox.SelectedIndex == 5)
                {
                    State.StateType = LaserState.PulseType.STOP;
                }
                else if (PulseTypeBox.SelectedIndex == 6)
                {
                    State.StateType = LaserState.PulseType.SENDDATA;
                }

                return(State);
            }
        }
Ejemplo n.º 24
0
        private void addRabiLoop(TreeView newPulseTree,LoopState loop, TreeNode loopNode,
            LaserState oldState, TreeNode laserNode, int pulseLength, int repeats)
        {
            // Create loop state for this pulse length
            loop = new LoopState();
            loop.Name = "Pulse length: " + (float)pulseLength * 0.64 / 1000 + "ms";
            loop.LoopCount = repeats;
            loop.bIsFPGALoop = true;            // Always make it an FPGA loop

            // Add loop to top level of nodes on new pulse tree
            loopNode = newPulseTree.Nodes.Add(loop.Name);
            loopNode.Tag = loop;
            // Select the loop node so that we can add children to it
            newPulseTree.SelectedNode = loopNode;

            LaserState[] newState = new LaserState[PulseTree.Nodes.Count];

            for (int i = 0; i < PulseTree.Nodes.Count; i++)
            {
                newState[i] = new LaserState();

                oldState = (LaserState)PulseTree.Nodes[i].Tag;
                copyState(oldState, newState[i]);
                // If we want to sweep this state, set the pulse length
                if (newState[i].toSweep)
                {
                    // Set correct ticks & target length
                    newState[i].Ticks = pulseLength;
                    newState[i].TargetLength = pulseLength * 640;
                }
                // If not to sweep, just leave it as it is

                // Add the state as a child of the loop
                laserNode = newPulseTree.SelectedNode.Nodes.Add(newState[i].Name);
                laserNode.Tag = newState[i];
            }

            // Create 'Send Data' LaserState
            LaserState sendData = new LaserState();
            sendData.Name = "Send Data";
            sendData.StateType = LaserState.PulseType.SENDDATA;
            // Add 'Send Data' LaserState as a node to new pulse tree
            TreeNode sendDataNode = newPulseTree.Nodes.Add(sendData.Name);
            sendDataNode.Tag = sendData;
        }