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

About __POUNAME() behavior

void
2021-12-13
2021-12-28
  • void - 2021-12-13

    Hello, I have written a custom logger and wanted to add the name of POUs as the pszComponent for easier debugging.

    I wrote a custom FB_init which accepts as input the name of the POU as a string and encountered puzzling behavior (to me at least).

    Could someone explain to me why the following compiles

    VAR
      name : STRING := __POUNAME();
      test : FB_logAdd(sCmpName:=name);
    END_VAR
    

    but the following

    VAR
      test : FB_logAdd(sCmpName:=__POUNAME());
    END_VAR
    

    throws the following compiler error?

    [ERROR]         Internal error:System.NullReferenceException: Object reference not set to an instance of an object.    at _3S.CoDeSys.LanguageModelManager.CompileContext.NeedsExternalFunctionCall(IOperatorExpression op, ICompiledType type, String& stFunctionName, TypeClass& tcWithType)    at _3S.CoDeSys.Compiler35160.ExpressionTypifier.(_IOperatorExpression )    at _3S.CoDeSys.LanguageModelManager.OperatorExpression.Accept(IExprementVisitor visitor)    at _3S.CoDeSys.Compiler35160.InterfaceCompiler.(_IVariable , _ISignature , ISignature , ISignature , IScope5 , _ICompileContext , IList`1 , IVariable[] , ExpressionTypifier , TypeChecker , ErrorVisitor )    at _3S.CoDeSys.Compiler35160.InterfaceCompiler.(IList`1& , IVariable[] , _IVariable , IScope5 , _ICompileContext , _ISignature , ISignature , ISignature , ExpressionTypifier , TypeChecker , ErrorVisitor )    at _3S.CoDeSys.Compiler35160.InterfaceCompiler.(_IVariable , IScope5 , _ICompileContext , _ISignature , ISignature , ISignature , ExpressionTypifier , TypeChecker , ErrorVisitor )    at _3S.CoDeSys.Compiler35160.InterfaceCompiler.(_IVariable , IScope5 , _ICompileContext , _ISignature , ExpressionTypifier , TypeChecker , ErrorVisitor , ISignature , ISignature )    at _3S.CoDeSys.Compiler35160.InterfaceCompiler.(_IVariable , IScope5 , _ICompileContext , _ISignature )    at _3S.CoDeSys.Compiler35160.InterfaceCompiler.(_ISignature , IScope5 , _ICompileContext )    at _3S.CoDeSys.Compiler35160.Compiler.(_ICompileContext , _IPreCompileContext , _IPreCompileContext , _ICompileContext , Boolean , Boolean , Boolean& , IProgressCallback )    at _3S.CoDeSys.Compiler35160.Compiler.(_ICompileContext , Boolean , Boolean , _IPreCompileContext , _IPreCompileContext , _ICompileContext , Boolean , Boolean& , IProgressCallback )    at _3S.CoDeSys.Compiler35160.Compiler.(Guid , Boolean , Boolean , Boolean , Boolean& , _ICompileContext& , _ICompileContext& , IProgressCallback , Boolean , Boolean , Boolean )
    


    Is it because __POUNAME() behaves like a function block instead of a function like I assumed?

    Which is why

    VAR
      test : FB_logAdd(pCmpName:=ADR(__POUNAME()));
    END_VAR
    

    also works if I change the input to a string pointer?

     

    Last edit: void 2021-12-13
  • dFx

    dFx - 2021-12-17

    I think the issue is that the compiler cannot take a function as a value/variable for a function block input in a declaration.
    When you do the first and 3rd declaration, you link the input to a variable. But with 2nd one, you link it to the result of a function.

     
    πŸ‘
    1

Log in to post a comment.