Binary -> ASCII conversion
Converts 16-bit/32-bit binary data stored in the area specified by s2_BinaryData to ASCII code. The conversion method is specified by n_ConversionMethod according to the four control characters of s1_Control. The converted result is stored in the area specified by d_AsciiData.
Input
Control string
H: converts to hexadecimal ASCII data
- Reverse direction
32: converts in 32-bit (2-word) units
Starting area for storing binary data
Conversion method
(for details, see explanation following the tables)
Output
Starting area for storing ASCII data
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.
(X values do not change)
About the number of ASCII characters (8-bit) per converted unit
When converting 16-bit binary units to hexadecimal ASCII data:
Range: 16#1–16#4
When converting 32-bit binary units to hexadecimal ASCII data:
Range: 16#1–16#8
When converting binary units to decimal ASCII data:
Range: 16#1–16#F
Binary data |
s1_ Con-trol |
n_Con- version Method |
Result ASCII data |
Comment |
|||||
---|---|---|---|---|---|---|---|---|---|
Data type |
Offs. in 16-bit word units |
Hex. value |
D |
D+1 |
D+2 |
D+3 |
|||
INT, WORD |
0 |
16#5678 |
16+H |
16#204 |
'78' |
'56' |
'34' |
'12' |
Normal direction. 2 x 4 ASCII characters. |
1 |
16#1234 |
||||||||
INT, WORD |
0 |
16#5678 |
16-H |
16#204 |
'78' |
'56' |
'12' |
'34' |
Reverse direction. 2 x 4 ASCII characters. |
1 |
16#1234 |
||||||||
INT, WORD |
0 |
16#0456 |
16+H |
16#203 |
'56' |
'42' |
'31' |
'$xx$xx' |
Normal direction. 2 x 3 ASCII characters. |
1 |
16#0123 |
||||||||
INT, WORD |
0 |
16#0456 |
16-H |
16#203 |
'45' |
'61' |
'23' |
'$xx$xx' |
Reverse direction. 2 x 3 ASCII characters. |
1 |
16#0123 |
||||||||
DINT, DWORD |
0 |
16#1234 5678 |
32+H |
16#108 |
'78' |
'56' |
'34' |
'12' |
Normal direction. 1 x 8 ASCII characters. |
DINT, DWORD |
0 |
16#1234 5678 |
32-H |
16#108 |
'12' |
'34' |
'56' |
'78' |
Reverse direction. 1 x 8 ASCII characters. |
DINT, DWORD |
0 |
16#00012345 |
32+H |
16#105 |
'45' |
'23' |
'1$xx' |
'$xx$xx' |
Normal direction. 1 x 5 ASCII characters. |
DINT, DWORD |
0 |
16#00012345 |
32-H |
16#105 |
'12' |
'34' |
'5$xx' |
'$xx$xx' |
Reverse direction. 1 x 5 ASCII characters. |
'x' values do not change.
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;
iArray1: ARRAY [0..1] OF INT:=[1234,-56];
iAscii1: ARRAY [0..4] OF WORD:=[5(16#FFFF)];
END_VAR
When bExecute is set to TRUE, the instruction is carried out. It converts two 16-bit units to 2 x 4 decimal ASCII data. Offset = 1 ASCII character (8-bit).
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_F,F250_BTOA!,Instance,9,3,21,9,,?DEN?Ds1_Control?Ds2_BinaryData?Dn_ConversionMethod?AENO?Cd_AsciiData);
B(B_VARIN,,'16-D',7,5,9,7,);
B(B_VARIN,,iArray1,7,6,9,8,);
B(B_VARIN,,16#214,7,7,9,9,);
B(B_VAROUT,,iAscii1,21,5,23,7,);
B(B_CONTACT,,bExecute,3,4,5,6,R);
B(B_COMMENT,,Result iAscii1: 'x1234 -56x',22,7,35,8,);
B(B_COMMENT,,Converts two 16-bit units to 2x4 decimal ASCII data. Offset = 1 ASCII character (8-bit).,2,1,35,3,);
L(1,5,3,5);
L(5,5,9,5);
L(1,0,1,9);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF DF(bExecute) then
F250_BTOA(s1_Control := '16-D',
s2_BinaryData := iArray1,
n_ConversionMethod := 16#214,
d_AsciiData => iAscii1);
END_IF;