I am trying to get my head around the wonderful world of OOP in CODESYS. I currently have the following environment setup
Base_Analog_Manager is my parent FB and Level_Instrument_Manager extends the Base_Analog_Manager
Base_Analog_Manager makes use of the DUT DUT_Base_Analog and Level_Instrument_Manager makes use of DUT DUT_Level_Instrument which extends the DUT_Base_Analog
ITF_Level_Instrument extends ITF_Base_Analog
In my GVL I have a variable called IL101 that is of type DUT_Level_Instrument
Hopefully the above makes sense.
What I want to achieve is the following:
Place Level_Instrument_Manager and pass data of DUT type DUT_Level_Instrument (which should also contain DUT_Base_Analog as it extends it)
I want to pass the data as a Var_In_Out so that it can be passed from SCADA, read and written to, then passed back.
The problem that I am facing is:
- CODESYS throws errors and warnings when using Var_In_Out in the FB Base_Analog_Manager:
I don't understand how I can pass IL101's Data (DUT_Level_Instrument) to the In_Out of FB Level_Instrument_Manager when the data type is inherited from FB Base_Analog_Manager as data type DUT_Base_Analog
The above images show what I mean, would this even work?
I understand method extension and how to use that, but I don't understand how In_Out's work with extended DUTs.
Any guidance would be greately appreciated, I'm really struggling to work out if this is even doable.
Thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the extended function block (Level_Instrument_Manager), instead of using a call "Super^", I inserted the actual function block of it's parent and gave it an instance of "Super^". This then allowed my to interconnect the Var_In_Out and set the value as "Data", which the Level data type, but Codesys appears to be casting this to it's parent type and executing correctly. I'm assuming its truncating the memory of the Data variable so it can fit, because it's inherited it can only ever be larger, truncating to the parents length would be safe.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I am trying to get my head around the wonderful world of OOP in CODESYS. I currently have the following environment setup
Base_Analog_Manager is my parent FB and Level_Instrument_Manager extends the Base_Analog_Manager
Base_Analog_Manager makes use of the DUT DUT_Base_Analog and Level_Instrument_Manager makes use of DUT DUT_Level_Instrument which extends the DUT_Base_Analog
ITF_Level_Instrument extends ITF_Base_Analog
In my GVL I have a variable called IL101 that is of type DUT_Level_Instrument
Hopefully the above makes sense.
What I want to achieve is the following:
The problem that I am facing is:
- CODESYS throws errors and warnings when using Var_In_Out in the FB Base_Analog_Manager:
The above images show what I mean, would this even work?
I understand method extension and how to use that, but I don't understand how In_Out's work with extended DUTs.
Any guidance would be greately appreciated, I'm really struggling to work out if this is even doable.
Thanks in advance
I think I've answered my own question now.
In the extended function block (Level_Instrument_Manager), instead of using a call "Super^", I inserted the actual function block of it's parent and gave it an instance of "Super^". This then allowed my to interconnect the Var_In_Out and set the value as "Data", which the Level data type, but Codesys appears to be casting this to it's parent type and executing correctly. I'm assuming its truncating the memory of the Data variable so it can fit, because it's inherited it can only ever be larger, truncating to the parents length would be safe.