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

ENUM in STRUCT

Anonymous
2019-05-02
2020-02-07
  • Anonymous - 2019-05-02

    Originally created by: palej

    Can there be ENUM in STRUCT? Because I'am getting a weird error from my library saying Instance of reference...

    I am just trying to make a simple struct DUT for logging

    TYPE sLogEvent :
    STRUCT
    LogID : WORD;
    LogTime: DATE_AND_TIME;
    LogType: ErrorLevelType;
    LogMessage: STRING(100);
    END_STRUCT
    END_TYPE


    If I comment out the LogType, it works, but with it, it doesn't:

    {attribute 'qualified_only'}
    {attribute 'strict'}
    TYPE ErrorLevelType :
    (
    NoError := 0,
    Debug := 1,
    Info := 2,
    Warning := 3,
    Error := 4,
    Critical := 5
    ) := NoError;
    END_TYPE

    What I am doing wrong?

    Thank you

     
  • Krowi - 2019-05-02

    I've added these 2 DUT's and used both and I'm not getting any errors. Do you have more code available or is this already causing an error?

     
  • Anonymous - 2019-05-02

    Originally created by: palej

    I have builded this in Codesys library, then "Save Project as Compiled library" -> then used the compiled library in other project in Network Variable List:

    EH_EventLog: MyCommonLibrary.sLogEvent;

    And when build my project, it says that error. If I comment out those two ENUMs from the MyCommonLibrary and save as compiled library and update the library file from my other project, the error is gone?

     
  • Lo5tNet - 2019-05-02

    Because your enum is in your library also I believe you need to include the library name.

    TYPE sLogEvent :
    STRUCT
    LogID : WORD;
    LogTime: DATE_AND_TIME;
    LogType: MyCommonLibrary.ErrorLevelType;
    LogMessage: STRING(100);
    END_STRUCT
    END_TYPE
    
     
  • Anonymous - 2019-05-03

    Originally created by: palej

    They are in same library. And I still did try that, and it doesn't recognize the library name when it is in it's own library.

     
  • lassepc - 2019-10-14

    Any solution available for this?

    I'm in kind of the same situation, when adding custom library structs (containing enums) to a network variable lists, compiling is not completed

    The 2 devices exchanging the NVL is in the same project, and the library is installed in the POU library manager.
    Linking the NVL to a external file makes no difference.
    If i change the enums to INT, compile is completed with no errors.

    [ERROR]         Internal error:System.NullReferenceException: The object reference is not set to an instance of an object.
    ved _3S.CoDeSys.ApplicationObject.NetVarPDOList.AddVariable(String stVarName, IType type, IPrecompileScope scope, ApplicationObject appl, IVariable var, String& stError, HashSet`1 hsRecursionCheck)
    ved _3S.CoDeSys.ApplicationObject.NetVarPDOList.AddVariable(String stVarName, IType type, IPrecompileScope scope, ApplicationObject appl, IVariable var, String& stError, HashSet`1 hsRecursionCheck)
    ved _3S.CoDeSys.ApplicationObject.NetVarManager.AddObject(NetVarObject nwObject, String& stError)
    ved _3S.CoDeSys.ApplicationObject.NetVarProtocol.AddObject(NetVarObject nwObject, String& stError)    ved _3S.CoDeSys.ApplicationObject.NetVarLanguageModel.AddObject(NetVarObject nwObject)
    ved _3S.CoDeSys.ApplicationObject.ApplicationObject.AddNetVarLanguageModel(XmlWriter xmlwriter)
    ved _3S.CoDeSys.ApplicationObject.ApplicationObject.GetLanguageModel()
    ved _3S.CoDeSys.ApplicationObject.ApplicationObject.GetStructuredLanguageModel(ILanguageModelBuilder lmbuilder)
    ved _3S.CoDeSys.LanguageModelManager.LanguageModelManagerConsolidated.PutLanguageModel(ILanguageModelProvider lanmodprov, Boolean bShowSyntaxErrors, Boolean forceCompleteLanguageModel)
    ved _3S.CoDeSys.ApplicationObject.ApplicationObject.OnBeforeCompile(Object sender, CompileEventArgs e)    ved _3S.CoDeSys.Core.LanguageModel.CompileEventHandler.Invoke(Object sender, CompileEventArgs e)
    ved _3S.CoDeSys.LanguageModelManager.LanguageModelManagerConsolidated.OnBeforeCompile(CompileEventArgs e)
    ved _3S.CoDeSys.LanguageModelManager.LanguageModelManagerConsolidated.RaiseAndCheckBeforeCompile(Guid guidApplication, IMessageCategory cmc)
    ved _3S.CoDeSys.LanguageModelManager.Compiler35110.Compiler.(_IPreCompileContext , Guid , Boolean , Boolean , Boolean , Boolean& , _ICompileContext& , _ICompileContext& , IProgressCallback , Boolean , Boolean )
    ved _3S.CoDeSys.LanguageModelManager.Compiler35110.Compiler.(Guid , Boolean , Boolean , Boolean , IOnlineChangeDetails& , IMessage[]& , IMessage[]& )
                    Build complete -- 1 errors, 0 warnings : no download possible!
    
     
  • lassepc - 2019-10-15

    dFx hat geschrieben:
    Does strong typing the enums solve your problem ?

    No, what i meant was: The variable which was declared as an enum, inside the struct, is changed to an INT.
    That is why i strongly suspect the library defined ENUM to be the cause of compile error, when it's part of a library defined STRUCT used in a network variable list.
    Maybe a code example will be more clear:

    In "CustomLibrary"

    //Library ENUM
    {attribute 'qualified_only'}
    {attribute 'strict'}
    TYPE LibraryError :
    (
       NO_ERROR := 0,
       ERROR_1,
       ERROR_2  //etc..
    );
    END_TYPE
    
    //Library STRUCT
    TYPE CommonData : 
    STRUCT
       eError   :LibraryError; // ENUM
       iDummy   :INT;   
       xDummy   :BOOL;
    END_STRUCT
    END_TYPE
    

    In Codesys Project with library installed

    VAR_GLOBAL //Global Variable list, setup as Network variable list UDP , MainTask, Cyclic Transmission
    stCommonData:CustomLibrary.CommonData;
    END_VAR
    

    Not able to compile because of Library Enum inside the struct.

     
  • dFx

    dFx - 2019-10-15

    I was asking if typing your enum solves your problem, not what your problem is.

    exemple :

    TYPE COLOR :
    (
        white := 16#FFFFFF00,
        yellow := 16#FFFFFF00,
        green := 16#FF00FF00,
        blue := 16#FF0000FF,
        black := 16#88000000
    ) DWORD := black; // Basic data type is DWORD, default initialization for all COLOR variables is black
    END_TYPE
    

    using this explicit type declaration in your library may help to compile your project.

     
  • lassepc - 2019-10-16

    dFx hat geschrieben:
    I was asking if typing your enum solves your problem, not what your problem is.
    using this explicit type declaration in your library may help to compile your project.

    Okay, i misunderstood.

    I've just tested your suggestion, but it doesn't solve the compile error in the network variable list.
    I should mention i get the "The object reference is not set to an instance of an object." dialog too.

     
  • lassepc - 2020-02-07

    The compile error was caused by the library "Project Information" setup.
    Changing the "LanguageModelAttribute" property from the default value "qualified-access-only" to "qualified-access-mandatory" solved the compile error, when declaring library structs with enums, in Network variable list NVL.

    Deleting the property gives the same result.

    IMG: Lib1.library

     

Log in to post a comment.