admin 发表于 6 天前

通过程序获取任务Task周期

前言
再分享一个实际项目常用的程序段,Codesys下通过程序获取任务Task周期。(Tips:文章持续输出中~~~)

正文    
先看功能效果:


需要加载以下库:
[*]1.SysTypes
[*]2.CmpIecTask
添加程序 Pro_SysMessage

PROGRAM Pro_SysMessage
VAR
      //获取Task实时数据
      ahTaskHandle: ARRAY OF SysTypes.RTS_IEC_HANDLE ;
      aResultList   : ARRAY OF SysTypes.RTS_IEC_RESULT ;
      aResult       : ARRAY OF SysTypes.RTS_IEC_RESULT ;
      aTaskInfo   : ARRAY OF POINTER TO CmpIecTask.Task_Info2 ;
END_VAR

ahTaskHandle := CmpIecTask.IecTaskGetFirst(pszAppName:= ADR('Application'), pResult:= ADR(aResult));
ahTaskHandle := CmpIecTask.IecTaskGetNext(pszAppName:= ADR('Application'),hPrevIecTask := ahTaskHandle, pResult:= ADR(aResult));      
ahTaskHandle := CmpIecTask.IecTaskGetNext(pszAppName:= ADR('Application'),hPrevIecTask := ahTaskHandle, pResult:= ADR(aResult));
ahTaskHandle := CmpIecTask.IecTaskGetNext(pszAppName:= ADR('Application'),hPrevIecTask := ahTaskHandle, pResult:= ADR(aResult));
ahTaskHandle := CmpIecTask.IecTaskGetNext(pszAppName:= ADR('Application'),hPrevIecTask := ahTaskHandle, pResult:= ADR(aResult));
ahTaskHandle := CmpIecTask.IecTaskGetNext(pszAppName:= ADR('Application'),hPrevIecTask := ahTaskHandle, pResult:= ADR(aResult));

aTaskInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := ahTaskHandle,pResult:= aResultList);
aTaskInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := ahTaskHandle,pResult:= aResultList);
aTaskInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := ahTaskHandle,pResult:= aResultList);
aTaskInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := ahTaskHandle,pResult:= aResultList);
aTaskInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := ahTaskHandle,pResult:= aResultList);
aTaskInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := ahTaskHandle,pResult:= aResultList);

gModbusTCP.DiPLC_CycTime := DWORD_TO_DINT(aTaskInfo^.dwCycleTime);
gModbusTCP.DiPLC_CycTime := DWORD_TO_DINT(aTaskInfo^.dwCycleTime);
gModbusTCP.DiPLC_CycTime := DWORD_TO_DINT(aTaskInfo^.dwCycleTime);
gModbusTCP.DiPLC_CycTime := DWORD_TO_DINT(aTaskInfo^.dwCycleTime);
gModbusTCP.DiPLC_CycTime := DWORD_TO_DINT(aTaskInfo^.dwCycleTime);
gModbusTCP.DiPLC_CycTime := DWORD_TO_DINT(aTaskInfo^.dwCycleTime);


通过IecTaskGetFirst抓取Task句柄,配合IecTaskGetNext获取下一个。通过IecTaskGetInfo2得到对应Task信息。如上述程序中aTaskInfo^.dwCycleTime 就是实时扫描周期。在aTaskInfo^. 下还有以下常规的
[*]dwAverageCycleTime :平均扫描周期时间
[*]dwCycleCount : 扫描周期计数
[*]dwMaxCycleTime : 最大扫描周期
[*]dwMinCycleTime : 最大扫描周期
[*]更多请自行移步官网帮助
[*]https://content.helpme-codesys.com/en/libs/CmpIecTask/Current/Task_Info2.html#id1
结尾这个功能配合触摸屏上显示,可有效得帮忙排查控制器的实际程序运行情况。有需要的直接CV大法即可~拿走不谢~





页: [1]
查看完整版本: 通过程序获取任务Task周期