ASCII data check
Checks whether the ASCII codes stored in the area specified by s2_AsciiData can be converted correctly using the conversion method specified in by n_ConversionMethod and the 4 control characters specified by s1_Control.
Input
Control string
H: converts to hexadecimal ASCII data
- Reverse direction
32: converts in 32-bit (2-word) units
Starting area for storing ASCII data
16-bit equivalent constant or 16-bit area for storing conversion method
Output
Starting area for storing binary data
If the results are correct, the system variable sys_bIsEqual turns on.
If the results are incorrect, the system variable sys_bIsEqual turns off.
For an detailed description of s1_Control and F251_ATOB, please refer to F251_ATOB.
if there is an error in the control string specified by s1_Control.
if normal direction (+) is specified in s1_Control when the format is decimal.
if the number of ASCII characters per converted unit specified by n_ConversionMethod exceeds 4 for 16-bit data or 8 for 32-bit data when hexadecimal format is specifed by s1_Control.
if 0 is specified for the no. of 16- or 32-bit (1- or 2-word) units to be converted in n_ConversionMethod.
if the number of 16- or 32-bit decimal numbers to be converted specified by n_ConversionMethod exceeds the area for storing ASCII data.
if the converted result exceeds the area.
if there is an error in the control string specified by s1_Control.
if normal direction (+) is specified in s1_Control when the format is decimal.
if the number of ASCII characters per converted unit specified by n_ConversionMethod exceeds 4 for 16-bit data or 8 for 32-bit data when hexadecimal format is specifed by s1_Control.
if 0 is specified for the no. of 16- or 32-bit (1- or 2-word) units to be converted in n_ConversionMethod.
if the number of 16- or 32-bit decimal numbers to be converted specified by n_ConversionMethod exceeds the area for storing ASCII data.
if the converted result exceeds the area.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
bExecute: BOOL:=FALSE;
sString1: STRING[10]:='1234567890';
(*Important: Initialize the string with the desired current length*)
bAsciiDataAreCorrect: BOOL:=FALSE;
END_VAR
When bExecute is set to TRUE, the instruction checks whether the data connected at s2_AsciiData can be converted when the control string is 'D-16' and the conversion method 16#214.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 9 ;
NETWORK_BODY
B(B_VARIN,,'D-16',21,5,23,7,);
B(B_VARIN,,16#214,21,7,23,9,);
B(B_F,F252_ACHK!,Instance,23,3,35,9,,?DEN?Ds1_Control?Ds2_AsciiData?Dn_ConversionMethod?AENO);
B(B_CONTACT,,sys_bIsEQ,36,4,38,6,);
B(B_F,Adr_Of_VarOffs_I!,Instance,10,5,19,9,,?D@'Var'?DOffs?CAdr);
B(B_VARIN,,2,8,7,10,9,);
B(B_VARIN,,sString1,8,6,10,8,);
B(B_COIL,,bAsciiDataAreCorrect,43,4,45,6,S);
B(B_COMMENT,,Result ø^bAsciiDataAreCorrect: TRUE,35,6,48,8,);
B(B_CONTACT,,bExecute,3,4,5,6,R);
B(B_COMMENT,,When bExcecute ist set to TRUE~ the instruction checks whether the data connectd atø^s2_AsciiData can be converted when the control string is 'D-16' and the conversion method 16#214.,2,1,40,3,);
L(19,7,23,7);
L(35,5,36,5);
L(38,5,43,5);
L(1,0,1,9);
L(1,5,3,5);
L(5,5,23,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF DF(bExecute) then
F252_ACHK(s1_Control := 'D-16', s2_AsciiData := Adr_Of_VarOffs(Var := sString1, Offs := 2), n_ConversionMethod := 16#214);
IF (sys_bIsEQ) then
bAsciiDataAreCorrect := TRUE;
end_if;
END_IF;