FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important
information on the platform change.
10-19-2023 11:03 AM - edited 10-19-2023 11:22 AM
Hello,
I would like to read the node 'system/state' (as highlighted below) by using DL_ReadNode to access the datalayer, yet I'm not sure which data type I should declare for the variables in the PLC program in Structured Text(ST).
In the Metadata of the node I found that the readType is stated in types/systemhandler/state as below highlighted.
Yet I've tried declaring the variables as string or create an enum list containing the states, none of them worked and DL_ReadNode returned the DL_TYPE_MISMATCH error.
Does anyone have any exprience on this and can shed some light?
Thank you!
Solved! Go to Solution.
10-23-2023 05:08 PM - edited 10-23-2023 05:11 PM
Hello,
From the documentation on DL_ReadNode: "This function must only be used on simple data types! For complex types please use DL_ReadNodeValue(). To use this function correctly you need to know the type of the returned value. If you don’t know the value type, the DL_ReadNodeValue() function will provide a NodeValue-object which can be used to request the specific type."
In your case, you will need to include the CXA_AUTOMATIONCORE_FBS library to access the system state flatbuffer definitions.
Here is an example...
Declaration:
PROGRAM PLC_PRG
VAR
Result: CXA_Datalayer.DL_RESULT;
m_fbReadNodeValue: CXA_Datalayer.DL_ReadNodeValue;
m_Execute : BOOL;
m_NodeValue : DL_NodeValue;
m_address : STRING;
fbs_system_state: common_systemhandler_fbs_CurrentState;
get_system_state: common_systemhandler_fbs_State;
END_VAR
Implementation:
m_address := 'system/state';
m_Execute := TRUE;
m_fbReadNodeValue(Execute:= m_Execute, NodeName:= m_address, NodeValue:= m_NodeValue);
IF m_fbReadNodeValue.Done = TRUE THEN
get_system_state.getRootAsState(m_NodeValue.GetData(), m_NodeValue.GetSize());
fbs_system_state := get_system_state.getState();
END_IF
IF (m_fbReadNodeValue.Done = TRUE) OR (m_fbReadNodeValue.Error = TRUE) THEN
m_Execute := FALSE;
m_fbReadNodeValue(Execute:= m_Execute, NodeName:= m_address, NodeValue:= m_NodeValue);
END_IF
See DL-ReadNode-DL-ReadNodeValue-in-CoDeSys for additional discussion on this topic.
10-24-2023 10:07 AM