Skip to main content
Skip table of contents

6.1 - Creating sequences (Applies to T-Series and UD-Series)

Much of what you can do in DAQFactory, such as acquiring data, logging it, and displaying it on the screen can be done without writing any script. However, to enjoy the full flexibility of DAQFactory, you will need to do at least a little basic scripting. You may think scripting is bad, but trust us: its the best way to get a computer to do exactly what you want. We could have made DAQFactory not have any scripting, but then every properties window for every feature would have thousands of choices, which would be much more cumbersome to use, and you still wouldn't have the flexibility of scripting. Fortunately, you can step into it slowly, using many of the built in features we've shown so far, but mixing in an occasional short script to do something unique.

We've seen some scripting already when we talked about conditional logging. This section will go over a few more of the basics of DAQFactory scripting so you'll understand the examples in the rest of this guide. It is not designed to be a complete overview of Sequences. For that you should read the DAQFactory User's Guide chapter on Sequences.

Script is used in a number of different places. In the conditional logging section we used script in Channel Events.

In the batch logging section we had script in the Action for a screen component. The primary place for script, however, is in a sequence. A sequence is script that either executes standalone in the background, or as a function to another piece of script. Because sequences can run in the background while the rest of DAQFactory does its thing, you can create a separate sequence for each different function of your application and have them all run at the same time. For example, if you want a loop that switches a valve every 30 seconds, and another loop that sends an email every day, you would create two separate sequences and run them both at the same time.

Creating a new sequence is as simple as creating a new logging set. Right click on SEQUENCES: in the Workspace and select Add Sequence. Enter a name for your sequence. Like every other name in DAQFactory, your sequence name must start with a letter and contain only letters, numbers and the underscore. Click OK and the new sequence is created and the sequence editor window displayed.

The sequence editor window is a simple text editor with some special features, like auto-indenting, that make it easier to write script. Before we jump into some of the script basics, a few important pointers. Our apologizes if we sound like we are preaching, but these are important points and will save you headaches down the road no matter whether you are scripting in DAQFactory, making webpages in PHP, or coding in Visual Basic. You'd be amazed at how many support calls we get because people didn't properly indent, can't figure out code they wrote a year ago, or don't see their decimal points:

Indenting:

Proper indenting of your script is very important. You should indent in 3 spaces on the line after any block level command (such as "if", "while", "for", "try", or "switch"), and indent out 3 spaces before the end of block commands (such as "endif", "endwhile", "endfor", or "endcatch"). Some lines do both, such as "else" and "catch". Here's a simple example of proper indenting. Don't worry about the script itself, just look at the indenting:

while(1)
try
if (x > 3)
y = 1
else
y = 2
endif
catch()
y = 4
endcatch
delay(1)
endwhile

Even if you don't understand any of the script above, you have to admit that this is easier to read than:

while(1)
try
if (x > 3)
y = 1
else
y = 2
endif
catch()
y = 4
endcatch
delay(1)
endwhile

OK, perhaps both are just unintelligible geek talk to you, but soon you will understand, and you should get into the habit of indenting properly from the start. There really are no excuses not to indent, unless, of course, your keyboard lacks a space bar.

Commenting:

We strongly recommend you put comments in your code. A comment is simply two slashes followed by whatever you'd like to say:

// this is a comment

global x // x is an important variable because...

You may think that you'll remember how your script works a year from now, but without good comments, it is very unlikely. The DAQFactory source is probably one half code and one half comments.

Decimals:

Whenever you need to type a value that is less than 1 and greater than -1, you should always put a zero in front of
the decimal point. In other words:

0.325 Correct

.325 Incorrect

-0.325 Correct

-.325 Incorrect

The reason for this is that when you have a page full of script the decimal place can easily be lost if there isn't that 0 in front. It may seem minor, but when its 2am and you can't figure out why your calculations are off because you confused 325 with .325 you'll wish you had gotten into this habit. Just look at this last sentence. If it was written properly as "confused with 325 with 0.325 you'll wish", it would be very obvious that the two numbers are not the same.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.