Dear Community User! We are updating our platform to a new system.
Read more: Important information on the platform change.

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

Reading cycle time

Reading cycle time

Fersträgen
Member

Hello

Is there a way to access a given task's cycle time so that it can be read as a variable in the PLC? I've been trying to use either common_scheduler_fbs_Task (from the CXA_AUTOMATIONCORE_FBS library)  or plc_cmp_datalayer_fbs_AppTaskInfo (from the CXA_PLC_FBS library), but when I change the corresponding task's cycle time, the values remain unchanged. The former yields 0, and the latter yields 20000, regardless of the cycle time. My cycle time is set to 20ms but, as I said, changing its value results in no change in the aforementioned variables. I feel like this should be something somewhat straightforward, but I'm probably doing something wrong. Also, apologies if this question has already been posted, but I couldn't find a solution for it, here in the forum. Many thanks in advance, for all your help.

4 REPLIES 4

bostroemc
Occasional Contributor

If you are only interested in the task interval, you can read it directly using functionality from library CXA_Datalayer:

VAR
	_readNode: ARRAY[0..9] OF DL_ReadNodeValue;
	_nodeValue: ARRAY[0..9] OF DL_NodeValue;
END_VAR

// Read node directly, access value
_readNode[1](Execute:=_execute, NodeName:='plc/app/Application/admin/task/MainTask/interval', NodeValue:=_nodeValue[1]);	
_nodeValue[1].GetValueUInt32(Value=>_info.Interval);

 

Library CXA_PLC_fbs is only required if the entire set of task information is to be read (as a flatbuffer).  In this case, read the node value as before, then use method plc_cmp_datalayer_fbs_AppTaskInfo.getRootAsAppTaskInfo to handle the flatbuffer.  Access individual elements of the complex type with the get-methods provided by plc_cmp_datalayer_fbs_AppTaskInfo.  (Note that in this case the method you require, getInterval, seems to be missing...)

PROGRAM PLC_PRG
VAR
	_appTaskInfo: plc_cmp_datalayer_fbs_AppTaskInfo;
	_info: TASK_INFO_TYPE;  // user-defined type
END_VAR

// Read flatbuffer and associated access helper functions
_readNode[0](Execute:=_execute, NodeName:='plc/app/Application/admin/task/MainTask', NodeValue:=_nodeValue[0]);	
_appTaskInfo.getRootAsAppTaskInfo(_nodeValue[0].getData(), _nodeValue[0].getSize());	

_info.Name:= _appTaskInfo.getName();
_info.Priority:= _appTaskInfo.getPriority();
_info.CycleTime:= _appTaskInfo.getCycleTime();
_info.CycleCount:= _appTaskInfo.getCycleCount();
_info.CycleTime_Avg:= _appTaskInfo.getAverageCycleTime();

task_info.png

read_node.png

Hello

Many thanks for your message, and apologies for the late reply. I've tried implementing what you've suggested, as per your annexed file, but the read value, using only CXA_Datalayer, does not change (it's always 0). Any thoughts on why this would be the case?

bostroemc
Occasional Contributor

Is your task named 'MainTask'?  If not, make sure to adjust the node string accordingly.  

Can you post your code?

HmiGuide
Community Moderator
Community Moderator

You can use the CoDeSys library: SysTask, which provides functions to create, change and get info of tasks.

PROGRAM PLC_PRG
VAR
	hTask:       SysTask.RTS_IEC_HANDLE; // task handle
	udiInterval: UDINT; // intervall in micro seconds
END_VAR

// **** Implementation ***
// get handle of current task
SysTaskGetCurrent(ADR(hTask));
// get task interval
SysTaskGetInterval(hTask, udiInterval);

 

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