CXA_Datalayer: How to create a remote device via PLC?

Best reply by CodeShepherd

See this post for another example and for your case see my working example below:

Declaration:

 

PROGRAM PROG_comm_datalayer_remote_ConfigItem
VAR
	fbConfigItem: CXA_AutomationCore_fbs.comm_datalayer_remote_ConfigItem; //Flatbuffer function out of CXA_Automationcore_fbs
	fbBuilder: flatbuffers.FlatBufferBuilder;     // Declare the flatbuffer builder out of CXA_Flatbuffers
	fbDL_CreateNodeValue: DL_CreateNodeValue; //Funktion block to write an flatbuffer out of CXA_Datalayer
	bExecute: BOOL;
	bDone: BOOL;
	bActive: BOOL;
	bError: BOOL;
	ErrorID: CXA_Datalayer.ERROR_CODE;
	ErrorIdent: CXA_Datalayer.ERROR_STRUCT;
	fbValueIn: CXA_Datalayer.DL_NodeValue;
	fbValueOut: CXA_Datalayer.DL_NodeValue;
	bStart_write: BOOL;
	udiName: UDINT;
	udiAddress: UDINT;
	strName: STRING := 'otherControl';
	strAddress: STRING := 'tcp://192.168.1.1:2069';
END_VAR

 

Implementation:

 

//////////////////Write values	/////////////////////////
IF bStart_write THEN
	fbBuilder(forceDefaults := TRUE); //Start flatbuffer builder and load with default values	
	udiName := fbBuilder.createString(strName); //Create flatbuffer offset
	udiAddress := fbBuilder.createString(strAddress); //Create flatbuffer offset
	fbConfigItem.startConfigItem(fbBuilder); //Start flatbuffer function using the builder
	fbConfigItem.addName(udiName); //Add offset to the flatbuffer
	fbConfigItem.addAddress(udiAddress); //Add offset to the flatbuffer
	fbBuilder.finish(fbConfigItem.endConfigItem()); // Finish complete builder and closing the fbConfigItem
  	fbValueIn.SetFlatbuffer(fbBuilder); //Set flatbuffer out of the builder in the variable to be written
	bExecute := TRUE;
	bStart_write := FALSE;
END_IF

fbDL_CreateNodeValue(
	Execute:= bExecute, 
	Done=> bDone, 
	Active=> bActive, 
	Error=> bError, 
	ErrorID=> ErrorID, 
	ErrorIdent=> ErrorIdent, 
	ClientId:= , 
	NodeName:= 'devices/remotes', //Path of the node that should be written
	NodeValueIn:= fbValueIn, 
	NodeValueOut:= fbValueOut);

 

View original
3 replies