FP_DEC_TO_ASCII

Decimal -> ASCII conversion

This FP instruction converts the decimal characters specified by s to ASCII codes if the trigger EN is TRUE. n_Chars specifies the number of bytes to be converted.The result is stored in the area specified by d_Start.

ASCII HEX codes to express decimal characters:

Decimal characters

ASCII HEX code

SPACE+-0123456789

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

Parameters

Input

s (INT, DINT, UINT, UDINT)

Input value

n_Chars (WORD, INT, UINT)

Number of bytes

Output

d_Start (WORD, INT, UINT)

Starting address of the data area for the results. The size is n_Bits * 2 words.

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

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

  • if the number of bytes of the conversion result is greater than the number of bytes specified by n_Chars.

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

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

  • if the number of bytes of the conversion result is greater than the number of bytes specified by n_Chars.

Example16-bit data, unsigned

Offset

Dec. characters

Decimal figure

Offset

Converted ASCII codes

Dec. equivalent

s

0

16#FF9C

65436

Þ

d_Start

0

16#3620

6

n_Chars

0

16#0006

1

16#3435

45

2

16#3633

63

Example16-bit data, signed

Offset

Dec. characters

Decimal figure

Offset

Converted ASCII codes

Dec. equivalent

s

0

16#FF9C

-100

Þ

d_Start

0

16#2020

n_Chars

0

16#0006

1

16#312D

1 -

2

16#3030

00

Example32-bit data, unsigned

Offset

Dec. characters

Decimal figure

Offset

Converted ASCII codes

Dec. equivalent

s

0

16#FF9C

4294967196

Þ

d_Start

0

16#3234

24

1

16#FFFF

1

16#3439

49

n_Chars

0

16#000A

2

16#3639

69

3

16#3137

17

4

16#3639

69

Example32-bit data, signed

Offset

Dec. characters

Decimal figure

Offset

Converted ASCII codes

Dec. equivalent

s

0

16#FF9C

-100

Þ

d_Start

0

16#2020

0

1

16#FFFF

1

16#2020

0

n_Chars

0

16#000A

2

16#2020

0

3

16#312D

1 -

4

16#3030

00

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;
		iInput: INT:=82;
		awResult: ARRAY [0..2] OF WORD:=[3(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 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 8 ;
        NETWORK_BODY
B(B_COMMENT,,After conversion: ø^awResult[0]=16#2020ø^awResult[1]=16#3238ø^awResult[2] is not written,24,1,39,5,);
B(B_CONTACT,,bStart,4,4,6,6,R);
B(B_F,FP_DEC_TO_ASCII!,,12,3,22,8,,?DEN?D@'s'?Dn_Chars?AENO?Cd_Start);
B(B_VARIN,,iInput,10,5,12,7,);
B(B_VAROUT,,awResult[0],22,5,24,7,);
B(B_VARIN,,4,10,6,12,8,);
L(1,0,1,8);
L(1,5,4,5);
L(6,5,12,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

if (DF(bStart)) then
	FP_DEC_TO_ASCII(s := iInput, n_Chars := 4,
	                d_Start => awResult[0]);
	(* After conversion: 
			awResult[0]=16#2020
			awResult[1]=16#3238
			awResult[2] is not written *)
end_if;

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