FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
10-24-2022 06:08 PM
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.
Solved! Go to Solution.
11-02-2022 09:01 PM
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();
11-22-2022 02:42 PM
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?
12-13-2022 09:24 PM
Is your task named 'MainTask'? If not, make sure to adjust the node string accordingly.
Can you post your code?
12-14-2022 10:00 AM
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);