1

I have a list of Ingredients where each Ingredient contains a structure of variables.

The structure of variables is common to all Ingredients; however, occasionally an Ingredient will have a unique variable, in which case the variable is not in the structure but defined as a class variable.

I have separated the Ingredients into classes in an attempt to use the factory pattern, 'Ingredient' being the base class and other derived classes with unique parameters and overridden methods.

When I create a list of Ingredients, only the structure of variables is passed to the list, and child ingredients' extra parameters are lost.

I cannot create a list of Ingredient interfaces because of the way the system persists objects - only instantiated objects may be persisted (stored to file).

Do I just add the parameters of the child class to the structure of variables even though the parameter won't be used in most cases? This seems 'clunky' to me, but I can't seem to think of another way to save the parameter data.

  • Have you tried [extending your structures](https://help.codesys.com/api-content/2/codesys/3.5.17.0/en/_cds_datatype_structure/#id1)? – Guiorgy Sep 02 '21 at 14:24

1 Answers1

0

You should be able to store Function Blocks as Persistent. From what I understand, you are trying to store a list of Interfaces in the Persistent memory. CODESYS always treats variables declared with the type of an interface as references, so instead of storing references (kinda like pointers) as persistent, store the initialized objects themselves and use their interfaces in code. If you do this, try to avoid creating big Function blocks, because the function block instance is stored entirely in permanent memory and not just the marked variable.

Guiorgy
  • 1,405
  • 9
  • 26
  • Thank you for your response. I've done just what you have said in persisting the initialized objects and on initialization have created a secondary list of interfaces (references, as you mentioned) that point to the list of initialized objects. In this way, I simply pass around the interface list and that works great! – Sean Barton Sep 09 '21 at 15:16
  • Glad that you found my Answer helpful. If this has solved your problem, please consider accepting this answer. ;) – Guiorgy Sep 10 '21 at 16:19