FBD - sequential file writing services

The functions below enable you to write sequentially (from the top to the bottom) the source code of a program written in FBD language. Is has limited features (it is not possible to link 2 blocks together) but provides a very easy way to generate FBD as you do not need to care with the position of the elements in the diagram. Files are open using the paFileOpenWriteSrc function. When complete, they must be closed by calling the paFileClose function.

Use the following functions for inserting objects sequentially:

paFbdsBreak - insert a network break
paFbdsComment - insert a multiline comment block
paFbdsLabel - insert a label
paFbdsJump - Insert a unconditional jump
paFbdsReturn - Insert a unconditional <RETURN> statement
paFbdsBlock - Insert a block

Just after inserting a block, you then can define its inputs and outputs:

paFbdsInputVar - Connect a variable on input of the last block
paFbdsOutputVar - Connect a variable on output of the last block
paFbdsOutputJump - Connect a jump statement on output of the last block
paFbdsOutputReturn - Connect a <RETURN> statemenrt on output of the last block

See an example...

Below are detailed information about these functions:

paFbdsBreak - add a network break

OK := paFbdsBreak (FID, TEXT)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
TEXT : STRING; Text written on the network break
OK : BOOL; True if successful

Description:

This function adds a network break under the last added item in a FBD source file open for writing.

other functions

paFbdsComment - add a comment block

OK := paFbdsComment (FID, TEXT, HEIGHT)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
TEXT : STRING; Comment text
HEIGHT ; DINT; Height of the comment block (in diagram grid unit)
OK : BOOL; True if successful

Description:

This function adds a multiline comment block under the last added item in a FBD source file open for writing. You can use the '$N' sequence in the comment text to specify an end of line.

other functions

paFbdsLabel - add a label

OK := paFbdsLabel (FID, LABEL)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
LABEL : STRING; Label name
OK : BOOL; True if successful

Description:

This function adds a label under the last added item in a FBD source file open for writing. The label is placed on the left side of the diagram.

other functions

paFbdsJump - add a unconditional jump

OK := paFbdsLabel (FID, LABEL)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
LABEL : STRING; Target label name
OK : BOOL; True if successful

Description:

This function adds a jump instruction under the last added item in a FBD source file open for writing. It is an unconditional jump instruction. The jump symbol is placed on the left side of the diagram, connected to a LD left power rail (always true):

other functions

paFbdsReturn - add a unconditional <return> symbol

OK := paFbdsReturn (FID)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
OK : BOOL; True if successful

Description:

This function adds a <RETURN> jump instruction under the last added item in a FBD source file open for writing. It is an unconditional instruction. The jump symbol is placed on the left side of the diagram, connected to a LD left power rail (always true):

other functions

paFbdsBlock - add a block

OK := paFbdsBlock (FID, NAME, INSTANCE)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
NAME : STRING; Block name
INSTANCE : STRING; Instance name in case of a function block
OK : BOOL; True if successful

Description:

This function adds a block symbol under the last added item in a FBD source file open for writing. It can be a basic operator, a function or a function block. The name of the instance must be specified in case of a function block.

Immediately after calling this function, use the FbdsInput... and FbdsOutput... functions in order to connect the input and output pins of the block.

other functions

paFbdsInputVar - connect an input of the last added block

OK := paFbdsInputVar (FID, NAME, PIN, NEGATE)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
NAME : STRING; Variable name or constant expression
PIN : DINT; Index of the input pin of the block (the first input pin is 1)
NEGATE : BOOL; If TRUE, the connection between the variable and the block has a boolean negation
OK : BOOL; True if successful

Description:

This function connects a variable box on input of the last block added by the paFbdsBlock function, and must be called immediately after.

other functions

paFbdsOutputVar - connect an output of the last added block

OK := paFbdsOutputVar (FID, NAME, PIN, NEGATE)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
NAME : STRING; Variable name
PIN : DINT; Index of the output pin of the block (the first output pin is 1)
NEGATE : BOOL; If TRUE, the connection between the block and the variable has a boolean negation
OK : BOOL; True if successful

Description:

This function connects a variable box on output of the last block added by the paFbdsBlock function, and must be called immediately after.

other functions

paFbdsOutputJump - connect a jump symbol on output of the last added block

OK := paFbdsOutputJump (FID, LABEL, PIN, NEGATE)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
LABEL : STRING; Target label name
PIN : DINT; Index of the output pin of the block (the first output pin is 1)
NEGATE : BOOL; If TRUE, the connection between the block and the variable has a boolean negation
OK : BOOL; True if successful

Description:

This function connects a jump instruction on output of the last block added by the paFbdsBlock function, and must be called immediately after.

other functions

paFbdsOutputReturn - connect a <return> jump symbol on output of the last added block

OK := paFbdsOutputReturn (FID, PIN, NEGATE)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
PIN : DINT; Index of the output pin of the block (the first output pin is 1)
NEGATE : BOOL; If TRUE, the connection between the block and the variable has a boolean negation
OK : BOOL; True if successful

Description:

This function connects a <RETURN> instruction on output of the last block added by the paFbdsBlock function, and must be called immediately after.

other functions

Example

Below is an example of script that generates a FBD file in the target project:

    // make FBD code - sequential writing
    f := paFileOpenWriteProgramSrc ('ProgFBD');
    if f <> 0 then
        // add a comment block (2 lines of text)
        paFbdsComment (f, 'FBD program$Ngenerated by script', 2);
        // add a function block and its inputs and outputs
        paFbdsBreak (f, 'function block');
        paFbdsBlock (f, 'Blink', 'Blinker');
            paFbdsInputVar (f, 'TRUE', 1, FALSE);
            paFbdsInputVar (f, 't#1s', 2, FALSE);
            paFbdsOutputJump (f, 'TheEnd', 1, FALSE);
        // add a function and its inputs and outputs
        paFbdsBreak (f, 'simple addition');
        paFbdsBlock (f, '+', '');
            paFbdsInputVar (f, 'i1', 1, FALSE);
            paFbdsInputVar (f, 'i2', 2, FALSE);
            paFbdsOutputVar (f, 'q', 1, FALSE);
        // add a label and an unconditional return instruction
        paFbdsBreak (f, 'the end');
        paFbdsLabel (f, 'TheEnd');
        paFbdsReturn (f);
        // add a break at the end of the diagram
        paFbdsBreak (f, 'eof');
        // close the file
        paFileClose (f);
    end_if;

Here is the FBD program generated by the script: