FP_ASCII_TO_DEC

ASCII -> decimal conversion

This FP instruction converts the hexadecimal ASCII codes beginning at s_Start to decimal numbers if the trigger EN is TRUE. n_Chars specifies the number of bytes to be converted.The result is stored in d.

Parameters

Input

s_Start (WORD, INT, UINT)

Starting address

n_Chars (WORD, INT, UINT)

Number of bytes

Output

d (INT, DINT, UINT, UDINT)

Converted bytes

Remarks

ASCII HEX codes to express decimal characters:

Decimal characters

ASCII HEX code

SPACE+-0123456789

16#2016#2B16#2D16#3016#3116#3216#3316#3416#3516#3616#3716#3816#39

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the number of bytes specified by n_Chars is greater than the area specified by d

  • if the conversion result is greater than the data area specified by d

  • if ASCII characters other than 0–9, signs (+, ) or space is specified

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the number of bytes specified by n_Chars is greater than the area specified by d

  • if the conversion result is greater than the data area specified by d

  • if ASCII characters other than 0–9, signs (+, ) or space is specified

Example32-bit data, unsigned

Offset ASCII codes Dec. equivalent

Offset Converted decimal characters Decimal figure

s_Start

0

16#3620

6

Þ

d

0

16#FF9C

65436

1

16#3435

45

1

2

16#3633

63

n_Chars

0

16#0006

Example32-bit data, signed

Offset ASCII codes Dec. equivalent

Offset Converted decimal characters Decimal figure

s_Start

0

16#2020

Þ

d

0

16#FF9C

-100

1

16#312D

1 -

1

2

16#3030

00

n_Chars

0

16#000A

Example32-bit data, unsigned

Offset ASCII codes Dec. equivalent

Offset Converted decimal characters Decimal figure

s_Start

0

16#3234

24

Þ

d

0

16#FF9C

4294967196

1

16#3439

49

1

16#FFFF

2

16#3639

69

2

3

16#3137

17

4

16#3639

69

n_Chars

0

16#000A

Example32-bit data, signed

Offset ASCII codes Dec. equivalent

Offset Converted decimal characters Decimal figure

s_Start

0

16#2020

Þ

d

0

16#FF9C

-100

1

16#2020

1

16#FFFF

2

16#2020

3

16#312D

4

16#3030

n_Chars

0

16#000A

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
		bStart: BOOL:=FALSE;
			(*activates the function*)
		wASCII_input: WORD:=16#3031;
		iConversion_result: INT:=0;
	END_VAR

POU body

When the variable bStart is set to TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,5,3,7,5,);
B(B_VARIN,,wASCII_input,11,4,13,6,);
B(B_VARIN,,2,11,5,13,7,);
B(B_VAROUT,,iConversion_result,23,4,25,6,);
B(B_F,FP_ASCII_TO_DEC!,,13,2,23,7,,?DEN?Ds_Start?Dn_Chars?AENO?Cd);
L(1,4,5,4);
L(7,4,13,4);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF (bStart) then
    FP_ASCII_TO_DEC(s_Start := wASCII_input, 
                    n_Chars := 2, 
                    d => iConversion_result);
END_IF;

Modified on: 2019-05-15Feedback on this pagePanasonic hotline