F251_ATOB

ASCII -> binary conversion

Converts ASCII code stored in the area specified by s2_AsciiData to 16-bit/32-bit binary data. 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_BinaryData.

Parameters

Input

s1_Control (STRING)

Control string, e.g D-16

  • D converts decimal ASCII data
  • H converts hexadecimal ASCII data
  • + normal direction
  • - reverse direction
  • 16 converts the ASCII data to 16-bit data, -32,768 to +32,767 (16#0 to 16#FFFF)
  • 32 converts the ASCII data to 32-bit data, -2,147,483,648 to +2,147,483,647 (16#0 to 16#FFFFFFFF)
s2_AsciiData (BOOL, INT, UINT, WORD, DINT, UDINT, DWORD, REAL, DATE, TOD, DT, STRING)

Starting area for storing ASCII data

n_ConversionMethod (WORD, INT, UINT)

Conversion method e.g 16#404

  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_BinaryData (BOOL, INT, UINT, WORD, DINT, UDINT, DWORD, REAL, DATE, TOD, DT, STRING)

Starting area for storing binary 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#0413 for ASCII data '0123456789012'

For comma-delimited data, specify the maximum number for numeric data. For decimal ASCII data, spaces, symbols and a decimal point are included. The data range is restricted by the control character string s1_Control.

  1.  (1) Number of ASCII characters per converted unit
  2.  (2) Register content (hex.)
  3.  (3) Character string
  4.  (4) Offset in ASCII character units (8-bit) for storing the result
  5.  (5) Number of 16-bit (1-word) or 32-bit (2-word) units to be converted

Conversion examples for ASCII data '0123456789ABCDEF'

n_Conversion method

s1_ Control

ASCII data

Binary data

Comment

Data type

Offset1)

Hex. value

 

H+16

16#404

D:'01'

D+1:'23'

D+2:'45'

D+3:'67'

D+4:'89'

D+5:'AB'

D+6:'CD'

D+7:'EF'

INT, WORD

0

16#2301

Normal direction

4 x 4 ASCII characters

1

16#6745

2

16#AB89

3

16#EFCD

H-16

16#404

INT, WORD

0

6#0123

Reverse direction

4 x 4 ASCII characters

1

16#4567

2

16#89AB

3

16#CDEF

H+16

16#403

INT, WORD

0

16#*201

Normal direction

3 x 4 ASCII characters

1

16#*534

2

16#*867

3

16#*B9A

H-16

16#403

INT, WORD

0

16#*012

Reverse direction

3 x 4 ASCII characters

1

16#*345

2

16#*678

3

6#*9AB

H+32

16#208

DINT, DWORD

0

16#67452301

Normal direction

8 x 2 ASCII characters

2

16#EFCDAB89

H-32

16#208

DINT, WORD

0

16#01234567

Reverse direction

8 x 2 ASCII characters

2

16#89ABCDEF

H+32

16#205

DINT, DWORD

0

16#***42301

Normal direction

5 x 2 ASCII characters

2

16#***97856

H-32

16#205

DINT, DWORD

0

16#***01234

Reverse direction

5 x 2 ASCII characters

2

16#***56789

1) Offset in 16-bit word units

*The extra characters become '0'.

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;
		iArray2: ARRAY [0..1] OF INT:=[2(0)];
			(*Begin ASCII: _1,23,04,-5,6_*)
		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 2 x 4 decimal ASCII characters to binary data. Offset = 0 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,F251_ATOB!,Instance,9,3,21,9,,?DEN?Ds1_Control?Ds2_AsciiData?Dn_ConversionMethod?AENO?Cd_BinaryData);
B(B_VARIN,,'D-16',7,5,9,7,);
B(B_VARIN,,iAscii1,7,6,9,8,);
B(B_VARIN,,16#214,7,7,9,9,);
B(B_VAROUT,,iArray2,21,5,23,7,);
B(B_CONTACT,,bExecute,3,4,5,6,R);
B(B_COMMENT,,Result iArray2: [1234~-56],22,7,35,8,);
B(B_COMMENT,,Converts 2x4 decimal ASCII data to binary data. Offset = 1 ASCII character (8-bit).,2,1,35,2,);
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
    F251_ATOB(s1_Control := 'D-16', 
    s2_AsciiData := iAscii1, 
    n_ConversionMethod := 16#214, 
    d_BinaryData => iArray2);
END_IF;

Modified on: 2019-12-14Feedback on this pagePanasonic hotline