SFC - 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 SFC language. The program is written sequentially, from the top to the bottom and branch per branch. Files are open using the paFileOpenWriteSrc function. When complete, they must be closed by calling the paFileClose function.

Use the following functions for inserting SFC items in the chart:

paSfcIStep - Add an initial step
paSfcStep - Add a step
paSfcTrans - Add a transition
paSfcJump - Add ajump to a step
paSfcDiv - Start a divergence on the current branch
paSfcBranch - Start a new branch under the current divergence
paSfcConv - Finish the current divergence
paSfcAddLv2String - Add a text string to the level 2 program
paSfcAddLv2Line - Add a text line to the level 2 program
paSfcAddLv2Eol - Add end ol line characters to the level 2 program

See an example...

Notes: macro-steps are not supported.

Below are detailed information about these functions:

paSfcIStep - add an initial step

OK := paSfcIStep (FID, REF)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
REF : DINT; Reference number of the step
OK : BOOL; True if successful

Description:

This function adds an initial step at the end of the current branch.

other functions

paSfcStep - add a step

OK := paSfcStep (FID, REF)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
REF : DINT; Reference number of the step
OK : BOOL; True if successful

Description:

This function adds a step at the end of the current branch.

other functions

paSfcTrans - add a transition

OK := paSfcTrans (FID, REF)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
REF : DINT; Reference number of the transition
OK : BOOL; True if successful

Description:

This function adds a transition at the end of the current branch.

other functions

paSfcJump - add a jump to a step

OK := paSfcJump (FID, REF)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
REF : DINT; Reference number of the target step
OK : BOOL; True if successful

Description:

This function adds a jump to a step at the end of the current branch.

other functions

paSfcDiv - start a divergence

OK := paSfcDiv (FID)

Parameters:

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

Description:

This function starts a divergence the end of the current branch. It automatically initiates the first branch (left side) so you can start instering items on it. The divergence will have to be ended by a convergence, even if its branches finish by a jump symbol (and thus do not actually converge). Divergences can be nested.

other functions

paSfcBranch - add a branch to the last open divergence

OK := paSfcBranch (FID)

Parameters:

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

Description:

This function adds a new branch on the right of the divergence created by the last call to paSfcDiv() It is not needed to call this function for the first branch (on the left) as it is automatically initiated when the divergence is created.

other functions

paSfcConv - finish a divergence

OK := paSfcConv (FID)

Parameters:

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

Description:

This function closes the divergence created by the last call to paSfcDiv() The divergence will have to be ended by a convergence, even if its branches finish by a jump symbol (and thus do not actually converge). Divergences can be nested.

other functions

paSfcAddLv2String - add text string to level2 programming

OK := paSfcAddLv2String (FID, KIND, TEXT)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
KIND : STRING; Kind of level 2 information - see notes
TEXT : STRING; Text to be appened
OK : BOOL; True if successful

Description:

This function appends a string to the level 2 programming of the last created step or transition. It must be called immediately after the step or transition is created. The "KIND" argument specify which piece of level 2 information must be written. The following values are predefined:

_LV2_NOTE Description text
_LV2_COND Condition (for a transition)
_LV2_ACTION Default actions of a step
_LV2_P1 P1 actions of a step
_LV2_N N actions of a step
_LV2_P0 P0 actions of a step

Generating level 2 programs in LD or FBD is not supported.

other functions

paSfcAddLv2Line - add text line to level2 programming

OK := paSfcAddLv2Line (FID, KIND, TEXT)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
KIND : STRING; Kind of level 2 information - see notes
TEXT : STRING; Text to be appened
OK : BOOL; True if successful

Description:

This function appends a string plus end of lines characters ('$R$N') to the level 2 programming of the last created step or transition. It must be called immediately after the step or transition is created. The "KIND" argument specify which piece of level 2 information must be written. The following values are predefined:

_LV2_NOTE Description text
_LV2_COND Condition (for a transition)
_LV2_ACTION Default actions of a step
_LV2_P1 P1 actions of a step
_LV2_N N actions of a step
_LV2_P0 P0 actions of a step

Generating level 2 programs in LD or FBD is not supported.

other functions

paSfcAddLv2Eol - add end of line characters to level2 programming

OK := paSfcAddLv2Eol (FID, KIND)

Parameters:

FID : DINT; File identifier answered by paFileOpenWriteSrc
KIND : STRING; Kind of level 2 information - see notes
OK : BOOL; True if successful

Description:

This function appends end of lines characters ('$R$N') to the level 2 programming of the last created step or transition. It must be called immediately after the step or transition is created. The "KIND" argument specify which piece of level 2 information must be written. The following values are predefined:

_LV2_NOTE Description text
_LV2_COND Condition (for a transition)
_LV2_ACTION Default actions of a step
_LV2_P1 P1 actions of a step
_LV2_N N actions of a step
_LV2_P0 P0 actions of a step

Generating level 2 programs in LD or FBD is not supported.

other functions

Example

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

    // make LD code
   
f := paFileOpenWriteProgramSrc ('ProgSFC');
    if f <> 0 then

        // initial step
        paSfcIStep (f, 1);
        paSfcAddLv2String (f, _LV2_NOTE, 'Thats S1');
        paSfcAddLv2Line (f, _LV2_ACTION, 'VarXX (N);');

        // an 'OR' divergence
        paSfcDiv (f);

            paSfcTrans (f, 1);
            paSfcAddLv2String (f, _LV2_NOTE, 'Thats T1');
            paSfcAddLv2Line (f, _LV2_COND, 'condition');

        // second branch
        paSfcBranch (f);

            paSfcTrans (f, 101);
            paSfcStep (f, 101);
            paSfcTrans (f, 102);

        // converge
        paSfcCnv (f);

        // jump to the initial step
        paSfcJump (f, 1);

        // close the file
        paFileClose (f);
    end_if;
 

Here is the SFC program generated by the script: