Skip to main content
Skip table of contents

5.2 - Batch logging (Applies to T-Series and UD-Series)

The method we just used can also be used for batch logging. Batch logging is used when you are doing multiple groups of measurements and you wish to log each group into a separate file. We already know how to create a logging set, so to do batch logging requires two more things:

a) a way to start and stop the batch

b) a way to change the file name, or, automatically assign the filename

Starting and stopping the batch log:

Really this is just starting and stopping a logging set. The easiest way is to simply use a button:

1) On a page, right click and select Buttons-Button.

2) Right click on your new button component and select Properties.... Change the caption to Start / Stop.

3) Click on the Action tab and select Start / Stop Logging Set, then in the combo, select our MyLog logging set, then
click OK.

At this point we have a button that will start and stop the logging set. But, it doesn't tell us if the logging set is actually running. For this, we'll use a descriptive text component. We can treat the status of the logging set, which is either running or not running, as a digital input:

4) Right click on the page again and select Displays - Descriptive Text.

5) Right click on this new component and select Properties....

6) For the Expression type: logging.mylog.running

7) Change the word Text in the Text table to Not Logging, and then click Add to add a new row, putting 1 in the new
row under Threshold, and Logging for the Text. Click OK to close the window.

The logging.mylog.running is a variable of the our "mylog" logging set which will equal 0 if the logging set is not logging, and 1 if it is. To differentiate between the "running" variable of the "mylog" logging set and the running variable of other logging sets, sequences, etc. we have to specify exactly what we want. "logging." means we want a logging set. "mylog." means we want the logging set called "mylog", and "running" is a variable of the logging set mylog.

Now, if you click on the button you will see the descriptive text component change from Not Logging to Logging and back. The logging set is also starting and stopping.

Changing the logging file name:

Now that we can start and stop the logging set, we need to create a way to change the file name of our logging set. The file name is just another variable of the logging set: "strFileName", so we'll access it using logging.mylog.strFileName:

1) Right click somewhere on the page and select Displays - Variable Value

2) Right click on the new component and select Properties....

3) Change the Caption to Logging Path, set the Expression to: logging.mylog.strFileName, and clear out the Units. This sets up the display.

4) Click on the Action tab, and then select Set To from the available actions.

5) For Set To Channel, put logging.mylog.strFileName. Click OK.

At this point, you can click on the display of the logging path and it will prompt you for the file path. But, it'd be nicer if it displayed a standard windows File Save Window instead so the user could browse for the file:

6) Right click on our variable value component again and select Properties....

7) Go back to the Action tab and select Quick Sequence.

8) In the white space that appears, enter the following script:

private string path = File.FileSaveDialog(logging.mylog.strFileName)
if (!IsEmpty(path))
logging.mylog.strFileName = path

9) Click OK to close, then click on the path again to see it work.

To explain the script:

In the first line, we declare a string variable called path. It gets the result of the FileSaveDialog() function which is part of a group of functions which are always prefixed with File. The FileSaveDialog() displays the standard Windows File Save window.

In the second line, we look to see if the path variable is empty. This would occur if the user hit Cancel from the Save window.

If the user didn't hit Cancel, then we get to the third line, which assigns the path they selected to the logging set.

Automatically setting the file name:

Finally, let's quickly demonstrate how to automatically set the file name based on the time and date. What we need to do is change the start / stop logging button to change the file name to include the current time whenever the logging set is started:

1) Right click on the Start / Stop Logging button we created at the beginning of this section, and select Properties....

2) Go to the Action tab and change the Action to Quick Sequence. Enter the following script:

if (logging.mylog.running)
logging.mylog.strFileName = "c:\mydata_" + formatdatetime("%y%m%d_%H%M%S",systime()) + ".csv"

3) Click OK and give the button a try. You should see the variable value component update with a new filename every time the logging set starts up. Note that clicking on the variable value component to change the filename has been rendered moot as the start / stop button will reset the filename.

To explain the script above:

In the first line we see if the logging set is running.

If it is running, then in the second line we stop the logging set.

Otherwise, in the fourth line, we set the filename. The filename is made up of three strings combined together. The first and last parts are static, "c:\mydata_" and ".csv". The middle part contains the date. The FormatDateTime() function takes what is called a specifier that determines how you would like the date and time displayed. In this case it will be Year Month Day_Hour Minute Second with no spaces. Please see the DAQFactory help for more details on possible specifiers. The second part of the FormatDateTime() function takes the time you want to format. In this case, we use SysTime() which is the current system time.

Sample file: LJGuideSamples\LogBatch.ctl

JavaScript errors detected

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

If this problem persists, please contact our support.