cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Data type of the node 'system/state'

Data type of the node 'system/state'

TSY1BOX
Member

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).

TSY1BOX_0-1697705162659.png

In the Metadata of the node I found that the readType is stated in types/systemhandler/state as below highlighted.

TSY1BOX_1-1697705248571.png

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.

TSY1BOX_2-1697705595545.png

Does anyone have any exprience on this and can shed some light?

Thank you!

 

 

 

2 REPLIES 2

Sgilk
Contributor

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.

Hello @Sgilk,

Thank you so much for the explicit answer and the example, it works!

 

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist