Join us today!
Notifications
Clear all
Clearing memory area of a Structure or an Array in TwinCAT
Tips & Tricks
1
Posts
1
Users
1
Reactions
554
Views
Sep 21, 2022 1:22 pm
(@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
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
Reply
Treyem reacted
Topic Tags
Forum Jump:
Forum Information
- 17 Forums
- 265 Topics
- 932 Posts
- 1 Online
- 689 Members
Our newest member: nominal
Forum Icons:
Forum contains no unread posts
Forum contains unread posts
Topic Icons:
Not Replied
Replied
Active
Hot
Sticky
Unapproved
Solved
Private
Closed