Declaring programs

Below are the main services to declaring programs.

Declaration:

paCreateProgram - Create a main program
paCreateSubProgram - Create a sub-program
paCreateUDFB - Create User Defined Function Block
paCreateSfcChildProgram - Create a child SFC program
paCopyProgram - Duplicate a program
paSetProgramComment - Set the desrciption text of a program

Working with existing programs:

paEnumProgram - Enumerate programs
paGetProgramDesc - Get information about a program
paDeleteProgram - Remove a program

Arranging programs in folders:

paCreateProgramFolder - Create a new folder
paSendProgramToFolder - Put a program in a folder
paEnumProgramFolder - Enumerate program folders
paDeleteProgramFolder - Remove a folder

Below are details about these functions:

paCreateProgram - Create a main program

OK := paCreateProgram (NAME, LANGUAGE)

Parameters:

NAME : STRING; Name of the new program
LANGUAGE : STRING; Programming language (see notes)
OK : BOOL; True if successful

Description:

This function creates a main program in the target project. Main programs are arranged in the cycle in the same order you create them from your script.

The following values are predefined for the "LANGUAGE" parameter:

_LG_SFC Sequential Function Chart
_LG_FBD Function Block Diagram
_LG_LD Ladder Diagram
_LG_ST Structured Text
_LG_IL Instruction List

Example:

    // create a new program folder
    paCreateProgramFolder ('Folder1') then
    // create a new program in LD language
    if paCreateProgram ('Prog1', _LG_LD) then
        // and put it in the folder
        paSendProgramToFolder ('Prog1', 'Folder1');
    end_if;

other functions

paCreateSubProgram - Create a sub-program

OK := paCreateSubProgram (NAME, LANGUAGE)

Parameters:

NAME : STRING; Name of the new program
LANGUAGE : STRING; Programming language (see notes)
OK : BOOL; True if successful

Description:

This function creates a sub-program in the target project.

The following values are predefined for the "LANGUAGE" parameter:

_LG_FBD Function Block Diagram
_LG_LD Ladder Diagram
_LG_ST Structured Text
_LG_IL Instruction List

Example:

    // create a new program folder
    paCreateProgramFolder ('SubPrograms') then
    // create a new sub-program in LD language
    if paCreateSubProgram ('SP1', _LG_LD) then
        // and put it in the folder
        paSendProgramToFolder ('SP1', 'SubPrograms');
    end_if;

other functions

paCreateUDFB - Create a User Defined Function Block

OK := paCreateUDFB (NAME, LANGUAGE)

Parameters:

NAME : STRING; Name of the new function block
LANGUAGE : STRING; Programming language (see notes)
OK : BOOL; True if successful

Description:

This function creates a User Defined Function Block in the target project.

The following values are predefined for the "LANGUAGE" parameter:

_LG_FBD Function Block Diagram
_LG_LD Ladder Diagram
_LG_ST Structured Text
_LG_IL Instruction List

Example:

    // create a new program folder
    paCreateProgramFolder ('UDFBs') then
    // create a new sub-UDFB in LD language
    if paCreateUDFB ('FB1', _LG_LD) then
        // and put it in the folder
        paSendProgramToFolder ('F1', 'UDFBs');
    end_if;

other functions

paCreateSfcChildProgram - Create a child SFC program

OK := paCreateUDFB (NAME, PARENT)

Parameters:

NAME : STRING; Name of the new child program
PARENT : STRING; Name of the parent program
OK : BOOL; True if successful

Description:

This function creates a new SFC program to be a child of the specified parent SFC program. The parent SFC program must exist before calling this function.

Example:

    // create the parent program
    paCreateProgram ('MAIN', _LG_SFC);
    // create the child program
    paCreateSfcChildProgram ('Child1', 'MAIN');

other functions

paCopyProgram - Duplicate a program

OK := paCopyProgram (SRC, DST)

Parameters:

SRC : STRING; Name of the source program
DST : STRING; Destination program
OK : BOOL; True if successful

Description:

This function duplicates the "SRC" programin the "DST" program. This function creates the "DST" program and is normally not used for overwriting an existing program.

other functions

paSetProgramComment - Set the description a program

OK := paSetProgramComment (NAME, COMM)

Parameters:

NAME : STRING; Name of the program
COMM : STRING; Description text
OK : BOOL; True if successful

Description:

This function sets the comment text of a program. It may be used for either programs or sub-programs or User Defined Function Blocks (UDFBs).

Example:

    // create the program
    paCreateProgram ('PROG1', _LG_ST);
    // and sets its description text
    paSetProgramComment ('PROG1', 'This is PROG1 description');

other functions

paEnumProgram - Enumerate programs of the target project

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

Input parameters:

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

Ouputs:

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

Description:

This function block is used for enumerating the programs, sucb-programs and UDFBs of the target project. You must first call it with LOAD input at TRUE in order to load the list of programs. 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 program 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 can specify a filtering string that may include some '*' or '?' wildchars.

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 programs. After the box is closed, only checked items remain in the loaded list.

Example:

    // "ENU" is a declared instance of paEnumProgram function block
    // load all programs
    ENU (TRUE, FALSE, 0, '*');
    // 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"
        sProgName := ENU.Q;
    end_for;

other functions

paGetProgramDesc - Get information about a program

function block: Inst_paGetProgramDesc (NAME)

Input parameters:

NAME : STRING; Name of the program

Ouputs:

OK : BOOL; TRUE if successful
KIND : STRING; Kind of POU
LANGUAGE : STRING; Programming language
PARENT : STRING; Parent SFC program or empty string
COMMENT : STRING; Description text

Description:

This function block is for getting information about a program of the target project. It can be used for programs, sub-programs or UDFBs.

The following values are predefined for the "LANGUAGE" output:

_LG_SFC Sequential Function Chart
_LG_FBD Function Block Diagram
_LG_LD Ladder Diagram
_LG_ST Structured Text
_LG_IL Instruction List

The following values are predefined for the "KIND" output:

_POU_MAIN Main program
_POU_SP Sub-program
_POU_UDFB User Defined Function Block
_POU_CHILDOF Child SFC program (the name of its parent program is in the PARENT output)

other functions

paDeleteProgram - Delete a program

OK := paDeleteProgram (NAME)

Parameters:

NAME : STRING; Name of the program (see notes)
OK : BOOL; True if successful

Description:

This function deletes the specified program. It can be used for programs, sub-programs of UDFBS. The "NAME" parameter can contain '?' and '*' wildchars. For instance, paDeleteProgram ('*')  deletes all the POUs of the target project. If the specified program is a SFC program having child programs, its children are deleted as well.

other functions

paCreateProgramFolder - Create a folder of programs

OK := paCreateProgramFolder (NAME)

Parameters:

NAME : STRING; Name of the folder
OK : BOOL; True if successful

Description:

This function creates a new folder in the "Programs" tab of the target project workspace.

Warning: This function supports only one level of program folders and cannot be used for nested folders.

Example:

    // create a new program folder
    paCreateProgramFolder ('Folder1') then
    // create a new program in LD language
    if paCreateProgram ('Prog1', _LG_LD) then
        // and put it in the folder
        paSendProgramToFolder ('Prog1', 'Folder1');
    end_if;

other functions

paSendProgramToFolder - Move a  program to a folder in the workspace

OK := paSendProgramToFolder (NAME)

Parameters:

PROG : STRING; Program name
FOLDER : STRING; Destination folder
OK : BOOL; True if successful

Description:

This function moves the specified program under the specified folder in the "Programs" tab of the target project workspace. The destination folder must exist before this function is called.

Warning: This function supports only one level of program folders and cannot be used for nested folders.

Example:

    // create a new program folder
    paCreateProgramFolder ('Folder1') then
    // create a new program in LD language
    if paCreateProgram ('Prog1', _LG_LD) then
        // and put it in the folder
        paSendProgramToFolder ('Prog1', 'Folder1');
    end_if;

other functions

paEnumProgramFolder - Enumerate program folders or the target project

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

Input parameters:

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

Ouputs:

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

Description:

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

Warning: This function supports only one level of program folders and cannot be used for nested folders.

When loading folderss (LOAD inputs is TRUE), you can specify a filtering string that may include some '*' or '?' wildchars.

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 folders. After the box is closed, only checked items remain in the loaded list.

Example:

    // "ENU" is a declared instance of paEnumProgramFolder function block
    // load all folders
    ENU (TRUE, FALSE, 0, '*');
    // 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"
        sFolderName := ENU.Q;
    end_for;

other functions

paDeleteProgramFolder - Delete a program folder

OK := paDeleteProgramFolder (NAME)

Parameters:

NAME : STRING; Name of the folder
OK : BOOL; True if successful

Description:

This function deletes the specified folder. The "NAME" parameter can contain '?' and '*' wildchars. For instance, calling paDeleteProgramFolder ('*')  deletes all the folders of the target project.

Warning: This function supports only one level of program folders and cannot be used for nested folders.

other functions