Macros

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Macros

mapp Services V5.16

Show advanced parameter

Name



Macros




Actions





Action {/Identifier}






Identifier






Code







Line 1-N






Arguments







Argument 1-N




Conditions





Condition {/Identifier}






Identifier






Code







Line 1-N






Arguments







Argument 1-N




Actions and conditions can be defined in section "Macros". For general information, see section Macros.

Actions can be used as coils in the LadderEditor.

Conditions can be used as contacts in the LadderEditor.

If a certain condition is met, then an action can be carried out.

"Identifier" allows a condition or action to be uniquely identified in the program. The name of the "identifier" can also be specified as localized via the text system. See "Specifying texts as localized via the text system" in section General settings.

Process variables with the following data types cannot be used:

Directly derived data types

Arrays that do not start with 0

Arrays of structures

Multidimensional arrays

Arrays with more than 65535 elements

Line

"Line" specifies a program line or program that should be executed when the action/condition is enabled. A few rules must be followed.

When assigning variables or specifying process variables, etc., care must be taken when using spaces (marked in red in the picture)! Otherwise, the specified code will not be interpreted correctly.

whitespace_usage

ST programming

It is possible to use all operators, statements and keywords that are available in the ST editor. Character ";" must be added after each program line.

No functions or function blocks from libraries can be called, for example function MpAlarmXCheckState or CfgSetIPAddr.

This looks something like this for an IF statement in the configuration:

how_to_st_if

Accessing process variables

PVs from the controller can be specified directly; they must also be specified in section PV access for this.

Process variables must be specified in "Line" as follows:

Global variables: PVName

Local variables: $TaskName:PVName

Local variables:

Character ":" is used when accessing local variables. In order for this to be interpreted correctly, character "$" must be used in front of the task name. ";" must be entered after each program line. To prevent ";" from being added to the variable name when the PV is specified, an additional "$" character must be appended to the end of the PV specification. It thus looks like this: "$TaskName:PVName$;"

Example from the configuration:

configuration_variablenzuweisung

This accesses variable "Input2" and task "CodeBox".

Global variable

Character "$" is not used when specifying global variables. The name of the variable can be entered directly. Example from the configuration:

global_var_access

mapp keyword "#R"

"#R" is used to determine the state of a contact. A condition is thus assigned to result "#R". If a condition is created, this keyword must be used under "Line". It can look like this, for example:

condition_example_r

Variable "Input1" is assigned to #R in this example. This allows the variables to be used as a contact in the ladder editor.

mapp keyword "#IN"

"#IN" defines the input state of a coil. "#IN" is thus assigned to an action. The keyword must be used inside an action. It can look like this, for example:

condition_example_in

In this example, #IN is assigned to output variable "Output2". In this way, variable "Output2" can be used as a coil in the ladder editor.

mapp keyword "#ARG"

A previously defined argument can be specified using "#ARGn", where n stands for the index of the argument. The argument must first have been created in section Arguments. It must then be specified for the condition or action under "Arguments" in order for it to be used under "Line". This could look like this in the configuration:

arguments

Argument "Position" was specified under "ARG1". A numerical argument type was used for this. It is therefore the first argument. In order to access the argument under "Line", "ARGn" ("ARG1" in this example) must be used.

Using an index argument:

If an argument of type "Index" is added in section Arguments, it can be used as follows, for example:

index_arg_config

Condition "TestIndexARG" is created in the example. Array variable "MyArray" of type BOOL was created in program "Data". Which index of variable "MyArray" is accessed is defined using index argument "IndexARG".

If the condition in LadderEditor is added, then a dialog box appears to select the index that should be accessed:

set_index_arg_editor

mapp keyword "#SB"

If keyword "#SB" is used, then it is possible to access the sandbox variable/structure specified in the MpCodeBoxCore configuration. This looks something like this in the configuration:

configuraiton_sanbox_variable

Declaring variables

It is also possible to declare variables in "Line". This works as follows:

VAR {Scope}

VarName : BOOL := FALSE;

END_VAR

The following values can be used for the {scope}:

{}: If no scope is specified, then the variable is valid only within the macro.

{LOCAL}: With "LOCAL", the variable is only valid/visible within the program in which the macro is called.

{GLOBAL}: With "GLOBAL", the variable is valid/visible within the entire MpCodeBoxCore instance.

{SHARED}: With "SHARED", the variable is valid/visible within all MpCodeBoxCore instances.

The first parameter "VarName" defines the name of the variable. "BOOL" specifies the IEC data type. All IEC data types can be used. An array is specified with "ARRAY[0..n] OF BOOL". At the end, the variable can be assigned an initial value. In the example above, the initial value is "TRUE". Example of an initialization for an array:

VAR {Scope}

testArray: ARRAY[0..9] OF SINT:= [0,2,45,2,8,7,26,74,88,52];

END_VAR

It is not possible to create a structure.

This can be specified in the configuration as follows, for example:

add_variable_config

Examples

This section lists different examples for macros.

Enabling a machine command

This example illustrates how to enable a machine command. The goal is to issue the command for heating if a certain temperature value is reached.

Macros:

Condition "TempLimit" and action "SetHeater" are created. As soon as variable "TempReached" = TRUE, variable "HeaterOn" should become TRUE.

set_command_config

Ladder editor:

The program looks like this in the ladder editor:

set_command_browser

Requesting a state

This example explains how to request a state. Various values can be set depending on the result. The goal is to set the value of a variable based on whether the action is active.

Macros:

Condition "Temperature" and action "SetTempLimit" are created.

If the input value of action "SetTempLimit" is TRUE, a value should be assigned to variable "TempZone1". If the input value of the action is FALSE, the value is assigned to variable "TempZone2".

set_temp_config

Ladder editor:

The program looks like this in the ladder editor:

set_temp_browser