F_FormatArgToStr
![F_FormatArgToStr 1:](Images/gif/35817483__en-US__Web.gif)
Auxiliary format function. This function is used internally by the FB_FormatString function block. The function can be used to convert a variable of type T_Arg into a formatted string according to the format specification.
FUNCTION F_FormatArgToStr: UDINT
VAR_INPUT
VAR_INPUT
bSign : BOOL;(* Sign prefix flag *)
bBlank : BOOL;(* Blank prefix flag *)
bNull : BOOL;(* Null prefix flag *)
bHash : BOOL;(* Hash prefix flag *)
bLAlign : BOOL;(* FALSE => Right align (default), TRUE => Left align *)
bWidth : BOOL;(* FALSE => no width padding, TRUE => blank or zeros padding enabled *)
iWidth : INT;(* Width length parameter *)
iPrecision : INT;(* Precision length parameter *)
eFmtType : E_TypeFieldParam; (* Format type field parameter *)
arg : T_Arg;(* Format argument *)
END_VAR
bSign: sign flag.
bBlank: blank flag.
bNull: null flag.
bHash: hash prefix flag.
bLAlign: alignment flag (TRUE=left align).
bWidth: If TRUE, the iWidth parameter is interpreted, otherwise not.
iWidth: Width parameter.
iPrecision: Precision parameter.
eFmtType: Type parameter (type: E_TypeFieldParam).
arg: The argument to be formatted. The following auxiliary functions can be used for converting different types of PLC variables into the required data type T_Arg: F_BYTE, F_WORD, F_DWORD, F_LWORD, F_SINT, F_INT, F_DINT, F_LINT, F_USINT, F_UINT, F_UDINT, F_ULINT, F_STRING, F_REAL, F_LREAL.
VAR_IN_OUT
VAR_IN_OUT
sOut : T_MaxString;
END_VAR
sOut: If successful, this variable returns the formatted output string (Type:T_MaxString).
Return parameter |
Meaning |
---|---|
0 |
No error |
<> 0 |
Error. For error description see Format error codes |
Examples:
Formatting a BYTE variable as a binary string.
PROGRAM MAIN
VAR
s1 : T_MaxString;
s2 : T_MaxString;
s3 : T_MaxString;
s4 : T_MaxString;
s5 : T_MaxString;
errID : UDINT;
varByte : BYTE;
double : LREAL;
L1 : INT;
L2 : INT;
L3 : INT;
L4 : INT;
L5 : INT;
END_VAR
varByte := 128;
errID := F_FormatArgToStr(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s1 );
errID := F_FormatArgToStr(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s2 );
errID := F_FormatArgToStr(FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s3 );
errID := F_FormatArgToStr(FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, 20, 8, TYPEFIELD_B, F_BYTE( varByte ), s4 );
L1 := LEN( s1 );
L2 := LEN( s2 );
L3 := LEN( s3 );
L4 := LEN( s4 );
The result:
s1 = '10000000'
s2 = ' 10000000'
s3 = '10000000 '
s4 = '2#10000000 '
L1 = 8
L2 = 20
L3 = 20
L4 = 20
Formatting an LREAL variable.
double := 12345.6789;
errID := F_FormatArgToStr( FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s1 );
errID := F_FormatArgToStr( FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s2 );
errID := F_FormatArgToStr( FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s3 );
errID := F_FormatArgToStr( FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s4 );
errID := F_FormatArgToStr( TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, 20, 8, TYPEFIELD_F, F_LREAL( double ), s5 );
L1 := LEN( s1 );
L2 := LEN( s2 );
L3 := LEN( s3 );
L4 := LEN( s4 );
L5 := LEN( s5 );
The result:
s1 = '12345.67890000'
s2 = ' 12345.67890000'
s3 = '12345.67890000 '
s4 = '00000012345.67890000'
s5 = '+12345.67890000 '
L1 = 14
L2 = 20
L3 = 20
L4 = 20
L5 = 20
Requirements
Development environment |
Target platform |
PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_Utilities (System) |