Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

__vfInit in Element Collections Example

asnik
2020-09-20
2022-11-26
  • asnik - 2020-09-20

    Hello, i am unable to compile Element Collections Example because Codesys (3.5.10, 3.5.14.10, 3.5.14.30) does not recognize pInstance^.__vfInit();
    __in MyElementFactory.Create with C0004 and C0046 errors.
    What could be the reason?

     
  • i-campbell

    i-campbell - 2020-09-20

    Are they just precompile errors? It should still compile.

     
  • asnik - 2020-09-20

    Yes, indeed, thanks!

     
  • michaelADE - 2021-06-17

    Hey, I know that this is an old topic, but was useful to me too knowing this error wouldn't actually prevent the system from running.

    However, this means that there is now always an error in my code. is there any way to hide this error? I have found there is the {warning disable} command but it doesn't appear to work for errors.

     
    πŸ‘
    1
  • rlie - 2022-11-24

    Hello,

    It seems that with {implicit on} it is managed by the compiler.

     
    πŸ‘
    1

    Last edit: rlie 2022-11-24
  • Strucc.c

    Strucc.c - 2022-11-26

    Interesting topic... Can we please get an update or a little bit more explanation of these former system calls - used mostly by library developers?

    As far as I understand, __vfInit() is to be called on "typed" pointers, typically on pointers to function block types, to execute the init sequence, ie. variable initialization.

    So... in theory all 3 alternatives should work the same:

    Declaration:

    PROGRAM PLC_PRG
    VAR
        // Static declaration
        E0      :   FB_TEST;
    
        // Dynamic declaration to be used by __NEW()
        pE1     :   POINTER TO FB_TEST;
        E1      :   REFERENCE TO FB_TEST;
    
        // Dynamic declaration
        pE2     :   POINTER TO FB_TEST;
        E2      :   REFERENCE TO FB_TEST;
    
        xInit   :   BOOL := TRUE;
        RES     :   RTS_IEC_RESULT;
    END_VAR
    

    Code:

    IF xInit THEN
    
        // This requires "dynamic memory allocation" option in the application
        pE1 :=  __NEW(FB_TEST);
        E1  REF=    pE1^;
    
        pE2     :=  SysMem.SysMemAllocData('FB_ENTRY Whatever', SIZEOF(FB_TEST), ADR(RES));
        {implicit on}
        pE2^.__vfInit();
        pE2^.FB_Init(TRUE, FALSE);
        {implicit off}
        E2  REF=    pE2^;
    
        xInit := FALSE;
    END_IF
    

    Question:
    1. Is this still correct to use vfInit() in library development (so that it doesn't depend on "Dynamic memory allocation" )?
    2. Is it OK to use SysMem, or is there a better wrapping platform for such purpose? (also from the library development aspect)

     

    Last edit: Strucc.c 2022-11-26

Log in to post a comment.