RTC (FB) ¶ FUNCTION_BLOCK RTC Calculates the elapsed time since a given start time Usage Examples: This function block can be used as an operation hour counter, when PDT is set to DT#1970-01-01-00-00:00 , or is simply not connected. This function block can be used to return the current date and time, by adjusting the FB to the current local time. Just, set the input PDT to the current local time, on the rising edge of EN . Note This counter will have an overflow at the 7th February, 2106. (* Example in ST *) RTC ( EN := VarBOOL1 , PDT := DT#2006-03-30-14:00:00 , Q => VarBOOL2 , CDT => VarTimeCur ); InOut: Scope Name Type Comment Input EN BOOL Rising edge: CDT is set to PDT and CDT starts increasing. Falling edge: CDT is set to DT#1970-01-01-00:00:00 . PDT DT Preset date and time Output Q BOOL TRUE as long as CDT is counting CDT DT Date and time, elapsed since PDT
String Functions ¶ CONCAT (Function) DELETE (Function) FIND (Function) INSERT (Function) LEFT (Function) LEN (Function) MID (Function) REPLACE (Function) RIGHT (Function)
CONCAT (FUN) ¶ FUNCTION CONCAT : STRING(255) Concatenates two strings CONCAT(STR1,STR2) means: Connect STR1 and STR2 to a single string STR1STR2 . (* Example declaration *) VarSTRING1 : STRING ; (* Example in ST , result is 'SUSIWILLI' *) VarSTRING1 := CONCAT ( 'SUSI' , 'WILLI' ); InOut: Scope Name Type Comment Return CONCAT STRING(255) Concatenated string, max. 255 characters. If the result doesn’t fit into these 255 bytes, it will be silently truncated. No error is produced. Input STR1 STRING(255) String 1 to be concatenated, max. 255 characters STR2 STRING(255) String 2 to be concatenated, max. 255 characters
DELETE (FUN) ¶ FUNCTION DELETE : STRING(255) Deletes a number of characters from a string DELETE (STR, LEN, POS) means: Delete LEN characters from STR , beginning with the character in the POS position. POS = 0 or POS = 1 , are both addressing the first character. Note The current implementation is unfortunately not correct for the case Pos=0 . The implementation cannot be changed for compatibility reasons. If Pos=0 is used, the parameter LEN is internally reduced by one! It is generally recommended to use values in the range specified by IEC 61131-3. The smallest value for Pos is specified there as 1 . (* Example declaration *) VarSTRING1 : STRING ; (* Example in ST , result is 'SUSI' *) VarSTRING1 := DELETE ( 'SUXYSI' , 2 , 3 ); InOut: Scope Name Type Comment Return DELETE STRING(255) String remaining after deletion Input STR STRING(255) String to be modfied LEN INT Length of the partial string to be deleted, number of characters POS INT Position in STR after which the deletion starts. Counted from left, starting with 1
FIND (FUN) ¶ FUNCTION FIND : INT Searches for the position of a partial string within a 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 declaration *) arINT1 : INT ; (* Example in ST , result is '4' *) arINT1 := FIND ( 'abcdef' , 'de' ); InOut: Scope Name Type Comment Return FIND INT Character position of the first occurance of STR2 in STR1 . If no occurance is found, result is 0 Input STR1 STRING(255) String within which STR2 is searched STR2 STRING(255) String whose position is searched in STR1
INSERT (FUN) ¶ FUNCTION INSERT : STRING(255) Inserts a string into another string at a specific position INSERT (STR1, STR2, POS) means: Insert STR2 into STR1 after position POS . (* Example declaration *) VarSTRING1 : STRING ; (* Example in ST , result is 'SUXYSI' *) VarSTRING1 := INSERT ( 'SUSI' , 'XY' , 2 ); InOut: Scope Name Type Comment Return INSERT STRING(255) Resulting string Input STR1 STRING(255) String into which STR2 is inserted STR2 STRING(255) String to be inserted into STR1 POS INT Insert position. If POS is > 255 OR < 0, the result equals STR1 0 : Inserts before the first character 1 : Inserts after the first character.
LEFT (FUN) ¶ FUNCTION LEFT : STRING(255) Returns a specific number of characters of a string, starting from left LEFT (STR, SIZE) means: Return the first SIZE characters from the left in string STR (* Example declaration *) VarSTRING1 : STRING ; (* Example in ST , result is 'SUS' *) VarSTRING1 := LEFT ( 'SUSI' , 3 ); InOut: Scope Name Type Comment Return LEFT STRING(255) Resulting string Input STR STRING(255) String to be analyzed SIZE INT Number of characters
LEN (FUN) ¶ FUNCTION LEN : INT Returns the number of characters of a string (* Example declaration *) VarINT1 : INT ; (* Example in ST , result is '4 *) VarINT1 := LEN ( 'SUSI' ); InOut: Scope Name Type Comment Return LEN INT Length of string STR Input STR STRING(255) String to be analyzed
MID (FUN) ¶ FUNCTION MID : STRING(255) Returns a specific number of characters of a string, starting from a specific position MID (STR, LEN, POS) means: Retrieve LEN characters from the STR string beginning with the character at position POS . (* Example declaration *) VarSTRING1 : STRING ; (* Example in ST , result is 'US' *) VarSTRING1 := MID ( 'SUSI' , 2 , 2 ); InOut: Scope Name Type Comment Return MID STRING(255) Partial string of STR Input STR STRING(255) String to be analyzed LEN INT Number of characters, counted from the left POS INT Start position for the partial string
REPLACE (FUN) ¶ FUNCTION REPLACE : STRING(255) Replaces a specific number of characters of a string by another string REPLACE(STR1, STR2, L, P) means: Replace L characters from STR1 by STR2 , beginning with the character in the P position. POS = 0 or POS = 1 , are both addressing the first character. Note The current implementation is unfortunately not correct for the case P=0 . The implementation cannot be changed for compatibility reasons. If P=0 is used, the parameter L is internally reduced by one! It is generally recommended to use values in the range specified by IEC 61131-3. The smallest value for P is specified there as 1 . (* Example declaration *) VarSTRING1 : STRING ; (* Example in ST , result is 'SKYSI' *) VarSTRING1 := REPLACE ( 'SUXYSI' , 'K' , 2 , 2 ); InOut: Scope Name Type Comment Return REPLACE STRING(255) Resulting string Input STR1 STRING(255) String of which a part is replaced STR2 STRING(255) String which replaces a part of STR1 L INT Number of characters, counting from left P INT Start position of the characters to be replaced. P = 1 or P = 0 are both addressing the first character