FP_HEX_TO_ASCIIHEX -> ASCII conversion
This FP instruction converts the hexadecimal data at s_Start into ASCII codes if the trigger EN is TRUE. n_Bytes specifies the number of bytes to be converted. The result is stored in the area specified by d_Start. ASCII code requires 8 bits (1 byte) to express one hexadecimal character. Upon conversion to ASCII, the data length will thus be twice the length of the source data.

Input
Hexadecimal data
Number of bytes
Output
Starting address of the data area for the results. The size is n_Bits * 2 words.
The two characters that make up one byte are interchanged when stored. Two bytes are converted as one segment of data.
if the area specified using the index modifier exceeds the limit.
if the byte number specified by n_Bytes is greater than the area specified by s_Start
if the calculated result exceeds the area specified by d_Start
if n_Bytes= 0 or a negative value
if the area specified using the index modifier exceeds the limit.
if the byte number specified by n_Bytes is greater than the area specified by s_Start
if the calculated result exceeds the area specified by d_Start
if n_Bytes= 0 or a negative value
Offset  | 
Hex. characters | Offset  | 
Converted ASCII codes  | 
String equivalent  | 
|||
s_Start  | 
0  | 
16#ABCD  | 
Þ  | 
d_Start  | 
0  | 
16#4443  | 
DC  | 
n_Bytes  | 
16#0002  | 
16#4241  | 
BA  | 
Offset  | 
Hex. characters | Offset  | 
Converted ASCII codes  | 
String equivalent  | 
|||
s_Start  | 
0  | 
16#1234  | 
Þ  | 
d_Start  | 
0  | 
16#3433  | 
43  | 
1  | 
16#5678  | 
1  | 
16#3231  | 
21  | 
|||
n_Bytes  | 
16#0004  | 
16#3837  | 
87  | 
||||
16#3635  | 
65  | 

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
		bStart: BOOL:=FALSE;
		awInput: ARRAY [0..2] OF WORD:=[16#ABCD,2(0)];
		awResult: ARRAY [0..5] OF WORD:=[6(16#FFFF)];
	END_VAR
    When the variable bStart is set to TRUE, the function is carried out.

      BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_COMMENT,,After conversion: ø^awResult[0]=16#4443ø^awResult[1]=16#4241ø^awResult[2]=16#3030ø^awResult[3]=16#3030ø^awResult[4] is not written,23,0,38,6,);
B(B_CONTACT,,bStart,4,5,6,7,R);
B(B_F,FP_HEX_TO_ASCII!,,12,4,22,9,,?DEN?D@'s'?Dn_Chars?AENO?Cd_Start);
B(B_VARIN,,awInput[0],10,6,12,8,);
B(B_VAROUT,,awResult[0],22,6,24,8,);
B(B_VARIN,,4,10,7,12,9,);
L(1,0,1,9);
L(1,6,4,6);
L(6,6,12,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY
    
if (DF(bStart)) then
	FP_HEX_TO_ASCII(s_Start := awInput[0], n_Bytes := 4, d_Start => awResult[0]);
	(* After conversion: 
		awResult[0]=16#4443
		awResult[1]=16#4241
		awResult[2]=16#3030
		awResult[3]=16#3030
		awResult[4] is not written *)
end_if;