Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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;
        }