• Create a "Standard project" and select CODESYS Control Win V3 as the device.
  • Define the target system by means of the Network scan.



  • Open the Library Manager and add the following libraries:
    CompErrors
    CmpIecTask
    SysTypes2 Interfaces




  • Create a new POU named sc and a new task named MySecTask.
    Assign the POU SecTask to the task MySecTask and set the call interval to 50 milliseconds.




  • Adapt the POU SecTask as follows:


    Declaration

    VAR
        iIndex     :    INT;
        sIndex     :    STRING; 
    END_VAR

    Implementation

    FOR iIndex := 0 TO 1000 DO
        //Do something to raise the cycle time
        sIndex := INT_TO_STRING(iIndex);
    END_FOR

  • Adapt the POU  PLC_PRG as follows:


    Declaration

    VAR
        dwCycleTimeMainTask, dwCycleTimeSecTask    :    DWORD;        
        dwIntervalMainTask, dwIntervalSecTask      :    DWORD;
        sNameMainTask, sNameSecTask                :    STRING;
        hFirstTask, hSecTask                       :    RTS_IEC_HANDLE;
        iecResult                                  :    RTS_IEC_RESULT;
        sAppName                                   :    STRING := 'Application';
        pIecInfo                                   :    POINTER TO CmpIecTask.Task_Info2;
    END_VAR

    Implementation

    hFirstTask := CmpIecTask.IecTaskGetFirst(pszAppName := ADR(sAppName), pResult := ADR(iecResult));
    IF ((hFirstTask <> RTS_INVALID_HANDLE) AND (iecResult = CmpErrors.Errors.ERR_OK)) THEN
        pIecInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := hFirstTask, pResult := ADR(iecResult));
        dwIntervalMainTask := pIecInfo^.dwInterval;
        dwCycleTimeMainTask := pIecInfo^.dwCycleTime;
        sNameMainTask := pIecInfo^.pszName^;
        hSecTask := IecTaskGetNext(pszAppName := ADR(sAppName), hPrevIecTask := hFirstTask, pResult := ADR(iecResult));
        IF ((hSecTask <> RTS_INVALID_HANDLE) AND (iecResult = CmpErrors.Errors.ERR_OK)) THEN
            pIecInfo := CmpIecTask.IecTaskGetInfo3(hIecTask := hSecTask, pResult := ADR(iecResult));
            dwIntervalSecTask := pIecInfo^.dwInterval;
            dwCycleTimeSecTask := pIecInfo^.dwCycleTime;
            sNameSecTask := pIecInfo^.pszName^;
        END_IF
    END_IF


  • After you have uploaded and started the project on the controller, you can compare the values between the task configuration and the IEC code.









  • No labels