AreaOffs32_ToVar

Copies the content of an address to a variable with 32-bit offset

This function copies number of words defined by the size of the variable Var to the variable Var from the address determined by the memory area iArea and the address offset diOffs.

Parameters

Input

iArea (INT)

Value for the memory area1)

If iArea is a variable, then it must be located in the memory area DT or FL. This should be checked using a function that incorporates the FP Tool Library's functions Is_AreaDT or Is_AreaFL.

diOffs (DINT)

Offset for the starting 32-bit address of the memory area

Output

Var (ANY_SIMPLE_NOT_BOOL)

Variable to which the address's content is copied

Remarks

The values for iArea and diOffs can be supplied via the function GetPointer32. The value for iArea has to lie in the DT orFL area.

Value for the memory area1)

Flag memory areas

Available for FP7 only.

SYS_MEMORY_AREA_R

SYS_MEMORY_AREA_L

SYS_MEMORY_AREA_X

SYS_MEMORY_AREA_Y

Flags

SYS_MEMORY_AREA_WR

Set value timer/counter

SYS_MEMORY_AREA_SV

Elapsed value timer/counter

SYS_MEMORY_AREA_EV

Data registers

SYS_MEMORY_AREA_DT

Link flags

SYS_MEMORY_AREA_WL

Link registers

SYS_MEMORY_AREA_LD

File registers

SYS_MEMORY_AREA_FL

Input registers

SYS_MEMORY_AREA_WX

Output registers

SYS_MEMORY_AREA_WY

Example

Global variables

In the global variable list you define variables that can be accessed by all POUs in the project.

Here the variables RealArrayIn1 and RealArrayIn2 are assigned. They were declared in different memory areas on purpose to illustrate the efficacy of the function block CalcSum_REAL. The variables could just as well be declared In the POU header of the program Program_CalcSums.

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_EXTERNAL
		g_arArrayIn1: ARRAY [0..5] OF REAL:=[10.0,20.0,30.0,40.0,50.0,60.0];
			(*data field 1*)
	END_VAR
	VAR
		bStart: BOOL:=FALSE;
			(*activation*)
		rRealSum1: REAL:=0.0;
			(*sum of the elements of data field 1*)
		CalcSum_Real1: CalcSum_Real;
			(*instance of the user function block*)
		@'': @'';
	END_VAR

POU body

When the variable bSart is set to TRUE, the function block CalcSum_REAL is carried out. It calculates the sum of all elements of the data field RealArrayIn1 and writes the result to the variable RealSum1.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 8 ;
        NETWORK_BODY
B(B_CONTACT,,bStart,5,2,7,4,);
B(B_FB,CalcSum_Real!,CalcSum_Real1,22,1,32,5,,?BEN?Bp32ToDatafield?AENO?ArSum);
B(B_VARIN,,g_arArrayIn1,13,3,15,5,);
B(B_VAROUT,,rRealSum1,32,3,34,5,);
B(B_F,GetPointer32!,,15,3,22,5,,?D?C);
B(B_COMMENT,,10.0 + 20.0 + 30.0 + 40.0 + 50.0 + 60.0,21,5,32,7,);
B(B_COMMENT,,= 210.0,33,5,38,6,);
B(B_COMMENT,,if (bStart == TRUE):,2,5,13,6,);
L(7,3,22,3);
L(1,3,5,3);
L(1,0,1,8);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Example programming the user-defined function block CalcSum_REAL

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_INPUT
		p32ToDatafield: POINTER32;
			(*pointer on the data field for calculation*)
	END_VAR
	VAR_OUTPUT
		rSum: REAL:=0.0;
			(*calculate sum*)
	END_VAR
	VAR
		Sum_Operand: REAL:=0.0;
			(*inernal calculation of the sum*)
		In_Offs_Intern: DINT:=0;
			(*internal offset*)
		Idx: INT:=0;
			(*index*)
		@'': @'';
	END_VAR

LD body

  • Network 1:

    If the data field delivered does not lie in the DT or FL area, the ENO of the function block is set to FALSE and the processing ended.

  • Network 2: 4:

    Here the initializations for calculating the sum that follows is dealt with. Since variables of the class VAR_INPUT cannot be changed directly, the input variable In_Offset has to be copied to the internal variable In_Offs_intern.

    see also: Var_ToAreaOffs32

  • Network 5: 8:

    Loop for the sum calculation.

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,Is_AreaDT!,,12,0,18,2,,?D?C);
B(B_VARIN,,p32ToDatafield.iArea,9,1,11,3,);
B(B_F,Is_AreaFL!,,12,3,18,5,,?D?C);
B(B_F,@AND-2!,,19,1,24,4,NN,?D?D?C);
B(B_F,E_MOVE!,,29,0,35,4,,?DEN?D?AENO?C);
B(B_VARIN,,FALSE,27,2,29,4,);
B(B_VAROUT,,ENO,35,2,37,4,);
B(B_RETURN,,,36,1,38,3,);
L(12,2,12,4);
L(12,1,12,2);
L(11,2,12,2);
L(18,1,18,2);
L(18,2,19,2);
L(18,3,18,4);
L(18,3,19,3);
L(35,2,36,2);
L(24,2,29,2);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 2 ;
        NETWORK_BODY
B(B_VARIN,,p32ToDatafield.diOffset,18,0,20,2,);
B(B_VAROUT,,In_Offs_Intern,20,0,22,2,);
L(1,0,1,2);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 2 ;
        NETWORK_BODY
B(B_VARIN,,0.0,18,0,20,2,);
B(B_VAROUT,,rSum,20,0,22,2,);
L(1,0,1,2);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 2 ;
        NETWORK_BODY
B(B_VARIN,,1,18,0,20,2,);
B(B_VAROUT,,Idx,20,0,22,2,);
L(1,0,1,2);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL := Lbl1: ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 4 ;
        NETWORK_BODY
B(B_F,AreaOffs32_ToVar!,,17,0,27,4,,?DiArea?DdiOffs?C@'Var');
B(B_VARIN,,p32ToDatafield.iArea,15,1,17,3,);
B(B_VAROUT,,Sum_Operand,27,1,29,3,);
B(B_VARIN,,In_Offs_Intern,15,2,17,4,);
L(1,0,1,4);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 3 ;
        NETWORK_BODY
B(B_F,@ADD-2!,,17,0,22,3,,?D?D?C);
B(B_VARIN,,rSum,15,0,17,2,);
B(B_VARIN,,Sum_Operand,15,1,17,3,);
B(B_VAROUT,,rSum,22,0,24,2,);
L(1,0,1,3);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 3 ;
        NETWORK_BODY
B(B_F,Size_Of_Var!,,17,1,24,3,,?D?C);
B(B_VARIN,,Sum_Operand,15,1,17,3,);
B(B_F,@ADD-2!,,32,0,37,3,,?D?D?C);
B(B_VARIN,,In_Offs_Intern,30,0,32,2,);
B(B_VAROUT,,In_Offs_Intern,37,0,39,2,);
B(B_F,INT_TO_DINT!,,24,1,32,3,,?D?C);
L(1,0,1,3);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,@LT-2!,,13,1,18,4,,?D?D?C);
B(B_VARIN,,p32ToDatafield.diSize,11,2,13,4,);
B(B_F,E_ADD-2!,,22,0,28,5,,?DEN?D?D?AENO?C);
B(B_VARIN,,1,20,3,22,5,);
B(B_VAROUT,,Idx,28,2,30,4,);
B(B_VARIN,,Idx,20,2,22,4,);
B(B_JUMP,,Lbl1,28,1,30,3,);
B(B_VARIN,,Idx,3,1,5,3,);
B(B_F,INT_TO_DINT!,,5,1,13,3,,?D?C);
L(18,2,22,2);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Modified on: 2020-10-01Feedback on this pagePanasonic hotline