I am developping a project using Twincat3 and C# ADS for the HMI.
For structure purpose, i want to use Twincat POO. I am new to Twincat and dont understand how to connect nested child objects to my HMI using ADS handler.
I have 1 parent function block
//Example
FUNCTION_BLOCK FB_Parent
VAR
iParentVariable: INT;
END_VAR
and multiple child function block that extends FB_Parent
//Example
FUNCTION_BLOCK FB_Child
VAR
iChildVariable: INT;
END_VAR
In my program, i have an array of FB_Parent. On initialization command from my custom HMI (C#), i create new FB_Child dynamically:
// Example
fbChild := __NEW(FB_Child);
array[0] := fbChild^;
__DELETE(fbChild);
The problem is that I can’t create handler and access child variable from my HMI (C#):
client = new AdsClient
{
Timeout = 500
};
client.Connect(parameters.AmsNetID, parameters.AdsPort);
handler = client.CreateVariableHandle("PRG_MAIN.arrConveyors[0].iChildVariable");
How can i still use POO and dynamic object creation in Twincat and access child variable in C# trough ADS ?
Thanks for you help !
I tried to change the definition of my array:
- Using POINTER OF FB_Parent
- Using Interface instead of Parent class
Nothing worked.
Schupbach Loïc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.