aitorbarrena - 2020-04-01

Hello,
I'm trying to do a university project in which I will use Codesys to program some logics.
The runtime is running in a Linux PC.

As you can see in the attachments, in Codesys y will use a structure which holds all the variables of a function block that I will try configure as symbols so that the can be read and written from the runtime. As seen in the image, I'm trying to read Var1, Var2,... names. So that later y can get the handle of this nodes.

For doing that I am using this code;

~~~
RTS_RESULT result;
RTS_HANDLE hNode;
VariableInformationStruct2 VarInfo;
RTS_HANDLE hInterface = RTS_INVALID_HANDLE;
TypeClass3 varType;
int i;
char szNodeName[512];
TypeDescAsUnion typeDesc;
RTS_HANDLE hTypeNode;
RTS_HANDLE hElemNode;


hNode = CAL_IecVarAccGetNode3(szName, &hInterface, &VarInfo, &result);
varType = CAL_IecVarAccGetTypeClass3(hInterface, hNode, &VarInfo, &result);


CAL_SysOutPrintf("%s: Expand structure %s\n", COMPONENT_NAME, szName);

hTypeNode = CAL_IecVarAccGetTypeNode3(hInterface, hNode, &VarInfo, &result);

memset(&typeDesc, 0, sizeof(typeDesc));
CAL_IecVarAccGetTypeDesc(hInterface, hTypeNode, &typeDesc);

typeDesc._union._struct._Components = (IBaseTreeNode **)CAL_SysMemAllocData(COMPONENT_NAME, typeDesc._union._struct._iComponents * sizeof(IBaseTreeNode*), &result);
CAL_SysOutPrintf("Res %d\n",result);//Result is 0.

result = CAL_IecVarAccGetTypeDesc(hInterface, hTypeNode, &typeDesc);
if ( result == ERR_OK)
{
    for (i=0; i<typeDesc._union._struct._iComponents; i++)
    {
    //IN THE LINE BELOW AN ERROR HAPPENS AND RUNTIME GETS BLOCKED.
        hElemNode = (RTS_HANDLE)typeDesc._union._struct._Components[i];
        char* pElemName = CAL_IecVarAccGetNodeName(hInterface, hElemNode, &result);


    }
}
CAL_SysMemFreeData(COMPONENT_NAME, typeDesc._union._struct._Components);

~~~

When running this code, runtime gets blocked when trying to get handle from typeDesc._union._struct._Components[i].

Can someone tell me why is this happening.

Thank you!

Aitor