How to register own component - CMAddComponent() or CMAddComponent2()

FPawlak
2026-02-27
2026-03-13
  • FPawlak - 2026-02-27

    Hi All,
    I wonder which way is correct or better?
    I would like to register my own component in order to use it in CMPLog. I can use CMAddComponent() or CMAddComponent2() to do it. The main difference is whether I provide udiCmpId myself or it will be generated by runtime. But I don't know which way is correct. Please look at those two examples below.
    I don't know if CMAddComponent2() is newer and then should be used?

    CMAddComponent() + providing my own udiCmpId

    //16#FFFF0000 for unknown
    myVendorId := 16#FFFF0000;
    myLibId := 1;
    
    myComponentId := myVendorId OR CMPID_IecCode OR myLibId;
    componentHandle := CMAddComponent(pszComponent:= 'myComponent', udiCmpId:= myComponentId, udiVersion:= 1, pResult:= ADR(result));
    
    
    
    IF componentHandle <> RTS_INVALID_HANDLE AND result = CmpErrors.Errors.ERR_OK THEN
        LogAdd2(
            hLogger:= STD_LOGGER, 
            udiCmpID:= myComponentId, 
            udiClassID:= CmpLog.LogClass.LOG_ERROR, 
            udiErrorID:= 0, 
            udiInfoID:= 0, 
            pszInfo:= 'myComponent regidtered succsefull.'
        );
    ELSE
        LogAdd2(
            hLogger:= STD_LOGGER, 
            udiCmpID:= CMPID_CmpMgr, 
            udiClassID:= CmpLog.LogClass.LOG_ERROR, 
            udiErrorID:= 0, 
            udiInfoID:= 0, 
            pszInfo:= 'Error while regidtering myComponent.');
    END_IF
    

    CMAddComponent2() + udiCmpId generated by runtime

    componentHandle := CMAddComponent2(pszComponent:= 'myComponent2', udiVersion:= 1, udiCmpId:= ADR(myComponentId), pResult:= ADR(result));
    
    
    IF componentHandle <> RTS_INVALID_HANDLE AND result = CmpErrors.Errors.ERR_OK THEN
        LogAdd2(
            hLogger:= STD_LOGGER, 
            udiCmpID:= myComponentId, 
            udiClassID:= CmpLog.LogClass.LOG_ERROR, 
            udiErrorID:= 0, 
            udiInfoID:= 0, 
            pszInfo:= 'myComponent2 regidtered succsefull.'
        );
    ELSE
        LogAdd2(
            hLogger:= STD_LOGGER, 
            udiCmpID:= CMPID_CmpMgr, 
            udiClassID:= CmpLog.LogClass.LOG_ERROR, 
            udiErrorID:= 0, 
            udiInfoID:= 0, 
            pszInfo:= 'Error while regidtering myComponent2.');
    END_IF
    
     

    Last edit: FPawlak 2026-02-27
  • FPawlak - 2026-03-13

    Hi,
    so really oneone has no idea which way is correct one? Or maybe both are okey if they work for me?

     

Log in to post a comment.