I'm developing a project in which it's supposed to use retentive areas of memory to store values which should be kept after turning the PLC off. I'm using the "RETAIN" keyword for this purpose, it does not work although I'm using the correct form of declaration as follows:
VAR_GLOBAL RETAIN
Var AT %MW0: WORD;
END_VAR
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
nobody else seems to have a solution, so let me try an answer.
On reading the post, three questions came up on me:
Which hardware do you use? Does this support RETAIN variables? (I know PLCs, which support a few bits only)
I think, it is not always possible to have a variable on a specific address as RETAIN. Some (or all??) PLCs may restrict the RETAIN address space. I normally use the RETAIN clause with symbolic variables only.
Why do you use the keyword "Var" as an identifier? This might confuse the compiler.
Try to declare the variable as
VAR_GLOBALRETAINΒ RetainVar:WORD;END_VAR
and put it to MW0, when you need it there.
Regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We had a unit, I think it was a Moeller/Microinnovations HMI/PLC that wouldn't retain values only to find out there was a bug in the firmware. When we updated the firmware it all worked out fine.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
read the documentation of the product to see if this product accepts retain variables or how to configure this variables. For example, with IFM PLC, there is a function block to use to declare retain variables.
look for a firmware update.
Hoping to be helpful, best regards
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In CoDeSys - and other IEC compliant PLCs -, there is no need to put variables to a certain address. Let the compiler allocate them. Access is working on the symbolic level only.
This is useful for RETAIN vars as well. The compiler knows, where to store it. MW0 as given in your example may be outside the battery buffered memory. You would have to study the system manual of the PLC to find out, which addresses are inside.
I use declarations with an absolute address with IO only. This works fine for lots of years now.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I also had the same issue in our HMI, At last we could able to manage by writing in a .ini file externally.
Hope your HMI also have a runtime/firmware to run the codesys application. Try to shutdown the runtime/firmware properly in order to retain the values. If that works, there is a problem in your runtime/firmware.
Thanks and Regards,
Rajesh G
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm developing a project in which it's supposed to use retentive areas of memory to store values which should be kept after turning the PLC off. I'm using the "RETAIN" keyword for this purpose, it does not work although I'm using the correct form of declaration as follows:
VAR_GLOBAL RETAIN
Var AT %MW0: WORD;
END_VAR
Hi,
nobody else seems to have a solution, so let me try an answer.
On reading the post, three questions came up on me:
Which hardware do you use? Does this support RETAIN variables? (I know PLCs, which support a few bits only)
I think, it is not always possible to have a variable on a specific address as RETAIN. Some (or all??) PLCs may restrict the RETAIN address space. I normally use the RETAIN clause with symbolic variables only.
Why do you use the keyword "Var" as an identifier? This might confuse the compiler.
Try to declare the variable as
and put it to MW0, when you need it there.
Regards
We had a unit, I think it was a Moeller/Microinnovations HMI/PLC that wouldn't retain values only to find out there was a bug in the firmware. When we updated the firmware it all worked out fine.
I think you have several ways of search :
read the documentation of the product to see if this product accepts retain variables or how to configure this variables. For example, with IFM PLC, there is a function block to use to declare retain variables.
look for a firmware update.
Hoping to be helpful, best regards
This is just an example to clarify how I declare variables in my application
and put it to MW0, when you need it there.
Regards
Why you are declaring the variable without address. "RetainVar: WORD;" Why don't you declare it as "RetainVar AT %MW0: WORD;"
the retain does not work when you change the program, did you set retain memory correct?
In CoDeSys - and other IEC compliant PLCs -, there is no need to put variables to a certain address. Let the compiler allocate them. Access is working on the symbolic level only.
This is useful for RETAIN vars as well. The compiler knows, where to store it. MW0 as given in your example may be outside the battery buffered memory. You would have to study the system manual of the PLC to find out, which addresses are inside.
I use declarations with an absolute address with IO only. This works fine for lots of years now.
yeah rolf you are good, however on modbus it is needed to use markers.
What hardware are you using? We use Modbus in Moeller controllers without using markers. But we do have to use function blocks.
Hi shooter,
maybe Modbus requires markers, don't know (never used this by now). But - did Shohadawy talk about Modbus?
Rolf
Hello All,
I also had the same issue in our HMI, At last we could able to manage by writing in a .ini file externally.
Hope your HMI also have a runtime/firmware to run the codesys application. Try to shutdown the runtime/firmware properly in order to retain the values. If that works, there is a problem in your runtime/firmware.
Thanks and Regards,
Rajesh G