Search code examples
codesys

Track program change on WAGO PLC with CoDeSys


I need to increment an integer value each time the PLC program is updated to track changes.

There are system events like online_change and before_download, but I have no idea how to implement their functions.

Also I need to save value between updates. I think the tracking variable should be created as RETAIN but not sure.


Solution

  • The variable declaration type should be VAR RETAIN PERSISTENT in your case. Variables declared under RETAIN only will lose their values (intentionally) with a program change.

    I believe the builtin Codesys library SysLibProjectInfo.lib has what you are looking for with the function SysGetProjectID. If you store SysGetProjectID as a RETAIN PERSISTENT and then compare against it, you can track changes (or, this unique value may be exactly what you wanted in the first place, without manually creating an ID).

    Note: Depending on how you declare your variables, changing the I/O configuration can have unexpected changes even on VAR RETAIN PERSISTENT variables (as all dynamically allocated addresses are shifted and may not point where they used to).