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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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]Â Â Â Â Â Internalerror:System.NullReferenceException:Theobjectreferenceisnotsettoaninstanceofanobject.ved_3S.CoDeSys.ApplicationObject.NetVarPDOList.AddVariable(StringstVarName,ITypetype,IPrecompileScopescope,ApplicationObjectappl,IVariablevar,String&stError,HashSet`1hsRecursionCheck)ved_3S.CoDeSys.ApplicationObject.NetVarPDOList.AddVariable(StringstVarName,ITypetype,IPrecompileScopescope,ApplicationObjectappl,IVariablevar,String&stError,HashSet`1hsRecursionCheck)ved_3S.CoDeSys.ApplicationObject.NetVarManager.AddObject(NetVarObjectnwObject,String&stError)ved_3S.CoDeSys.ApplicationObject.NetVarProtocol.AddObject(NetVarObjectnwObject,String&stError)Â Â ved_3S.CoDeSys.ApplicationObject.NetVarLanguageModel.AddObject(NetVarObjectnwObject)ved_3S.CoDeSys.ApplicationObject.ApplicationObject.AddNetVarLanguageModel(XmlWriterxmlwriter)ved_3S.CoDeSys.ApplicationObject.ApplicationObject.GetLanguageModel()ved_3S.CoDeSys.ApplicationObject.ApplicationObject.GetStructuredLanguageModel(ILanguageModelBuilderlmbuilder)ved_3S.CoDeSys.LanguageModelManager.LanguageModelManagerConsolidated.PutLanguageModel(ILanguageModelProviderlanmodprov,BooleanbShowSyntaxErrors,BooleanforceCompleteLanguageModel)ved_3S.CoDeSys.ApplicationObject.ApplicationObject.OnBeforeCompile(Objectsender,CompileEventArgse)Â Â ved_3S.CoDeSys.Core.LanguageModel.CompileEventHandler.Invoke(Objectsender,CompileEventArgse)ved_3S.CoDeSys.LanguageModelManager.LanguageModelManagerConsolidated.OnBeforeCompile(CompileEventArgse)ved_3S.CoDeSys.LanguageModelManager.LanguageModelManagerConsolidated.RaiseAndCheckBeforeCompile(GuidguidApplication,IMessageCategorycmc)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[]&)Â Â Â Â Â Â Â Â Buildcomplete-- 1 errors, 0 warnings : no download possible!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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"
//LibraryENUM{attribute'qualified_only'}{attribute'strict'}TYPELibraryError:(  NO_ERROR:=0,  ERROR_1,  ERROR_2 //etc..);END_TYPE
//LibrarySTRUCTTYPECommonData:STRUCT  eError  :LibraryError;//ENUM  iDummy  :INT;    xDummy  :BOOL;END_STRUCTEND_TYPE
I was asking if typing your enum solves your problem, not what your problem is.
exemple :
TYPECOLOR :
(
  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 blackEND_TYPE
using this explicit type declaration in your library may help to compile your project.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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?
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?
Because your enum is in your library also I believe you need to include the library name.
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.
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.
Does strong typing the enums solve your problem ?
see Codesys online help, chapter explicit basic data type
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"
In Codesys Project with library installed
Not able to compile because of Library Enum inside the struct.
I was asking if typing your enum solves your problem, not what your problem is.
exemple :
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.
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.