F250_BTOA

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.

Parameters

Input

s1_Control (STRING)

Control string

  1.  (1) D: converts to decimal ASCII data

    H: converts to hexadecimal ASCII data

  2.  (2) + Normal direction

    - Reverse direction

  3.  (3) 16: converts in 16-bit (1-word) units

    32: converts in 32-bit (2-word) units

s2_BinaryData (BOOL, INT, UINT, WORD, DINT, UDINT, DWORD, REAL, DATE, TOD, DT, STRING)

Starting area for storing binary data

n_ConversionMethod (WORD, INT, UINT)

Conversion method

  1.  (1) Number of ASCII characters per converted unit
  2.  (2) Offset in ASCII character units (8-bit)
  3.  (3) Number of 16-bit (1-word) or 32-bit (2-word) units converted

(for details, see explanation following the tables)

Output

d_AsciiData (BOOL, INT, UINT, WORD, DINT, UDINT, DWORD, REAL, DATE, TOD, DT, STRING)

Starting area for storing ASCII data

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • 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.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • 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.

Explanation of the conversion method, e.g. n_ConversionMethod = 16#0214

  1.  (1) Number of ASCII characters per converted unit (see notes for restrictions)
  2.  (2) Register content (hex.)
  3.  (3) Character string (see notes)
  4.  (4) Offset in ASCII character units (8-bit) for storing the result

    (X values do not change)

  5.  (5) Number of 16-bit (1-word) or 32-bit (2-word) units to be converted
  6.  (6) Register content (hex.)
  7.  (7) Values (dec.)
NOTE

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

Conversion examples:

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.

Example

POU header

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

POU body

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).

LD body

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

ST body

IF DF(bExecute) then
    F250_BTOA(s1_Control := '16-D', 
        s2_BinaryData := iArray1, 
        n_ConversionMethod := 16#214, 
        d_AsciiData => iAscii1);
END_IF;

Modified on: 2019-06-04Feedback on this pagePanasonic hotline