5. Generic Script Functions

The Script System comes with a set of generic, or core, functions that control the program flow. These functions are always available irrespective of the activated plug-ins. You will find these functions in the categories Core Functions , Function Sequences, and Time Functions (figure below).

../_images/100002010000016C000002591AF7FEE5FA0D46F1.png

5.1. Core Functions

5.1.1. Core Functions Overview

The category Core Functions contains functions that control program flow and the use of variables.

../_images/core_functions1.png

5.1.2. Interrupt Script

../_images/interrupt_script.svg

With this function you can interrupt the script execution. The function has the same effect as pressing the Interrupt button in the toolbar. The user can continue the script by pressing the Run button in the toolbar.

Important

If script execution is interrupted, all sequences running in parallel are interrupted and no communication with the script is possible.

5.1.3. Interrupt Sequence

../_images/interrupt_sequence3.svg

With this function you can interrupt the execution of the function sequence in which the function is contained. If several sequences are executed in parallel using the Parallelen Sequence, only the sequence containing the function is interrupted.

If the interrupt sequence function is executed, you will receive information in the Event Log of the application that the sequence was interrupted:

../_images/interrupt_sequence_message.png

You can double-click on the log entry to display the function and its operating panel in the Script Editor. You can then continue the execution by clicking on Continue in the control panel of the Interrupt Sequence function.

../_images/interrupt_sequence_continue.png

5.1.4. Show Message

../_images/10000490000034EB000034EB215655F378C8DAF2.svg

The Show Message function allows you to display a message to the user and optionally interrupt script execution. It is well suited for applications that require an intervention by the user at certain times during the execution of a script.

When you run this script function, the message can be displayed both in a message window…

Figure 1.1.3: Message window

… and in the Event Log view of the application:

Figure 1.1.4: Event log

In the Event Log, all messages are listed in chronological order. The optional Message Box always displays the last message.

Show Message Function Configuration

When configuring the message function, you can configure the following options:

../_images/show_message_config.png
  1. Enter your message text into the Message field.

  2. Select the type of message you want to display in the Message Type group. Depending on the message type, the relevant icon appears in the event log and in the message window and the message is highlighted with a type-specific color in the event log.

  3. In the Output pane you can set whether the message should be displayed in a separate message window (Show Message Box) and whether the message should appear in the Event Log (Write to Event Log).

  4. Select whether the message should interrupt script execution. If there is a check mark in this field, the complete script execution is interrupted until the user continues the program execution. If you display a message window with a Show Message Box, you should not select this option and use option instead.

  5. Here you can select whether the script execution will be continued after clicking OK in the message box window.

  6. Rich-Text - Turn on this option to format your text with bold, italics, colors, and more.

Depending on the options selected, this function works like this:

Show Message Box

Write to Event Log

Inter-rupt Script Exe-cution

Continue Script if User Clicks OK

Result

A message is written to the event log and then the next function is executed.

A message is written to the event log and script execution is interrupted. The execution can be continued by clicking the Run Script button in the script toolbar.

A message is written to the event log, a message box is displayed and then the next function is executed.

A message box is displayed. When the user clicks OK, the next script function is executed.

A message window is displayed and script execution is interrupted. Execution can be continued by clicking the Run Script button in the script toolbar.

Displaying variables content or process data

In the Message field of the function, you can also use variables (like $Volume) or Device property Identifiers (like $$neMESYS1.SyringeFillLevel). These serve as place holders and are replaced at script runtime by the contents of the variables or the process data of a certain device. As soon as you enter a dollar sign $ in the message input field, a list of available variables is displayed, from which you can select a variable (see figure below).

Figure 1.1.6: Using variables in Show Message function

E.g. you can enter the following text in the message input field:

The contents of variable A is $A.

If the variable $A contains the value 25.3 at runtime, then the function will display the following message:

The contents of variable A is 25.3.

Tip

You can display the contents of variables using the Show Message function, e.g. to check the results of calculations.

Tip

Click with the right mouse button in the input field and then select the context menu item Insert device property to insert a process data identifier of device process data you would like to print out, when Show Message function is executed.

Rich Text Support

If you activate the Enable rich text option, you get extensive possibilities to format your message text, to design lists or to insert pictures and hyperlinks. If the option is activated, a toolbar similar to that in a word processing application will be displayed:

../_images/show_message_rich_text.png

Important

Rich text needs more file space when script files are saved and may increase load times of script files so switch it on only in case you really need it.

5.1.5. Create Variable

../_images/1000119100003872000038728AF29595FE1DD321.svg

With Create Variable you can define a new variable and assign a name, a type hint, and a value to that variable (see figure below):

../_images/create_variable_function.png
  1. Name – set a unique name for your variable. For details concerning the naming of variables, please refer to section Naming Variables.

  2. Type Hint – choose the kind of variable you want to set.

  3. Value – give the variable a value or, if the variable is of the type JavaScript Expression, enter the JavaScript code to calculate the variable.

Tip

To prevent an incorrect variable name, the Name field accepts only names that start with a $ symbol.

Types of Variables

The variables in the script system are not typed and can hold a wide variety of values. For example, a numeric value can be assigned to a variable when it is created and a text can be stored in the same variable later. The Type Hint field in the configuration area is simply a hint as to which type is to be stored and is used to display a corresponding input field depending on the type. All types, Boolean, Number or Text can also be entered via a JavaScript expression. The following table is an overview of a selection of data that can be stored into variables:

Type Hint

Data / Values

Examples

image31

Boolean

Boolean values

true, false

image32

Number

Numeric values

24, 10, -13.23, -128, 0.001

image33

Text

Strings, words or text

Value1, Enter a value

image34

JavaScript

Device References (e.g. for passing devices to functions)

$$Nemesys_M_1 or $$Nemesys _M_1_ForceSensor

image34

JavaScript

Array of numbers

[3, 7, 8.5, 12, 23.5]

image34

JavaScript

Array of strings

[User1, User2, User3, User4]

image34

JavaScript

Array of device references

[$$Nemesys_M_1, $$Nemesys_M_2]

image34

JavaScript

Calculation result

25 + $TargetPositionX

image34

JavaScript

Read device properties / process data

$$Nemesy s_M_1.DosedVolume

Calculating using Variables

If you set the variable type to JavaScript Expression, you can define an expression in the field Value that is to be calculated during run time. This expression may include other variables to use their respective values. Script variables can be accessed via the variable name, which starts with a dollar $ sign.

Figure 1.1.8: Defining calculation variables

Tip

The auto-complete feature will support you during entering a new expression by listing all previously defined variables.

You can also directly read the properties / process data of a device within a JavasScript expression and include it in a calculation. In the following example, the variable $Flow is calculated as a twentieth of the device property $$Nemesys_M_1.MaxFlow . Device properties can be easily added using the context menu entry Insert device property .

../_images/10000201000001E7000000D09DED5F410BD67FC9.png

Tip

Click with the right mouse button in the input field and then select the context menu item Insert device property to directly access device process data values in the calculation.

Using the context menu you can also insert device references into the JavaScript code. This makes it possible to store device references (e.g. $$Nemesys_M_1) or arrays with device references (e.g. [$$Nemesys_M_1, $$Nemesys_M_2, $$Nemesys_M_3]) in variables. In the following example, a reference of the $$QmixP1_Pressure1 pressure sensor is stored in the $PressureSensor variable.

image46

The identifiers for device references start with two dollar signs like Device Properties, but consist only of the device name without any additional device property.

Operators

The following tables summarize available operators and their syntax:

Arithmetic Operators

Example

+

Addition

$a + $b

-

Subtraction

$a - 1

*

Multiplication

5 * $b

/

Division

$a / 10

%

Division and returning the remainder

$a % 5

Logical Operators

Example

==

Checks for equivalence

1 == 2

!=

Checks for difference

5 != 6

>

Checks for Larger Than

7 > 2

<

Checks for Smaller Than

3 < $a

Checks for Larger or Equivalent

$b 3

Checks for Smaller or Equivalent

$a $b

&&

Links two values with the logical AND

true && false

||

Links two values with the logical OR

$a || (b < 5)

!

Links a value with the logical NOT

!true == false

String Operators

Example

+

Assembles two strings or texts

text + $a

Operator Precedence

Operator precedence determines the order in which operators are evaluated. Operators with higher precedence are evaluated first.

Precedence

Operators

1

||

2

&&

3

== !=

4

< ≤ > ≥

5

+ -

6

\ / %

7

!

8

()

Parentheses allow you to influence the precedence in which the various operators are executed according to your needs. Refer to the JavaScript specification for more details about operator precedence.

Examples

The following examples show how to use variables for calculations:

Example 1

Adding two variables a and b and storing the result as a third variable c:

Name:

$c

JavaScript:

$a + $b

Example 2

Multiplication of the variable Speed with 5 and storing the result as the same variable:

Name:

$Speed

JavaScript:

$Speed * 5

Example 3

Connecting the two Boolean variables SwitchedOn and CheckOk with the logical AND and save the result as the variable TurnOn:

Name:

$TurnOn

JavaScript:

$SwitchedOn && $CheckOk

Example 4

You want to assign the current flow rate of the pump Nemesys_M_1 to the variable $Flow.

Name:

$Flow

JavaScript:

$$Nemesys_M_1.ActualFlow

Example 5

You want to create an array with 4 flow rates and assign it to the $TargetFlows variable.

Name:

$TargetFlows

JavaScript:

[0.12, 0.05, 0.2, 0.21]

Example 6

The $TargetFlows variable contains an array of 4 numeric values. You want to assign the third value in the array to the $NextFlow variable. The index for the array access is numbered starting from 0. I.e. to access the third element the index is 2.

Name:

$NextFlow

JavaScript:

$TargetFlows[2]

Example 7

You want to store an array with the two current values of the pressure sensors QmixP_1_Pressure1 and QmixP_1_Pressure2 in the variable $Pressures.

Name:

$Pressures

JavaScript:

[$$QmixP_1_Pressure1.ActualValue, $$QmixP_1_Pressure2.ActualValue]

Example 8

You want to store a device reference of the Nemesys_M_1 pump in the variable $Process Pump to be able to pass it to a function later.

Name:

$ProcessPump

JavaScript:

$$Nemesys_M_1

5.1.6. Set Variable

../_images/1000132400003872000038722A8DDCED1A890F1C.svg

With Set Variable you can assign a new value to an already existing variable. The configuration of the variable is equivalent to the function Create Variable.

Figure : Entering a variable name using the auto-complete

Tip

When entering a name, the auto-complete feature will provide you with a selection of all previously defined variable names.

Important

To be able to set the value of a variable using the Set Variable function, the variable has to be defined beforehand, e.g., by using the function Create Variable.

5.1.7. Variable Declaration Sequence

../_images/100015BD00003872000038722A0A6332DCBD75A0.svg

With the variable Declaration Sequence you can combine variables that you declare with Create Variable or Create Property Variable functions. This helps you to improve the clarity of your script. Instead of many individual variables, only the variable declaration sequence is visible and only when this sequence is expanded, the user sees the declared variables.

All variables are visible at the level in which the declaration sequence is located. This means that the variables within the sequence are declared as if they were at the level of the declaration sequence.

Figure : Example sequence with variables

With the sequence you can also group variables that logically belong together, making it easier for the user to find specific variables.

5.1.8. User Input

../_images/10001DE9000038720000387289754B44B2610975.svg

This function allows the reading of a single input value (number or text) into an existing variable. In the configuration area of the User Input function (see figure below), you can configure the following parameters:

../_images/user_input_config.png
  1. Label Text - Here you specify a text that will be displayed to the user during the execution of the function above the input field as a label and explanatory text.

  2. Variable - In this field you specify the variable to store the value entered by the user. In addition, the value of the variable is also used as the initial value when the input dialogue is displayed. This means if you initialise the variable with the value 5 beforehand, for example, the value 5 is displayed as the default value when the input dialogue is shown.

  3. Type Hint - You can specify the input type, number or text, here. Depending on the selected input type the user input dialog accepts only certain values.

  4. Enable Cancellation - If this checkbox is active, the displayed dialogue contains a Cancel button that allows you to cancel the input dialog.

  5. Rich Text - Turn on this option to format your text with bold, italics, colors, and more.

  6. Test Input Dialog - Clicking this button allows you to test the input dialog to check how the user will see the input dialog later during execution of the script function (see figure below).

    Input Dialog

    Input Dialog with Cancel Button

    input_dialog

    input_dialog_cancel

If the input is confirmed with OK during script execution, the variable contains the value entered by the user. If the dialogue is cancelled with Cancel, the variable contains an undefined value. In JavaScript, e.g. in a Conditional Sequence, you can then test whether the value is undefined as follows:

$InputVariable === undefined

The following example script tests whether the user has cancelled the input dialogue. In this case, a corresponding message is written in the event log:

../_images/input_dialog_canceled.png

Rich Text Support for Label Text

If you activate the Rich Text option, you get extensive possibilities to format your label text, to design lists or to insert pictures and hyperlinks. If the option is activated, a toolbar similar to that in a word processing application will be displayed:

../_images/user_input_rich_text.png

Important

Rich text needs more file space when script files are saved and may increase load times of script files so switch it on only in case you really need it.

5.1.9. Script Function Call

../_images/10002495000034EB000034EB5801BA1011E76C101.svg

Script Function Calls allow you to integrate your own scripts as functions. I.e. just as you create functions as reusable modules in other programming languages, you can also call your own functions in the script system in the form of external scripts.

../_images/10000201000001E1000001A9C4192918D20FBB5B.png

External script functions can have 0 – 10 input parameters and 0 – 10 return values . This allows you to pass values to the script (e.g. numeric values or variables) and read return values from the script and store them in script variables. Script File shows you the path to the external script file that is executed when the script is invoked.

In the section Programming your own script functions you will find detailed instructions on how to create your own script functions.

5.1.10. Execute JavaScript Code

../_images/javascript_logo1.svg

This function allows you to execute JavaScript code in the script system of the application. When you insert the function into your script, you will see the initial JavaScript code in the configuration area.

../_images/javascript_script_function_config.png

When the script is executed, it is loaded by the JavaScript engine and then the main() function is called. I.e. this function is the main function of the script and the logic should be implemented there.

Tip

Read the section Using JavaScript for a detailed introduction into the use of JavaScript for Script programming and how to use this function.

5.2. Function Sequences

5.2.1. Introduction to Function Sequences

Figure : List of function sequences

The Function Sequences category contains various types of function sequences. Function sequences are script functions that may contain a number of different functions. When Function Sequence is called, all script functions contained within this sequence are executed.

5.2.2. Counting Loop

../_images/100013490000388C0000388C4A5D96BDCF59F705.svg

The Counting Loop function allows for multiple sequential executions of the same function(s) within that loop. The number of times the loop is to be run is defined in the configuration area Loop Cycles.

In addition, you may set a name for the count variable Counter Variable of that loop. Within that loop, functions that support the use of variables may then use this variable to execute specific tasks or to perform additional calculations.

The number of loops may be defined explicitly, by setting a number, or implicitly, via a variable that returns a number (figure below, ).

image62

Additionally, you can assign a custom name to the Counter Variable of the present loop function (figure above, ). Within this loop, other functions may access the current loop count via this variable and use it for further calculations. This may be used, e.g., to control incremental moves of positioning systems.

Important

The counting variable of a counting loop always starts with the value 0 (zero). This is, a loop count set to 10 contains the values 0 to 9 for the successive loops.

Important

You should always insert a Delay in a loop to prevent the loop from blocking the application interface by consuming 100% processor power. A small delay of 10 ms – 100 ms is sufficient.

You can use the count variable Counter Variable to end the loop prematurely (abort). If you set the value of the count variable to a value >= the number of Loop Cycles within the loop using the Set Variable function, the loop is terminated at the next loop run.

Tip

You can end the counting loop prematurely by changing the counting variable.

5.2.3. Conditional Loop

../_images/100016C80000388C0000388C2CFA711217EA5B06.svg

This conditional loop function is used for multiple execution of functions within the loop as long as the loop condition set at its beginning is met. The termination condition in the loop header is checked before each iteration of the loop. The loop execution is stopped or skipped if the termination condition is false.

Spelled out, the Conditional Loop function reads as follows:

“Repeat the loop and execute the function(s) contained within that loop as long as the loop condition holds true.””

There are two ways to set the parameters for loop checking: a simple mode and as a JavaScript expression.

Configuration - Simple Mode

In the configuration panel, you may choose the simple mode to comfortably set the loop conditions directly via the Graphic User Interface – simply uncheck JavaScript Expression . The following parameters may be set:

../_images/10000201000001FF000001568EF29AE39EE9077E.png
  1. JavaScript Expression – this button is to toggle between the simple mode and JavaScript Expression mode (see section below).

  2. Name – Enter the name of the variable whose value is to be compared or checked in the condition. The variable is on the left side of the comparison condition and must start with a dollar sign $ (such as $FlowRate).

  3. Type – allows you to give a type hint to the variable and thus toggle the controls in the Condition section.

  4. Comparison operator – with the combo box you can conveniently select the comparison operator.

  5. Comparison condition – the value or a variable that the variable from is to be compared with.

Sample Configuration: Simple Mode

The loop condition to be checked against is whether a the variable $Position is smaller than or the same as 25000,31.

Variable Name

Type

Operator

Condition

$Position

Number

25.000,31

The script editor shows the complete mathematical expression:

Figure 1.1.15: Example for a Conditional Loop

The resulting expression effects that the loop will be rerun as long as the value of the variable $Position is smaller than or the same as 25000,31.

Configuration - JavaScript Expression

Whereas the simple mode provides the user with a graphical interface, the JavaScript mode allows to directly insert an JavaScript expression with variable names and mathematical and logical expression.

Figure : Configuration panel for conditional loops – advanced mode

In advanced mode, a JavaScript editor is displayed with syntax highlighting and line numbers. Here you can set the loop condition using JavaScript expressions. As shown in the example above, you can insert rather complex mathematical expressions or multiple variables to set conditions. JavaScript functions like Math.round() can also be used.

Important

You should always insert a Delay function in a loop to prevent the loop from blocking the application interface by consuming 100% processor power. A small delay of 10ms – 100ms is sufficient.

5.2.4. Function Sequence

../_images/10000944000038720000387225245FA0499799FC1.svg

The Function Sequence is used to group functions. This makes navigation in the function tree easier, since the function sequence can be collapsed if necessary. Furthermore, the sequence also eases the copying of function sequences that consist of several functions. If, for example, you want to copy several functions that are executed one after the other, then simply move them into an empty function sequence. Then you can conveniently move or copy the entire sequence and thus reuse it in different places in the program.

Figure 1.1.17: Function sequence configuration

Naming a Function Sequence

A function sequence may be given a name; that name will then be shown in the function tree. This simplifies navigation in particular with larger numbers of function sequences. To do this, simply enter the name by double-clicking the Caption Field (Figure above ).

Add function parameters and return values

You can access variables defined outside the function sequence from within the function sequence. Alternatively, you can also define function parameters and return values. Function parameters are values that are passed to the function when it is called. Return values are values (e.g. results of calculations) that are returned by the function to the calling script. Up to 10 function parameters and up to 10 return values can be defined for each function sequence. The functions in the sequence then only access the function parameters and not the external variables. This improves encapsulation and makes the function more independent of external variables and thus easier to maintain.

You can add function parameters or return values by clicking the Add buttons. Assign meaningful parameter names by clicking the parameter names above the input fields (figure below):

image77

Loading a Function Sequence

The Function Sequence also allows the loading of pre-stored scripts: You may load a script, which you have created and saved previously, into your current function sequence. To do this, just click on the Load from script file button (figure above, ) and select the desired file. The scripts are loaded into the current script. I.e. you can make changes to the loaded function sequence without affecting the external script.

Convert Selection to Function Sequence

To improve the clarity and readability of your script, you can quickly and easily group sequences of functions into function sequences. To do this, simply select a contiguous set of functions, and then click Convert Selection To Function Sequence in the context menu.

Figure : Grouping Functions

The selected functions are now replaced by a function sequence containing the selected functions.

image78

5.2.5. Conditional Sequence

../_images/100010E0000038720000387245E0E2D44AF732BF.svg

The conditional sequence contains a set of script functions that will be executed only if the check condition in the conditional sequence header is true. If the check condition is not true at the time of script execution, then the conditional sequence is simply skipped. In text form, the function execution can be described as follows:

“If the check condition is true, then execute the functions within the sequence.”

The configuration of the conditional sequence is identical to the configuration of the Conditional Loop.

5.2.6. Parallel Sequence

../_images/10000F0500003872000038726C61F7339CE41618.svg

This script function enables the parallel execution of functions or function sequences. The configuration of this script function is identical to the configuration of a normal function sequence. In contrast, however, to a standard function sequence, the individual functions are not executed sequentially but in parallel. In other words, when executing this function, all direct child functions start simultaneously.

If you want to execute complex workflows in parallel, you should combine them in a function sequence. The following figure shows you a parallel sequence in which the three individual processes (function sequences) run in parallel:

Figure 1.1.19: Example of a parallel sequence

The parallel sequence finishes only after all parallel child functions have been completed. Thus, the function is suitable for execution of parallel processes in which it is important to wait for the end of the process that takes the longest before proceeding to the next step.

Tip

Parallel sequences increase complexity and are difficult to debug, which means that it can be difficult to find errors in parallel sequences.

5.2.7. Break

../_images/10000CF40000387200003872240B44CEBEA58C98.svg

This function causes the enclosing function sequence to terminate. This works with all function sequences from the Function Sequences category and with the script itself.

With the Termination Depth parameter you can control up to which level the enclosing function sequences are terminated. With the default value 0, only the sequence containing the break function is terminated. If the value is 1, the sequence that is one level higher is also terminated, and so on.

If, for example, you want to terminate a Function Sequence when a certain condition occurs, insert a Conditional Sequence into the function sequence to check the termination condition and a break function with the termination depth 1 into this conditional sequence. The break function will then terminate the conditional sequence and the function sequence above it if the condition is true.

../_images/1000020100000175000000A03698480BFF00A770.png

Important

If you move or copy the break function, e.g. one level up or to a lower level, you should always check whether the Termination Depth needs to be adjusted.

5.2.8. Return

../_images/return.svg

You can use the return function to return immediately from a script or a Script Function Call to the caller. This function has a similar functionality as the return statement in languages such as JavaScript or C++.

5.3. Error Handling Functions

../_images/error_handling_category.png

The Error Handling category contains functions that you can use to implement proper error handling in your scripts.

5.3.1. Try…Catch

../_images/try_except1.svg

The Try…Catch block is used to catch and handle errors that occur during script execution. This enables similar error handling like known from other programming languages such as JavaScript or Python.


The Try…Catch block is comprised of the following two code blocks:

  • try_block Try

    With the Try statement, you define a code block that is tested for errors during its execution. Here you implement your normal function logic as in any other function sequence.

  • catch_block Catch

    In the Catch Block, you define a code block that is only executed if an error occurs in the Try Block.

It works like this:

  1. First, the code in the Try block is executed.

  2. If there were no errors, then Catch is ignored: the execution reaches the end of Try and goes on, skipping Catch.

  3. If an error occurs, then the Try execution is stopped, and control flows to the beginning of Catch.

../_images/try_catch_flow.png

Important

This means that an error in the Try block does not interrupt the script, parallel sequences continue to run and you have the chance to deal with the error.

If the Catch Block is executed, then the two script variables $ErrorMessage and $ErrorId are available in this block. The $ErrorMessage variable contains the error message generated by the script function that caused the error. The optional $ErrorId variable can contain a unique error id (e.g. ERR_TIMEOUT) that can be used in Catch to handle different errors differently.

In the configuration section of the Try…Catch Block, you can activate (default) or deactivate the Print Error Message To Event Log setting.

../_images/try_catch_print_error.png

If the option is deactivated, the error message is not automatically output in the event log. I.e., if you handle the error in the Catch block and do not want the users of your script to see any error, you can disable the error output here. You can then still output the error in the Catch block using a Show Message function or a Log Message function and access to the $ErrorMessage variable to create your own custom error message. By default, error output is enabled and a warning message is generated in the event log.

The following script shows an example of error handling:

../_images/try_catch_example.png

The Try Block contains a Wait For Device Property function . A timeout has been set for this function in the configuration section of the function. This causes the function to trigger an error with the error ID ERR_TIMEOUT in the case of a timeout.

This error causes the Try block to be stopped immediately and the Catch block to be executed. There is a Conditional Sequence in the Catch block. In its test condition, it is tested whether it is an ERR_TIMEOUT error. The following JavaScript code is used for this purpose:

ErrorIdString = $ErrorId; ErrorIdString.indexOf("ERR_TIMEOUT") == 0;

The content of the $ErrorId is stored in the string object ErrorIdString. Afterwards, the string function indexOf can be used to test whether the error ID begins with "ERR_TIMEOUT". In this case, one could also test with the isequal operator. However, testing for the beginning of the string also enables the detection of a group of errors. If, for example, there were the error codes ERR_PUMP_DOSING and ERR_PUMP_ENABLE, then the test

ErrorIdString = $ErrorId; ErrorIdString.indexOf("ERR_PUMP") == 0;

would recognize both errors and thus all pump errors.

If the timeout error was detected, a custom error message is then output in the next step using the Log Message function.

../_images/try_catch_example_message.png

The user then sees the following error output in the application’s event log:

../_images/try_catch_example_log.png

Tip

If you double-click on a log entry in the Event Log, the function that caused the log entry is opened in the Script Editor and highlighted in color. This way, in the case of an error, you can quickly jump to the function that caused the error. Alternatively, you can also use the menu item Got to Script Function in the context menu of the Event Log (right mouse button).

5.3.2. Throw Error

../_images/throw_error.svg

The Throw Error function allows you to throw an error that interrupts script execution or can be caught in a Try…Catch block. If you want to detect errors in your script or create your own error from a Catch block, you can use this function.

In the configuration area of the function you can set the Error Message and the Error Identifier :

../_images/throw_error_config.png

Tip

In the Error Message field, you can use script variables and device properties (see picture above).

5.4. Time Functions

5.4.1. Time Functions Overview

Figure : List of timing functions

This category contains functions to enable a time-controlled program flow. The execution of scripts may be suspended for a certain amount of time or can be interrupted to wait for certain timer events.

5.4.2. Delay

../_images/100007700000350500003505BC110D46A028D1D8.svg

The Delay function interrupts program execution for a configurable length of time. You can set the delay time (hours, minutes, seconds, or milliseconds) in the configuration area (see figure below).

Figure : Configuration of Delay function

All input fields support the use of variables. You can freely and flexibly assign any values to the input fields and you can freely mix variables and values with each other.

Sample Configuration

If you e.g. would like to set a delay of 10 minutes and 15 seconds, you can do so by very different assignments of the input fields:

Hours

Minutes

Seconds

Milliseconds

0

10

15

0

0

0

615

0

0

0

0

615000

0

10

0

15000

5.4.3. Wait Until

../_images/1000087800003505000035058C9536180430C275.svg

You can delay program execution until a precisely defined date and time with the Wait until function. Program execution is not resumed until the configured date and time has been reached.

Important

Please note that the Wait until function can only be correctly executed once. If the script is executed again, and the time point thus lies in the past, this function will simply be ignored. In other words, date and time of a Wait until function must be re-configured before restarting a script so that an effective delay can again be executed.

5.4.4. Start Timer

../_images/1000095E0000350500003505163F47DDE33790B9.svg

This function starts a millisecond timer which can be waited for with the Wait for Timer function (see below) or whose current millisecond value can be read with the Read Timer function. For configuration, assign a unique name for the timer Timer Name.

If this function is called with the name of a timer that has already been started, this timer is restarted with the configured time span.

Tip

If you want to measure the execution time for a particular process or sequence of functions in your script, simply start a timer before the sequence and read the milliseconds after the sequence with the Read Timer function.

5.4.5. Wait for Timer

../_images/10000D500000350500003505855C71628C55D85A.svg

This function interrupts the further program execution until the Timer Running Time configured in this function has elapsed for the selected timer. A timer with the configured timer name must have been started before via the function Start Timer. If the timer has already expired when this function is called, the program execution continues without interruption.

With the two above functions, Start Timer and Wait for Timer , it is very easy to execute functions at fixed intervals. For this, you can, for example, run a function or function sequence along a timer function in a Parallel Sequence.

5.4.6. Read Timer

../_images/10000B8100003505000035056090D1DE9D69C3F8.svg

With this function you can read out the current millisecond value of a particular timer and store it in a variable. You can then use the Show Message function to display this variable value. This allows you to measure and display the times of program sequences in your script, for example.

5.5. Device Functions

5.5.1. Introduction to Device Functions

../_images/device_functions_category.png

The script system comes with a number of generic script functions for accessing devices (device process data, device properties). These functions are available independently of the loaded plugins. You find these generic device functions in the category Device Functions.

5.5.2. Read Device Property

../_images/10002597000034EB000034EB8C1E4F7964CA4032.svg

This function allows you to read process data from a device and save it to a variable.

Select the device you want to access from the drop-down list Device , which lists all devices that are part of the current configuration. To simplify the search for a device, you can filter the device list by selecting an appropriate filter (device type) from the Filter drop-down field . After the device has been selected, use the last drop-down list Property to select the device property that you want to access.

Important

Only devices and device properties are displayed that allow read access.

In the input field Variable , enter the name of the variable into which the value is to be saved during script runtime (figure below).

Figure : Reading device property set-up panel

In abbreviated form, the set-up follows the following logic:

Read from device the value of parameter and save it into variable .

Tip

When entering a name, the auto-complete feature will provide you with a selection of all previously defined variable names.

5.5.3. Write Device Property

../_images/100024C0000034EB000034EBCD08BD4563B1D7D1.svg

This function is for writing process data from devices. In the input field enter the value to be written. You can also use variables or Device Property Identifiers in this field.

In the configuration panel (figure below), select the device and the appropriate device property that you want to write as described for function Read Device Property. The device selection controls only show devices and device properties, which allow write access.

Figure : Scriptconfiguration Write Device Property

The value in the input field is then written at run time in the selected device property.

5.5.4. Wait For Device Property

../_images/10002565000034EB000034EB5C19DADB200F9112.svg

This function allows a script to wait for a specific device property to reach a predefined condition. Once this condition is fulfilled, the script will resume. In the configuration panel (figure below), select the device and the appropriate device property that you want to monitor as described for function Read Device Property.

../_images/wait_for_device_property_function.png

In the Condition section you can configure the condition that is to be checked against. First define an operator and then the target value the device parameter is to be compared with. In the value field , you can also use Script Variables (e.g. $FlowRate) or Device Properties (e.G. Nemesys_M_1.ActualFlow) to set a test condition.

To prevent the function from blocking further execution for too long, you can set a time limit in the Timeout (ms) field. If the time limit has expired and the test condition is not yet true, the function generates an ERR_TIMEOUT error. To deactivate the timeout, simply set the value to 0.

In short, the function can be described as follows:

Continue script execution, if the selected property of the device meets the condition .

Tip

Script Variables (such as $Value) can be used as test / comparison condition.

Tip

A timeout value of 0 deactivates the time limit.

5.5.5. Create Property Variable

../_images/10001162000038720000387269894D0D5041B1EE.svg

Use this function to create a special variable that is associated with a certain property of a certain device. Via this variable you can directly access the assigned device property from within a script, without any additional function calls.

If you e.g. want to read an analog input value using normal variables, you first need to create a variable via Create Variable function and then use the Read Device Property function to store the analog input value into this variable. Only then you can use this variable for further calculations and tests in script functions. Whenever you need a new analog input value, you must call the Read Device Property function again.

Figure : Create Property Variable configuration panel

With property variables that access to device properties (e.g. analog input value) is considerably simplified. If you create a property variable, you use the configuration panel to connect a device property permanently with a variable. Whenever you read the value of this variable from within a script function, automatically the current value of the connected device property is read.

You can set the name of the variable in the input box Variable (figure above). Select the device you want to access from the drop-down list Device , which lists all devices that are part of the current configuration. To simplify the search for a device, you can filter the device list by selecting an appropriate filter (device type) from the Filter drop-down field .

After the device has been selected, use the last drop-down list Property to select the device property, the process data value that you want to access.

In summary, this function can be described as follows:

“Assign the device property of the device to the variable and return the device property value if a read access on the variable takes place.”

Important

Property variables can not be used to store values during calculations— use normal variables for calculations and value storage.

5.6. Logging

The Logging category contains script functions for controlling various log functions and accessing the event log.

../_images/logging_category.png

5.6.1. Log Message

../_images/log_message2.svg

With this function you can output a message in the Event Log of the application. In the configuration area of the function you can configure the following:

../_images/log_message_config.png
  1. Enter your message text in the Message field.

  2. Select the type of message you want to display in the Message Type group. Depending on the message type, the relevant icon appears in the event log and the message is highlighted with a type-specific color.

You can use Device Properties and Script Variables in the text. These serve as placeholders and are replaced by the content of the variables or the process data of a device at runtime of the script. As soon as you enter a dollar sign $ in the text, a list of available variables is displayed from which you can select a variable.

../_images/log_message_text_input.png

In the figure above, the script variable $TargetVolume and the device property $$Nemesys_S_1.DosedVolume have been inserted. When executed, the message is output in the event log of the application:

../_images/log_message_output.png

Tip

Device properties can be conveniently inserted via the context menu of the Message field (right-click with the mouse).

If you select the message type Debug / Trace, the message is only output when the debug mode is active. This way you can activate additional log output for debugging your scripts that do not appear when the script is executed normally.

5.6.2. Clear Event Log

../_images/clear_event_log.svg

This script function deletes all entries from the event log window of the application.



5.6.3. Export Event Log

../_images/export_event_log.svg

The export function exports the contents of the Event Log window to a text file. Click on the folder icon in the configuration area (see figure below) to select a file name and location. We recommend that you keep the location in the Log folder of the current project.

image111

The function saves the exported file with a timestamp, e.g. EventLog_20220121_161653.txt.

5.7. Data Storage

This category contains functions for reading data from files and for storing data persistently.

../_images/data_storage_category.png

5.7.1. Open Settings File

../_images/open_settings_file.svg

This function opens a settings file *.ini for reading / writing data persistently. An *.ini file is a structured data file that consists of sections and keys. The name of a section in the *.ini file is always entered inside square brackets. The name of a key is always on a separate line and the content is assigned by the = char. The following example shows a typical *.ini file:

[SyringeConfig]
Length=60
Volume=1000
Caption=CustomGlass

[Variables]
Flow=100
Caption=Water

The file has two sections (SyringeConfig and Variables) and each section contains a number of key-value pairs.

To open a settings file or to create a new one, you need to provide a filename and a script variable to store the created settings file object.

../_images/open_settings_config.png

In the input field for the file name , you have various options for entering a file name:

Selection via file dialog:

Click on the file folder icon and select the target directory as well as the file name and file type.

Enter an absolute file path:

Enter an absolute file path, e.g. C:tempMySettings.ini, using the keyboard.

Entering a relative file path

Enter a relative file path, e.g. .DataMySettings.ini using the keyboard. In this case, the MySettings.ini file is saved in the current project directory in the Data subfolder. If the current project for example folder is C:/Users/Public/Documents/QmixElements/Projects/Nemesys, then the following file would be created: C:/Users/Public/Documents/QmixElements/Projects/Nemesys/Data/MySettings.ini

Using a script variable

You can save an absolute or relative file path in a script variable and then use this variable in the input field.

If the file exists, it will be opened. If it does not exist yet, it will be created. You can now use the variable in the Read Setting and Write Setting functions to provide a valid and properly initialized settings object.

5.7.2. Read Setting

../_images/settings_read.svg

This function reads a single value from settings file. If the setting doesn’t exist, the function returns the given optional Default Value. If the settings doesn’t exist and no default value is given, the function raises and error.

If you would like to read the syringe length from the following settings file:

1[SyringeConfig]
2Length=60
3Volume=1000
4Caption=CustomGlass

then you would use the following parameters:

../_images/read_setting_config.png

In the Settings Object Variable you provide a variable with a valid settings object created with Open Settings File function. Then you need to provide the Settings Group SyingeConfig and the Key Length . The function now reads the value 60 from the file and stores it into the given script variable $SyringeLength.

5.7.3. Write Setting

../_images/settings_write.svg

This function writes a single value into a settings file. If the key given in Key field already exists, the previous value is overwritten. To use this function, you need to open or create a settings file before using the function Open Settings File.

In the following example, the syringe volume 1000 shall be stored into the settings file:

../_images/write_setting_config.png

In the Settings Object Variable you provide a variable with a valid settings object created with Open Settings File function. Then you need to provide an optional Settings Group and the Key . In the Value field you provide the value or a script variable containing the value.

The provided parameters will write the syringe volume into line 3 of the settings file:

1[SyringeConfig]
2Length=60
3Volume=1000
4Caption=CustomGlass