Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  • 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


    Image Added

  • 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:



    Section
    Column
    width7

    Declaration

    Column
    width93
    Code Block
    themeConfluence
    VAR
        iIndex     :    INT;
        sIndex     :    STRING; 
    END_VAR




    Section
    Column
    width7

    Implementation

    Column
    width93
    Code Block
    themeConfluence
    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:



    Section
    Column
    width7

    Declaration

    Column
    width93
    Code Block
    themeConfluence
    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




    Section
    Column
    width7

    Implementation

    Column
    width93
    Code Block
    themeConfluence
    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




...