Join us today!

Clearing memory are...
 
Notifications
Clear all

Clearing memory area of a Structure or an Array in TwinCAT

1 Posts
1 Users
1 Reactions
614 Views
TwinControls
Posts: 71
Admin
Topic starter
(@beckhoffsupport)
Member
Joined: 2 years ago

MEMSET function from the Tc2_System library allows us to set a particular value to memory areas of the PLC variables. The code below shows how we can set 0 (zero) to memory address of a structure or an array. 

 

ST_HistorianDataTags: 

TYPE ST_HistorianDataTags :
STRUCT
	nCounter : INT;
	bSystemReady : BOOL;
	fConveyorSpeed : REAL;
END_STRUCT
END_TYPE

MAIN program: 

PROGRAM MAIN
VAR
	stHistorianDataTags : ST_HistorianDataTags;
	aHistorianData : ARRAY [1..50] OF ST_HistorianDataTags;
	
	bClearArrayData : BOOL;
	bClearStructure : BOOL;
	nMEMSETResult : UDINT; // > 0 - If successful, the number of bytes that have been set (n). 0 - Incorrect parameter values. destAddr == 0 or n == 0
	bClearingSucessful : BOOL;
END_VAR
IF bClearArrayData THEN
	bClearingSucessful := FALSE;
	
	//The function MEMSET allows PLC variables in a particular memory area to be set to a particular value.
	nMemSetResult := MEMSET(destAddr := ADR(aHistorianData), fillByte := 0, n:= SIZEOF(aHistorianData));
				   
	bClearingSucessful := nMemSetResult > 0;
	bClearArrayData	:= FALSE;
END_IF

IF bClearStructure THEN
	bClearingSucessful := FALSE;
	
	//The function MEMSET allows PLC variables in a particular memory area to be set to a particular value.
	nMemSetResult := MEMSET(destAddr := ADR(stHistorianDataTags), fillByte := 0, n := SIZEOF(stHistorianDataTags));
	
	bClearingSucessful := nMemSetResult > 0;		
	bClearStructure := FALSE;
END_IF

 

 

Reply
Share: