Change global.var variable value from modbus

Have X20CP0410 CPU, and have variables thats are Retain so the CPU remember the var values on warm restart.
But if I have change som values from modbus and then need to a change something in the program then the values are restord to default in my global.var there the var i declared.
Best solution to fix this?, I assume you can’t write to global.var when changing via modbus.

Hi Hans. Yes, the Retained checkbox is not perfect if you are actively transferring updates to the PLC. It works great once the source code is finalized, but it can still be an issue during development. It’s pretty easy to try making the variable you want Permanent, but then it will still revert on some transfers if global memory gets touched by changes.

A more complete solution is to use mpRecipe, but this requires a bit of programming - usually a dedicated task. Whenever the values you care about change, automatically Save with mpRecipe, and then automatically Load the file on Init to recover your data even if the Transfer cleared it. With this solution, the values will be preserved as long as the file on the User Partition is not lost.

2 Likes

Are there more examples of how to do this than the example project?

Getting started with MpRecipe is described here. B&R Online Help. It is very easy.