DWORD_TO_STRING

DOUBLE WORD into STRING

The function DWORD_TO_STRING converts a value of the data type DWORD into a value of the data type STRING.

Generates a result string in right-aligned decimal representation, filled with leading spaces up to the predefined maximum number of characters.

Parameters

Input

Unnamed input (DWORD)
Input data type

Output

Unnamed output (STRING)
Conversion result

Remarks

When using the data type STRING with small PLCs like FP-e or FP0, make sure that the length of the result string is equal to or greater than the length of the source string.

Example

Input

Output defined as

Results in

16#ABCDEFFE

STRING[2]

'FE'

STRING[4]

'EFFE'

STRING[6]

'CDEFFE'

STRING[8]

'ABCDEFFE'

STRING[10]

'00ABCDEFFE'

STRING[12]

'0000ABCDEFFE'

and so on...

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 
		DWORD_value: DWORD:=0;
			(*example value: 16#ABCDEFFE*)
		result_string: STRING[10]:='';
			(*result: '00ABCDEFFE'*)
		@'': @'';
	END_VAR

The input variable DWORD_value of the data type DWORD is intialized by the value 16#ABCDEFFE. The output variable result_string is of the data type STRING[10]. It can store a maximum of 10 characters. Instead of using the variable DWORD_value, you can enter a constant directly at the function’s input contact in the body.

POU body

The DWORD_value of the data type DWORD is converted into STRING[10]. The converted value is written to result_string. When the variable DWORD_value = 16#ABCDEFFE, result_string shows '00ABCDEFFE'.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,DWORD_TO_STRING!,Instance,9,1,20,3,,?D?C);
B(B_VARIN,,DWORD_value,7,1,9,3,);
B(B_VAROUT,,result_string,20,1,22,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

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.

This example illustrates how you create STRING[10] out of the data type DWORD in which the leading part of the string '16#' is replaced by the string '0x'.

		VAR
		input_value: DWORD:=16#12345678;
		result_string: STRING[10]:='';
		@'': @'';
	END_VAR

In this example the input variable input_value of the data type DWORD and an output variable result_string of the data type STRING[10] are declared.

POU body

In carrying out the operation in question, the standard function REPLACE is attached to the function DWORD_TO_STRING. REPLACE replaces one section of a character string with another.

In the example, the output string of DWORD_TO_STRING function is added at input IN1 of the REPLACE function. At input IN2, the STRING constant '0x' is added as the replacement STRING. At the L input of REPLACE, the INT constant 3 determines the length of the STRING to be replaced. The P input determines the position at which the replacement begins. In this case it is the INT number 1. From the variable input_value = 16#12345678, the result_string = '0x12345678' results after undergoing the data type conversion and REPLACE function.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_F,DWORD_TO_STRING!,Instance,8,1,19,3,,?D?C);
B(B_VARIN,,input_value,6,1,8,3,);
B(B_VAROUT,,result_string,26,1,28,3,);
B(B_F,REPLACE!,Instance,20,0,26,6,,?DIN1?DIN2?DL?DP?C);
B(B_VARIN,,'0x',18,2,20,4,);
B(B_VARIN,,3,18,3,20,5,);
B(B_VARIN,,2,18,4,20,6,);
L(19,2,20,2);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Modified on: 2019-01-24Feedback on this pagePanasonic hotline