AOI Instance: Where Do Local Variables Reside?

Grendizer

Member
Join Date
Apr 2012
Location
Toronto
Posts
88
Hey all,


I have an AOI with multiple instances created in my running project. The question i have is: where do Local variables of each instance live during the life of the PLC execution?


In C++, depending on the variables scope, the function's variables live in the memory, as long as the application is calling the function. Data is lost otherwise. Does the PLC treat the AOI's local variables the same?



Thanks,
 
No, the data is never lost. You can stop calling the AOI and start it again, you can power the PLC down and back up again - all tag values, from controller-scoped tags to program-scoped tags, to AOI inputs and outputs, to AOI local parameters - all of them will retain the data. The only* way any tag or parameter changes is if your logic changes it.


*to be completely accurate, there are other ways tag values can change, including:
- A user changing the tag using Logix software
- Another PLC writing to that tag
- The controller pre-scan operation, which resets OTE's and so forth
But in broad terms, no, your data will under no circumstances be lost.
 
^ right.

The lifetime of a local tag is as long as its owning AOI instance exists. You can remove a call to an AOI instance from code but leave the instance in the tag database, and its local data will persist, for example.

A C/C++ function’s local variables exist for as long as the stack frame for that function call is in context. Once the instruction pointer returns to the caller, the stack is “unwound” and that memory is soon reused by other calls.

If you prefer thinking of an AOI call as a C function, it would be as if the C compiler accounted for all the incoming, outgoing, in/out, and local variables and their types when it encountered your function definition, combined and declared these to be a UDT (hello Add-On Defined Types!) and reflexively required the call structure to contain a reference to instances of that generated type.

The AOI is really just an elaborate access control and update mechanism upon discrete instances of the Add-On Defined Type. This is why static declarations and more sophisticated class constructs still aren’t a thing in Logix.
 
Last edited:

Similar Topics

Exposing shades of “newbie”…. I haven’t used arrays much, and I think using one for multi-zone temperature control is probably the solution I...
Replies
12
Views
770
Hey! I couldn't find any answer for my question anywhere, so maybe You can help me. Most of the time I was working with Siemens. I created an AOI...
Replies
4
Views
1,211
I have an array of APO instances that I loop through each scan using a jump. I can see the logic definition of the AOI but there are no...
Replies
12
Views
3,428
Hi Hope you all are doing well. Iam working on a project with some AOI. I also hate no online edits... lol. My problem occurs when I use a UDT...
Replies
0
Views
1
Hi everyone, i have an issue with saving a changed value in an AOI, I am using L84E, Everytime i try to save my work to SD card, the program lost...
Replies
1
Views
51
Back
Top Bottom