Incorrect/Unexpected POU Path Initialization

rickj
2020-11-12
2020-11-12
  • rickj - 2020-11-12

    I created a function block to initialize its Path string variable to the function block's path using the appropriate attribute pragmas as shown below. An instance of this function block in the main program is initialized to the correct and expected path.

    {attribute 'reflection'}
    FUNCTION_BLOCK PathTestFunctionFB 
    
    VAR
        {attribute 'instance-path'}
        {attribute 'noinit'}
        Path        : STRING(255);
    END_VAR
    

    I created a second function block in the same manner that also contains an instance of the first. An instance of this block, in the main program, and its instance of the first block are initialized correctly and as expected.

    {attribute 'reflection'}
    FUNCTION_BLOCK PathTestBaseFB
    VAR_INPUT
        PathTestFunction    : PathTestFunctionFB;
    END_VAR
    
    VAR
        {attribute 'instance-path'}
        {attribute 'noinit'}
        Path        : STRING(255);
    END_VAR
    

    I created a third function block which extends the second block as shown below. This block does not contain attribute pragmas or variable declarations. Instead, it inherits everything from the second function block. An instance of this block in the main program initializes both inherited path variables for Base and Function function blocks to the same value, which seems to be incorrect or at least unexpected.

    FUNCTION_BLOCK PathTestDerivedFB EXTENDS PathTestBaseFB
    

    An example project and screen shot of the initialized path variables are attached.

     

    Last edit: rickj 2020-11-12
  • rickj - 2020-11-12

    Is this a bug or correct behavior? If correct behavior then can someone explain why? I am working with a client who is making good use of this feature and I would like to give them a satisfactory when they ask me the above questions.

    We have an adequate work around so that's not a problem. However, they and I would like to have a better understanding of what's going on here and why. We want to have confidence that we are producing robust and quality applications for my client's customers.

    Any insight or information will be greatly appreciated.

     

    Last edit: rickj 2020-11-12

Log in to post a comment.