There are many ways to start or stop a sequence. When we say start or stop a sequence we mean running the sequence in its own thread. A thread is like a separate program that executes concurrently with other threads within DAQFactory. Sequences can also be called as functions or used as events. In these cases, they are not started, but are instead called. Called sequences do not run in their own thread, but instead run in the thread of the caller.
The easiest way to start or stop a sequence is to right click on the sequence name in the workspace and select Begin Sequence or End Sequence. You can also select the sequence in the sequence summary view and click the Begin or End button. You can get to the sequence summary view by clicking on SEQUENCES: in the workspace.
These two methods are not the most convenient methods however. A more convenient method is to create a screen component, such as a button, text component, panel, or descriptive text component and use the sequence.mySequence.begin() or sequence.mySequence.end() functions in the OnLButtonUp event. MySequence is the name of the desired sequence to start or stop. There are also start() and stop() functions that do the exact same thing (i.e. sequence.mySequence.start()). The descriptive text component provides a great way to do this:
1) On a page, right click and select Displays-Descriptive Text to create a new Descriptive Text component.
2) Hit the Enter key, or right click on the new component and select Properties... to open the properties window for the new component.
3) Under Expression put something like:
sequence.mySequence.running
replacing mySequence with the name of your sequence.
Running is a variable that exists in every sequence that will be 0 if the sequence is stopped, and 1 if the sequence is running.
4) Click on Texts right below Expression, then click on the button with three dots to the far right of that column to edit the list of texts.
5) In the new window, on the top left, click the yellow button to create a new text. This will add an item to the list with an edit box to give that item a name. Call the first item Stopped and press Enter. Repeat this a second time to create a second item called Running.
The texts list window is similar to many component properties windows that allow for multiple possible selections. All of them work in a similar way. The left side allows you to manage the items in the list, while the right side allows you to edit the properties for a particular item.
6) Click on Stopped that you just created, then on the right side, put Stopped for the Text. Leave the Threshold at 0 since 0 indicates stopped.
7) Click on Running, then put RUNNING for the Text and set the Threshold to 1 since 1 means the sequence is running.
8) Click Close which will return you to the main properties window.
If you'd like, you can click on TextMultiColor and the button with three dots in its row and create a different color for the two options. The first popup will have an option for Expression, which is the expression used to determine the color. In this case we want it to be Sequence.mySequence.Running, just like the main expression. Then click on Colors to edit the list of colors. It works just like the Texts list, but with colors.
So far, we have created a nice indicator of whether a sequence is running or not. We could use very similar settings to show the status of a valve or really anything with a couple discrete options. Now we just need to add some simple script in the OnLButtonUp event so that clicking the component runs or stops the sequence.
9) On the left side of the main Text Component Properties window, click on OnLButtonUp (Left Click). This will display the script editor for script that runs whenever the component is clicked.
10) Enter the following script, changing MySequence to match the name of your sequence:
if (Sequence.MySequence.Running)
sequence.mySequence.end()
else
sequence.mySequence.begin()
endif
11) Click Close to exit the properties window. The component will now either indicate that the sequence is stopped or running. Clicking on the component will either start or stop the sequence depending on its current state.
Note: many sequences, especially ones without loops, can be very fast to execute and may run and stop before your control ever updates to show it running.
This procedure creates a descriptive text component that will display either Stopped or RUNNING depending on the state of your sequence and when clicked will toggle the sequence between running and stopped. Take a look at the Action page of the component to see the settings. Other components, such as the button, static text, panel, have the same page and can also be set to trigger the sequence without displaying its status.