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

CXA_DataLayer: How to write a flatbuffer.

CXA_DataLayer: How to write a flatbuffer.

MHU
New Poster

I want to start a scheduler timer on the DataLayer. Path scheduler/tasks/ctrlXAutomation/info/duration/start.

 

1 REPLY 1

MHU
New Poster


With some great help and explanation it is working. It is good to share it also here the result of the working program.

Declaration:

 

PROGRAM StartTimerOnDL
VAR
  fbStartTimer : CXA_AutomationCore_fbs.common_scheduler_fbs_DurationTimer; // The type definition can be found in the references write type totally on the end.
  fbBuilder: flatbuffers.FlatBufferBuilder;     // Declare the flatbuffer builder
  fbDL_WriteNodeValue :  CXA_Datalayer.DL_WriteNodeValue; // Write the generated flatbuffer to the node
  bExecute_write : BOOL := FALSE; // Only execute once

  // By a complicated flatbuffer you must work with offset. Not necessary for this example.
	//fbOffset: UDINT;
  
    // Write node values
	strNodePath: STRING(255);       // Path in the DataLayer that you want to modify
	bStart_write: BOOL;             // Execute the function only once

  
  // Some variable to see the progress    
	writeNodeValue: CXA_Datalayer.DL_NodeValue;
  fbValueOut :  CXA_Datalayer.DL_NodeValue;
	bDone_write: BOOL;
	bActive_write: BOOL;
	ErrorID_write: CXA_Datalayer.ERROR_CODE;
	bError_write: BOOL;
	ErrorIdent_write: CXA_Datalayer.ERROR_STRUCT;
END_VAR

 

 

Implementation:

 

IF bStart_write THEN
  // Writing to the flatbuffer is started. The function is executed only once.
  fbBuilder(forceDefaults:=TRUE);      // Define the flatbuffer
  
  // 
  // For writing always the same sequence must be executed
  //   - Start builder
  //   - Add data
  //   - Finish builder
  //   - Set data from builder to the node value that must be written
  
  //fbOffset := fbStartTimer.createDurationTimer(fbBuilder, CXA_AutomationCore_fbs.common_scheduler_fbs_Timer.ALL);
  fbStartTimer.startDurationTimer(fbBuilder);
  fbStartTimer.addTimer(CXA_AutomationCore_fbs.common_scheduler_fbs_Timer.ALL);
  fbBuilder.finish(fbStartTimer.endDurationTimer()); // Finish complete builder and closing the startDurationTimer
  writeNodeValue.SetFlatbuffer(fbBuilder);
  
   // NodePath to create
    strNodePath := 'scheduler/tasks/ctrlXAutomation/info/duration/start';
    bExecute_write := TRUE;
    bStart_write := FALSE;
END_IF

fbDL_WriteNodeValue(
    Execute:= bExecute_write,
    Done=> bDone_write,
    Active=> bActive_write,
    Error=> bError_write,
    ErrorID=> ErrorID_write,
    ErrorIdent=> ErrorIdent_write,
    ClientId:=  ,
    NodeName:= strNodePath,
    NodeValueIn:= writeNodeValue,
    NodeValueOut:= fbValueOut);

IF fbDL_WriteNodeValue.Done THEN
  bExecute_write := FALSE;
END_IF


 

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