Track program change on WAGO PLC with CoDeSys

1.1k views Asked by At

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.

2

There are 2 answers

2
user2097818 On BEST ANSWER

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).

0
Steve Pfeifenroth On

If I understand you you only want to know like what version is running on the PLC and you want to track changes that you make? You can do it two ways:

Since it's a constant each time you make a change external to the PLC you roll the rev of a variable that is declared like SoftwareVersion :WORD := 100; and keep it in a Revision global list that you can add your notes to and change the version before downloading to PLC. You can also use the PLC summary area that has fields to enter the values and then you can read them through CoDeSys without software upload.

And of course the suggestion above can work.