Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
159
Добавлен:
11.10.2020
Размер:
2.81 Mб
Скачать

Appendix D: - The CoDeSys Libaries

Appendix D: The CoDeSys Libaries

10.16 The Standard.lib library

10.16.1 String functions...

Please note: String functions are not "thread safe": When using tasks, string functions may only be used in a single task. If the same function is used in different tasks, there is a danger of overwriting.

LEN

Returns the length of a string. Input STR is of type STRING, the return value of the function is type INT.

Example in IL:

LD 'SUSI'

LEN

ST VarINT1 (* Result is 4 *)

Example in FBD:

Example in ST:

VarSTRING1 := LEN ('SUSI');

LEFT

Left returns the left, initial string for a given string. Input STR is type STRING, SIZE is of type INT, the return value of the function is type STRING.

LEFT (STR, SIZE) means: Take the first SIZE character from the right in the string STR.

Example in IL:

LD

'SUSI'

LEFT

3

ST

VarSTRING1 (* Result is 'SUSI' *)

Example in FBD:

Example in ST:

VarSTRING1 := LEFT ('SUSI',3);

RIGHT

Right returns the right, initial string for a given string.

RIGHT (STR, SIZE) means: Take the first SIZE character from the right in the string STR.

Input STR is of type STRING, SIZE is of type INT, the return value of the function is of type STRING.

Example in IL:

CoDeSys V2.3

10-39

 

Appendix D: - The CoDeSys Libaries

LD

'SUSI'

RIGHT

3

ST

VarSTRING1 (* Result is 'USI' *)

Example in FBD:

Example in ST:

VarSTRING1 := RIGHT ('SUSI',3);

MID

Mid returns a partial string from within a string.

Input STR is type STRING, LEN and POS are type INT, the return value of the function is type STRING.

MID (STR, LEN, POS) means: Retrieve LEN characters from the STR string beginning with the character at position POS.

Example in IL:

LD 'SUSI'

MID 2,2

ST VarSTRING1 (* Result is 'US' *)

Example in FBD:

Example in ST:

VarSTRING1 := MID ('SUSI',2,2);

CONCAT

Concatenation (combination) of two strings.

The input variables STR1 and STR2 as well as the return value of the function are type STRING.

Example in IL:

LD

'SUSI'

CONCAT

'WILLI'

ST

VarSTRING1 (* Result is 'SUSIWILLI' *)

Example in FBD:

Example in ST:

VarSTRING1 := CONCAT ('SUSI','WILLI');

Please note: The CONCAT function does not work, if nested over more than five levels.

10-40

CoDeSys V2.3

Appendix D: - The CoDeSys Libaries

INSERT

INSERT inserts a string into another string at a defined point.

The input variables STR1 and STR2 are type STRING, POS is type INT and the return value of the function is type STRING.

INSERT(STR1, STR2, POS) means: insert STR2 into STR1 after position POS.

Example in IL:

LD

'SUSI'

INSERT 'XY',2

ST

VarSTRING1 (* Result is 'SUXYSI' *)

Example in FBD:

Example in ST:

VarSTRING1 := INSERT ('SUSI','XY',2);

DELETE

DELETE removes a partial string from a larger string at a defined position.

The input variable STR is type STRING, LEN and POS are type INT, the return value of the function is type STRING.

DELETE(STR, L, P) means: Delete L characters from STR beginning with the character in the P position.

Example in IL:

LD

'SUXYSI'

DELETE 2,3

 

ST

Var1

(* Result is 'SUSI' *)

Example in FBD:

Example in ST:

Var1 := DELETE ('SUXYSI',2,3);

REPLACE

REPLACE replaces a partial string from a larger string with a third string.

The input variable STR1 and STR2 are type STRING, LEN and POS are type INT, the return value of the function is type STRING.

REPLACE(STR1, STR2, L, P) means: Replace L characters from STR1 with STR2 beginning with the character in the P position.

Example in IL:

LD 'SUXYSI'

REPLACE 'K',2,2

ST

VarSTRING1 (* Result is 'SKYSI' *)

Example in FBD:

CoDeSys V2.3

10-41

Appendix D: - The CoDeSys Libaries

Example in ST:

VarSTRING1 := REPLACE ('SUXYSI','K',2,2);

FIND

FIND searches for a partial string within a string.

The input variable STR1 and STR2 are type STRING, the return value of the function is type STRING.

FIND(STR1, STR2) means: Find the position of the first character where STR2 appears in STR1 for the first time. If STR2 is not found in STR1, then OUT:=0.

Example in IL:

LD

'SUXYSI'

FIND

'XY'

ST

VarINT1 (* Result is '3' *)

Example in FBD:

Example in ST:

arINT1 := FIND ('SUXYSI','XY');

10.16.2 Bistable Function Blocks...

SR

Making Bistable Function Blocks Dominant: Q1 = SR (SET1, RESET) means:

Q1 = (NOT RESET AND Q1) OR SET1

The input variables SET1 and RESET as well as the output variable Q1 are type BOOL. Declaration example:

SRInst : SR ;

Example in IL:

CAL SRInst(SET1 := VarBOOL1, RESET := VarBOOL2)

LD SRInst.Q1

ST VarBOOL3

Example in FBD:

Example in ST:

SRInst(SET1:= VarBOOL1 , RESET:=VarBOOL2 );

VarBOOL3 := SRInst.Q1 ;

10-42

CoDeSys V2.3

Appendix D: - The CoDeSys Libaries

RS

Resetting Bistable Function Blocks Q1 = RS (SET, RESET1) means:

Q1 = NOT RESET1 AND (Q1 OR SET)

The input variables SET and RESET1 as well as the output variable Q1 are type BOOL. Declaration example:

RSInst : RS ;

Example in IL:

CAL RSInst(SET:= VarBOOL1,RESET1:=VarBOOL2)

LD RSInst.Q1

ST VarBOOL3

Example in FBD:

Example in ST:

RSInst(SET:= VarBOOL1 , RESET1:=VarBOOL2 );

VarBOOL3 := RSInst.Q1 ;

SEMA

A Software Semaphore (Interruptible) BUSY = SEMA(CLAIM, RELEASE) means:

BUSY := X;

IF CLAIM THEN X:=TRUE;

ELSE IF RELEASE THEN BUSY := FALSE; X:= FALSE; END_IF

X is an internal BOOL variable that is FALSE when it is initialized. The input variables CLAIM and RELEASE as well as the output variable BUSY are type BOOL.

If BUSY is TRUE when SEMA is called up, this means that a value has already been assigned to SEMA (SEMA was called up with CLAIM = TRUE). If BUSY is FALSE, SEMA has not yet been called up or it has been released (called up with RELEASE = TRUE).

Declaration example:

SEMAInst : SEMA ;

Example in IL:

CAL SEMAInst(CLAIM:=VarBOOL1,RELEASE:=VarBOOL2)

LD SEMAInst.BUSY

ST VarBOOL3

Example in FBD:

Example in ST:

SEMAInst(CLAIM:= VarBOOL1 , RELEASE:=VarBOOL2 );

VarBOOL3 := SEMAInst.BUSY;

CoDeSys V2.3

10-43

Соседние файлы в папке 759-333