Declaring variables

Below are the main services to declaring variables.

Declaration:

paCreateVar - Create a variable
paCreateInputParam - Create an input parameter of a sub-program or UDFB
paCreateOutputParam - Create an output parameter of a sub-program or UDFB
paSetVarXDim(s) - Set dimension(s) of a variable
paSetVarInitValue - Set initial value of a variable
paSetVarComment - Set description text of a variable
paEmbedVarSymbol - Embed the symbol of a variable
paProfileVar - Set variable profile and properties

Working with existing variables:

paEnumVar - Enumerate variables
paGetVarDesc - Get information about a variable
paDeleteVar - Delete a variable

Naming conventions

In any function where you need to specify a variable by its name, you must specify the group containing the variable. A variable can be Global or I/O, Retain, Local to a POU or can be an item of a data structure.

The convention for these functions is to prefix the variable name by its group name and the '.' separator. If no group is specified, then the variable is considered as Golbal. Below are some examples:

VarName a global variable
RETAIN.VarName a RETAIN variable
%IX1.0 a global I/O channel
ProgName.LocVarName a variable local to a program
UDFBName.ParamName a parameter of a UDFB
StructName.Item an item of a data structure
   
paCreateVar - Create a variable

OK := paCreateVar (SNAME, STYPE)

Parameters:

SNAME : STRING; Name of the new variable and speficication of ots group (see naming conventions)
STYPE : STRING; Data type
OK : BOOL; True if successful

Description:

This function creates a program with the specified name in the specified group. The STYPE indicates its data type. It can be a type of function block for declaring an instance. In case of a STRING type, the type must be followed by the string length. e.g. 'STRING(255)'

The same function can be used to create an item in a data structure.

Example:

    // create global variable and FB instance
    paCreateVar ('Global1', 'BOOL');
    paCreateVar ('Timer1', 'TON');
    // create a retain variable
    paCreateVar ('RETAIN.RetVar1', 'STRING(20)');
    // create a variable local to a program
    paCreateVar ('Prog1.Local1', 'DINT');
    // create an item of a structure
    paCreateVar ('Struct1.Item1', 'REAL');

other functions

paCreateInputParam - Create an input parameter of a POU

OK := paCreateInputParam (SNAME, STYPE)

Parameters:

SNAME : STRING; Name of the new variable in form 'POUName.VarName' (see naming conventions)
STYPE : STRING; Data type
OK : BOOL; True if successful

Description:

This function creates an input parameter for the POU (sub-program or UDFB) specified as a prefix in the variable nameThe STYPE indicates its data type. In case of a STRING type, the type must be followed by the string length. e.g. 'STRING(255)'

Example:

    // create a sub program
    paCreateSubProgram ('SP', _LG_LD);
    // declare parameters
    paCreateInputParam ('SP.IN1', 'BOOL');
    paCreateInputParam ('SP.IN2', 'DINT');
    paCreateOutputParam ('SP.Q', 'BOOL');

other functions

paCreateOutputParam - Create an output parameter of a POU

OK := paCreateOutputParam (SNAME, STYPE)

Parameters:

SNAME : STRING; Name of the new variable in form 'POUName.VarName' (see naming conventions)
STYPE : STRING; Data type
OK : BOOL; True if successful

Description:

This function creates an output parameter for the POU (sub-program or UDFB) specified as a prefix in the variable nameThe STYPE indicates its data type. In case of a STRING type, the type must be followed by the string length. e.g. 'STRING(255)'

Example:

    // create a sub program
    paCreateSubProgram ('SP', _LG_LD);
    // declare parameters
    paCreateInputParam ('SP.IN1', 'BOOL');
    paCreateInputParam ('SP.IN2', 'DINT');
    paCreateOutputParam ('SP.Q', 'BOOL');

other functions

paSetVar1Dim / paSetVar2Dims / paSetVar3Dims - Set the demiension(s) of a variable (array)

OK := paSetVar1Dim (NAME, DIM) // 1 dimension array
OK := paSetVar2Dims (NAME, DIMHIGH, DIMLOW) // 2 dimension array
OK := paSetVar3Dims (NAME, DIMHIGH, DIMMEDIUM, DIMLOW) // 3 dimension array

Parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)
DIMxxx : DINT; Dimension(s) of the array
OK : BOOL; True if successful

Description:

This function sets the dimension of a declared variable, in order to declare an array. The same function can be used for an item in a data structure.

Example:

    // declare Array1 : array [0..9] of BOOL
    paCreateVar ('Array1', 'BOOL');
    paSetVar1Dim ('Array1', 10);
    // declare Array2 : array [0..9,0..4] of BOOL
    paCreateVar ('Array2', 'BOOL');
    paSetVar2Dims ('Array2', 10, 5);
    // declare Array2 : array [0..9,0..4,0..19] of BOOL
    paCreateVar ('Array3', 'BOOL');
    paSetVar3Dims ('Array3', 10, 5, 20);

other functions

paSetVarInitValue - Set the initial value of a variable

OK := paSetVarInitValue (NAME, VALUE)

Parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)
VALUE : STRING; Initial value in IEC 61131-3 syntax
OK : BOOL; True if successful

Description:

This function sets the initial value of a declared variable. The same function can be used for an item in a data structure.

Example:

    // declare Integer1 : DINT := 1234;
    paCreateVar ('Integer1', 'BOOL');
    paSetVarInitValue ('Integer1', '1234');
    // declare Array1 : array [0..3] of BOOL := 1, 2, 3, 4;
    paCreateVar ('Array1', 'BOOL');
    paSetVarDim ('Array1', 4);
    paSetVarInitValue ('Integer1', '1,2,3,4');

other functions

paSetVarComment - Set the description a variable

OK := paSetVarComment (NAME, COMM, TAG)

Parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)
COMM : STRING; Description text
TAG : STRING; Short description text
OK : BOOL; True if successful

Description:

This function sets the comment text of a declared variable. The same function can be for an item in a data structure.

other functions

paEmbedVarSymbol - Embed the symbol of a variable

OK := paEmbedVarSymbol (NAME, SYB)

Parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)
SYB : BOOL; TRUE if the variable symbol must be embedded
OK : BOOL; True if successful

Description:

This function specifies if the symbol of a declared variable must be embedded. The same function can be for an item in a data structure.

other functions

paProfileVar - Defines the profile and embedded properties of a variable

OK := paProfileVar (PROFILE, PROPERTIES)

Parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)
PROFILE : STRING; Name of the profile
PROPERTIES : STRING; Embedded properties attached to the profile (if any)
OK : BOOL; True if successful

Description:

This function specifies the profile and the corresponding embedded properties for a declared variable. Properties are written in form:

    prop=value,prop=value,...

Example:

    // declare the variable
    paCreateVar ('F1', 'BOOL');
    paProfileVar ('K1', '1234');
    // declare Array1 : array [0..3] of BOOL := 1, 2, 3, 4;
    paCreateVar ('Array1', 'FKey', 'Key=1');

other functions

paEnumVar - Enumerate variables of a group in the target project

function block: Inst_paEnumVar (LOAD, CHECK, ITEM, FILTER)

Input parameters:

LOAD : TRUE; If TRUE, load the list of variables
CHECK : BOOL; If TRUE, open a checklist box to select some of the loaded variables
ITEM : DINT; Index of the item wanted on input (1 based)
FILTER : STRING; Group specification and filtering mask for loading variables

Ouputs:

NB : DINT; Number of variables
Q : STRING; Name of the item selected with "ITEM"

Description:

This function block is used for enumerating the variables of a group in the target project. You must first call it with LOAD input at TRUE in order to load the list of variables. You get the number of programs in the NB output. Then call it again with LOAD at FALSE and specifying the index of the wished variable in the ITEM input to get the name of the selected item in the Q output. The numbering of items starts at 1.

When loading programs (LOAD inputs is TRUE), you must specify the group in the FILTER parameter, possibly followed by the '.' separator and a filtering string including some '*' or '?' wildchars. No group name is required for global variables.

After loading, if can call again the block with the CHECK input at TRUE for opening a dialog box where the user can check wished variables. After the box is closed, only checked items remain in the loaded list.

Example:

    // "ENU" is a declared instance of paEnumVar function block
    // load all RETAIN variables
    ENU (TRUE, FALSE, 0, 'RETAIN.*');
    // open a dialog box for the user to check wished items
    ENU (FALSE, TRUE, FALSE, 0, '');
    // enumerate checked items
    for i := 1 to ENU.NB do
        // select the item "i"
        ENU (FALSE, FALSE, i, '');
        // get the name of the item specified by "i"
        sVarName := ENU.Q;
    end_for;

other functions

paGetVarDesc - Get information about a variable

function block: Inst_paGetVarDesc (NAME)

Input parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)

Ouputs:

OK : BOOL; TRUE if successful
INPARAM : BOOL; TRUE if it is an input parameter
OUTPARAM : BOOL; TRUE if it is an output parameter
DATATYPE : STRING; Data type
DIMTOTAL : DINT; Total number of items for an array
DIMHIGH : DINT; Highest dimension (0 for 1 or 2 dimension arrays)
DIMMEDIUM : DINT; Medium dimension (0 for 1 dimension arrays)
DIMLOW : DINT; Lowest dimension
INIT : STRING; Initial value in IEC syntax
SYB : BOOL; TRUE if the symbol of the variable is embedded
PROFILE : STRING; Name of the attached profile
PROPS : STRING; Embedded properties attached to the profile
COMMENT : STRING; Description text
TAG : STRING; Short description text

Description:

This function block is for getting information about a declared variable. The same block can be used for an item in a data structure.

other functions

paDeleteVar - Delete a variable

OK := paDeleteVar (NAME)

Parameters:

NAME : STRING; Name of the variable and speficication of ots group (see naming conventions)
OK : BOOL; True if successful

Description:

This function deletes the specified variable. The same function can be used for an item in a data structure.

The name of the variable may contain '?' and '*' wildchars, but the group name cannot. For instance, paDeleteVar ('RETAIN.*')  deletes all the retain variables.

other functions