Read/Write DataLayer Structure for OPC UA Client from PLC
I would like to control the OPC UA Client App connect/disconnect from the PLC. I also want to read the client state to verify that the connect/disconnect occured. I have tried various fbs like DL_ReadNode, DL_ReadNodeValue, etc. but the data types are not correct and I get errors. When I try to write, to trigger the connect or disconnect commands, I get an error, 16#0D0A0201 that I cannot find in the documentation:
Are there any examples of how to do this? I have seen some other examples in the forum but they are associated with other function blocks that exist, like motion function blocks. How can I read/write objects (they look like JSON objects) in the datalayer from the PLC?
Â
Best reply by CodeShepherd
After adding a client, in my case done via ctrlX CORE WebUI using:
You can see for each method which data type needs to send to this node and how it is structured. For "Connect" and "Disconnect" it is just an empty write. See "Operations" = "write" and "References" = "":
Reading the state means reading an object of the type "types/opcuaclient/state". This is done via a flatbuffer:
Data Layer UI opcuaclient state
Declaration:
PROGRAM OPCUa_Client
VAR
fbClientState: CXA_OpcUaClient_fbs.comm_opcua_client_State; //Flatbuffer function out of CXA_Automationcore_fbs
fbDL_ReadNodeValue: DL_ReadNodeValue; //Funktion block to read an flatbuffer out of CXA_Datalayer
bReadExecute: BOOL;
bReadDone: BOOL;
bReadActive: BOOL;
bReadError: BOOL;
ReadErrorID: CXA_Datalayer.ERROR_CODE;
ReadErrorIdent: CXA_Datalayer.ERROR_STRUCT;
DataRead: CXA_Datalayer.DL_NodeValue;
strState: CXA_OpcUaClient_fbs.comm_opcua_client_ConnectionState;
END_VAR