C++-samples | Sample26: Order of execution in a task 1. The module requires a context-based parameter Sort order of task, which will automatically select PID_Ctx_TaskSortOrder as name. Note that the parameter must be an alias (specification) of data type UDINT: 2. Start the TMC Code Generator in order to obtain the standard implementation. 3. Since the code is modified in the next step, disable the code generation for this parameter now. 4. Make sure you accept the changes before restarting the TMC Code Generator: Take a look at the CPP module (SortOrderModule.cpp in the sample).
The instance of the smart pointer of the cyclic caller includes information data, including a field for the sorting order. The parameter value is stored in this field. /////////////////////////////////////////////////////////////////////////////// // Set parameters of CSortOrderModule BEGIN_SETOBJPARA_MAP(CSortOrderModule) SETOBJPARA_DATAAREA_MAP() /// SETOBJPARA_VALUE(PID_TcTraceLevel, m_TraceLevelMax) SETOBJPARA_ITFPTR(PID_Ctx_TaskOid, m_spCyclicCaller) /// SETOBJPARA_TYPE_CODE(PID_Ctx_TaskSortOrder, ULONG, m_spCyclicCaller.GetInfo()- >sortOrder=*p) //ADDED //generated code:
SETOBJPARA_VALUE(PID_Ctx_TaskSortOrder, m_TaskSortOrderContext1Parameter) END_SETOBJPARA_MAP() /////////////////////////////////////////////////////////////////////////////// // Get parameters of CSortOrderModule BEGIN_GETOBJPARA_MAP(CSortOrderModule) GETOBJPARA_DATAAREA_MAP() /// GETOBJPARA_VALUE(PID_TcTraceLevel, m_TraceLevelMax) GETOBJPARA_ITFPTR(PID_Ctx_TaskOid, m_spCyclicCaller) /// GETOBJPARA_TYPE_CODE(PID_Ctx_TaskSortOrder, ULONG, *p=m_spCyclicCaller.GetInfo()- >sortOrder) //ADDED //generated code: GETOBJPARA_VALUE(PID_Ctx_TaskSortOrder, m_TaskSortOrderContext1Parameter) END_GETOBJPARA_MAP() 5. In this sample the object name, ID and sort order are tracked cyclically:
TwinCAT 3 299 Version: 1.19.1