I’m pretty sure a rebuild can reinitialize retain PV (as I understand in the help). To make it sure it’s only reinitialized during intial installation I would recommend to pass the PV from retain to permanent.
Were they local or global? I’ve previously seen global retain variables reset during a transfer.
The theory I and my US support team had come up with is that the memory fragmentation had made it impossible for the changes i was making to global memory layout, by adding/removing variables, to make the copy of current values into new memory locations. It happened in frequently. There was a line in the help that seemed to indicate this wsas possible in rare circumstances, but I don’t remember where.
But we were also dealing with some extremely large memory structures.
Yes you are right, if you playing too much with adding / removing variables on the project without a rebuild. The memory could fragment then result in reset some variable due to memory reorganization by the compiler.
I only noticed it happening about twice per year, but many sw transfer in between..
Anyway.. apparently, the only solution to this issue seems to be using permanent variables. It’s also difficult to replicate the issue, so I guess it’s just a matter of waiting and see if it happens again..
Support and I had a theory that perhaps making sure the Global PV size allocated be 2x or more larger than what was actually used, minimized this. I.e. the larger make this area the more AR can re-organize it.
just for info, if anyone will have the same problem. after talking with local support, we found out that:
retain variables are actually not retain if a rebuild is done. considering how often I need to rebuild a project because of weird machine behavior, it’s not so rare. so retain variables are actually useless in my use-case.
an alternative solution would be to use a permanent variable, but my cpu does not support it. I honestly don’t understand how a 600€ cpu is not able to store ONE VARIABLE.
final solution will be to use a file with library dataObj and just store the value there.
Instead of building your own library/program check the ‘mappRecipe’ for saving machine configuration. B&R Online Help
Think you should also dive in to the reason you need a ‘rebuild’ for weird machine behavior. A rebuild is only needed if your change big things like AR/AS versions and not for code things (And even then its not mandatory) . So if the weird things start to happen during a normal update double check your pointer/memory initialization.
I see your point. I just didn’t have time to dive into detailed analysis of these erratic behaviors. I just rebuild and that’s it.
I already use mappRecipe but it’s not the solution I need for my case because the variable I need to save it’s a machine-specific counter, while configuration files could be used in different machines.
We use many Retain variables, and have observed that their values sometimes reset during a normal transfer, not only after a full rebuild.
What we’ve found is that if we perform a transfer followed by a reboot, the Retain values almost never reset when making small software changes. Larger rebuilds or major changes can still cause resets.
It’s not the most convenient method, but if preserving Retain values is critical, it has proven reliable.
ok but I don’t understand the value of using retain variables if their value is not always preserved. actually they seems quite “fragile”.. probably it’s just me, but I don’t see the point. infact there are also permanent variables (not on all CPUs)!
so I have normal variables, not so permanent ones, and permanent
If you need to save and read back on startup counter, I would recommend to use something like this json serializer / deserializer to save it on exit routine and load it when your plc is started.
I’ve never use this specific lib but I’ve used a similar one. You should be able to save / load a structure so if your counters are all in the same structure you can convert to string / load from string in 1 cycle time. Then you just have to handle the string to be write or read from a file.
B&R Online Help According to this is might keep some retained variables during a rebuild.
This is what i had previously experienced, especially when we were passing around archives of projects or not using the same file paths, if the temp/binaries aren’t at the same place or don’t exist, that’s basically a rebuild. So sometimes as my colleagues and I passed projects around, sometimes we’d have a rebuild and sometimes not, and sometimes we’d lose retained data and sometimes not. There definitely seemed to be a something related to Global PV and Global PV remanent sizes that related to if the data was retained. I.e. if there was enough room for the entire memory area to be cleanly copied into new contigous memory, we didn’t loose data.
We started using a hybrid process utitlizing timestamp for the first 4 bytes of a structure for retained data and mpRecipe storing the strucutre. We would update the timestamp efvery time we updated the strucutre and put a delay of like 30 seconds after the time stamp changed to trigger the save, or the machine successfully producting product. If on reboot we just loaded the mapp recipe if the timestamp was 0’d.