Replies: 3 comments 1 reply
-
Hi @PTKu, thanks for that topic. I'm not sure whether your Codesys example follows the ICE61131-3. I haven't found something in that direction (@theBadT could you provide any insights there?). But for classes, you could do in an applicative way:
Inherit your class from the Base class and implement the Init() and RunCyclicUseCode() method.
For sure there are some limitations (e.g. the init() method does not allow different interfaces. But basically that could be a workaround. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @sjuergen. You are right. We can initialize the code in the call tree of a program. However, the idea with the initialization at construction is that it would enforce the call of the init method (not initialized would produce compile time error). This would prevent declaring a variable/field that would not be properly initialized and thus avoid possible errors at runtime. It proved extremely useful for us in the past. You're also right that there is no such thing in the current IEC61131-3 specification. As a side note to IEC. They are releasing the standard at a cadence of about ten years (the next release is delayed by about three years), which is way too much for any language to progress in a meaningful way. I would not mind if you added something outside the standard;). It is really about making sure the initialization was called. It would not be necessary to add 'init' method to the language; maybe it would suffice to check that the 'init; was called before the instance was used. It could be enforced by a compiler analyzer. I am unsure about the implementation, as this would need to know the call path to determine that the instance was initialized, and it may get tricky. Probably the more straightforward way would be to require the initialization in the declaration. |
Beta Was this translation helpful? Give feedback.
-
@sjuergen, as far as I know, FB_init is implemented in CoDeSys and the derivatives like Beckhoff's TwinCAT platform. I know that there is a handful of people that use this kind of initialization on those platforms, so it might be worth considering something like that in AX as well. |
Beta Was this translation helpful? Give feedback.
-
We would like to initialize an object at declaration.
Something along the lines of https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_method_fb_init_fb_reinit.html.
Reason:
We would need to have control over the object construction at initialization. At present, it is possible to make assignments at declaration. We would need to have the possibility to execute a code to provide additional logic to initialize an object. This would allow initializing otherwise inaccessible members but also execute initialization logic.
Beta Was this translation helpful? Give feedback.
All reactions