The functions below enable you to write sequentially (from the top to the bottom) the source code of a program written in LD language. The program is written ung after rung. Items are placed sequentially on the rung from the left to the right. Files are open using the paFileOpenWriteSrc function. When complete, they must be closed by calling the paFileClose function.
Use the following functions for inserting rungs in the diagram:
paFLdCommentLine - Add a comment line
(network break)
paFLdStartRung - Start a new rung
paFLdEndRung - Terminate the rung
paFLdDivergence - Start an "OR" divergence
on the current rung
paFLdConvergence - Terminate an "OR"
divergence on the current rung
paFLdNextBranch - Add a parallel branch to
the current divergence
Use the following functions for adding items on the current rung:
paFLdContact - Add a contact
paFLdCoil
- Add a coil
paFLdJump
- Add a jump instruction
paFLdReturn - Add a <return> jump
instruction
paFLdBlock - Add a block
paFLdHorzSegment - Add a horizontal
segment line
See an example...
Below are detailed information about these functions:
OK := paFLdCommentLine (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 comment line (network break) in between rungs.
OK := paFLdStartRung (FID, LABEL)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
LABEL : STRING; | Rung label name (empty string if no label defined) |
OK : BOOL; | True if successful |
Description:
This function starts a new rung. After calling this function, you can call other functions to add items on the rung from the left to the right. When complete, you need to call the paFLdEndRung function to terminate the rung.
OK := paFLdEndRung (FID)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
OK : BOOL; | True if successful |
Description:
This function terminates the current rung. You need to call it before starting another rung or adding a comment line.
OK := paFLdDivergence (FID)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
OK : BOOL; | True if successful |
Description:
This function starts a "OR" divergence on the current rung. After calling this function, items can be added on the first (top) branch of the divergence. Parallel branches can be added by calling the paFLdNextBranch function. When complete, you need to call the paFLdConvergence function to terminate the divergence.
OK := paFLdConvergence (FID)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
OK : BOOL; | True if successful |
Description:
This function terminates the current "OR" divergence. After calling this function, items can be added after the divergence on the parent rung.
OK := paFLdNextBranch (FID)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
OK : BOOL; | True if successful |
Description:
This function starts a new parallel branch in the current "OR" divergence. After calling this function, items can be added on the new branch.
OK := paFLdContact (FID, TYP, NAME)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
TYP : STRING; | Type of contact (see notes) |
NAME : STRING; | Name of the variable attached to the contact |
OK : BOOL; | True if successful |
Description:
This function adds a contact on the current rung. The following values are available for the TYP parameter:
_LD_DIR | Normal contact |
_LD_INV | Negated contact |
_LD_P | Positive pulse contact |
_LD_N | Negative pulse contact |
OK := paFLdCoil (FID, TYP, NAME)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
TYP : STRING; | Type of coil (see notes) |
NAME : STRING; | Name of the variable attached to the coil |
OK : BOOL; | True if successful |
Description:
This function adds a coil on the current rung. The following values are available for the TYP parameter:
_LD_DIR | Normal coil |
_LD_INV | Negated coil |
_LD_P | Positive pulse coil |
_LD_N | Negative pulse coil |
_LD_SET | Set coil |
_LD_RESET | Reset coil |
OK := paFLdJump (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 on the current rung.
OK := paFLdReturn (FID)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
OK : BOOL; | True if successful |
Description:
This function adds a <RETURN> jump instruction on the current rung.
OK := paFLdBlock (FID, NAME, INSTANCE, INPUTS, OUTPUTS)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
NAME : STRING; | Type of block |
INSTANCE : STRING; | Name of the instance in case of a function block |
INPUTS : STRING; | List of input values (see notes) |
OUTPUTS : STRING; | List of output values (see notes) |
OK : BOOL; | True if successful |
Description:
This function adds a block on the current rung. In case of a function block, you must specify the name of the instance. Blocks are connected to the rung by their first input and output. Name of additional inputs and outputs are passed in strings separated by comas. Below is the example of an "addition" block with 2 additional inputs calle 'i1' and 'i2'and 1 additional output calle 'q':
paFLdStartRung (f,
'');
paFldBlock (f, '+', '',
'i1,i2', 'q');
paFldCoil (f,
_LD_DIR, '');
paFLdEndRung (f);
OK := paFLdHorzSegment (FID)
Parameters:
FID : DINT; | File identifier answered by paFileOpenWriteSrc |
OK : BOOL; | True if successful |
Description:
This function adds a horizontal line segment on the current rung. This can be used for aligning items vertically in the diagram.
Below is an example of script that generates a LD file in the target project:
// make LD
code
f := paFileOpenWriteProgramSrc
('ProgLD');
if f <> 0 then
//
comment line
paFLdCommentLine (f, 'Generated by script');
//
a simple rung finishing with a
jump
paFLdStartRung (f, '');
paFldContact (f, _LD_DIR, 'Cond');
paFldJump (f, 'TheEnd');
paFLdEndRung (f);
//
a rung with contacts and
coils
paFLdStartRung (f, '');
paFldContact (f, _LD_DIR, 'V1');
paFLdDivergence (f);
paFldContact (f, _LD_DIR, 'V2');
paFLdNextBranch (f);
paFldContact (f, _LD_DIR, 'V3');
paFLdConvergence (f);
paFldCoil (f, _LD_INV, 'V');
paFLdEndRung (f);
//
a rung with
blocks
paFLdStartRung (f, '');
paFldBlock (f, '+', '', 'i1,i2', 'q');
paFldBlock (f, 'Blink', 'Blinker', 't#1s', '');
paFldCoil (f, _LD_DIR, '');
paFLdEndRung (f);
//
a rung with a label and a RETURN
instruction
paFLdStartRung (f, 'TheEnd');
paFldReturn (f);
paFLdEndRung (f);
//
close the file
paFileClose (f);
end_if;
Here is the LD program generated by the script: