none
C# to VB

    Question

  • I have code that works in C# but when I convert it to VB it is not working right...

    so there much be something wrong with the vb conversion

    here is the c# code:

      static IList<IReference> references = null;
            static BaseObjectState Trigger;
            static IDictionary<NodeId, IList<IReference>> externalReferences1;
            public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
            { 
                lock (Lock)
                {
                    externalReferences1 = externalReferences;
    
                    Trigger = new BaseObjectState(null);
                    Trigger.NodeId = new NodeId(1, NamespaceIndex);
                    Trigger.BrowseName = new QualifiedName("Plant", NamespaceIndex);
                    Trigger.DisplayName = Trigger.BrowseName.Name;
                    Trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType;
                    // ensure trigger can be found via the server object.
                   
                    if (!externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, out references))
                    {
                        externalReferences1[ObjectIds.ObjectsFolder] = references = new List<IReference>();
                    }
    
                    Trigger.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder);
                    references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, Trigger.NodeId));
                    AddPredefinedNode(SystemContext, Trigger);
    
                    #region property
                    PropertyState property = new PropertyState(Trigger);
                    property.NodeId = new NodeId(2, NamespaceIndex);
                    property.BrowseName = new QualifiedName("Level", NamespaceIndex);
                    property.DisplayName = property.BrowseName.Name;
                    property.TypeDefinitionId = VariableTypeIds.PropertyType;
                    property.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                    property.DataType = DataTypeIds.Int32;
                    property.ValueRank = ValueRanks.Scalar;
                    property.ArrayDimensions = null;
                    // read able
                    property.OnSimpleReadValue = new NodeValueSimpleEventHandler(onRead);
                    // write able     
                    property.AccessLevel = AccessLevels.CurrentReadOrWrite;
                    property.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                    Trigger.AddChild(property);
                    AddPredefinedNode(SystemContext, property);
                    #endregion
                    // save in dictionary
                    // Assest
                    #region Assest
                    BaseObjectState Asset = new BaseObjectState(null);
                    Asset.NodeId = new NodeId(3, NamespaceIndex);
                    Asset.BrowseName = new QualifiedName("Asset", NamespaceIndex);
                    Asset.TypeDefinitionId = ObjectTypeIds.BaseEventType;
                    Asset.DisplayName = Asset.BrowseName.Name;
                    Trigger.AddChild(Asset);
                    AddPredefinedNode(SystemContext, Asset);
                    #endregion
                    // Flow Computer
                    #region MassFlow
                    PropertyState MassFlow = new PropertyState(Asset);
                    MassFlow.NodeId = new NodeId(4, NamespaceIndex);
                    MassFlow.BrowseName = new QualifiedName("MassFlow", NamespaceIndex);
                    MassFlow.DisplayName = MassFlow.BrowseName.Name;
                    MassFlow.TypeDefinitionId = VariableTypeIds.PropertyType;
                    MassFlow.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                    MassFlow.DataType = DataTypeIds.Int32;
                    MassFlow.ValueRank = ValueRanks.Scalar;
                    MassFlow.ArrayDimensions = null;
                    // read able
                    MassFlow.OnSimpleReadValue = new NodeValueSimpleEventHandler(onRead);
                    // write able     
                    // MassFlow.AccessLevel = AccessLevels.CurrentReadOrWrite;
                    //MassFlow.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                    Asset.AddChild(MassFlow);
                    AddPredefinedNode(SystemContext, MassFlow);
                    #endregion
                    #region temperature
                    PropertyState temperature = new PropertyState(Asset);
                    temperature.NodeId = new NodeId(5, NamespaceIndex);
                    temperature.BrowseName = new QualifiedName("Temperture", NamespaceIndex);
                    temperature.DisplayName = temperature.BrowseName.Name;
                    temperature.TypeDefinitionId = VariableTypeIds.PropertyType;
                    temperature.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                    temperature.DataType = DataTypeIds.Int32;
                    temperature.ValueRank = ValueRanks.Scalar;
                    temperature.ArrayDimensions = null; // read able
                    temperature.OnSimpleReadValue = new NodeValueSimpleEventHandler(onRead);
                    temperature.AccessLevel = AccessLevels.CurrentReadOrWrite;
                    temperature.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                    Asset.AddChild(temperature);
                    AddPredefinedNode(SystemContext, temperature);
    
                    #endregion
    
                    #region pressure
                    PropertyState pressure = new PropertyState(Asset);
                    pressure.NodeId = new NodeId(6, NamespaceIndex);
                    pressure.BrowseName = new QualifiedName("Pressure", NamespaceIndex);
                    pressure.DisplayName = pressure.BrowseName.Name;
                    pressure.TypeDefinitionId = VariableTypeIds.PropertyType;
                    pressure.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                    pressure.DataType = DataTypeIds.Int32;
                    pressure.ValueRank = ValueRanks.Scalar;
                    pressure.ArrayDimensions = null; // read able
                    pressure.OnSimpleReadValue = new NodeValueSimpleEventHandler(onRead);
                    pressure.AccessLevel = AccessLevels.CurrentReadOrWrite;
                    pressure.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                    Asset.AddChild(pressure);
                    AddPredefinedNode(SystemContext, pressure);
    
                    #endregion
                  
                }
            }
        

    and here it my VB code:

     
    Private Shared references As IList(Of IReference) = Nothing
    		Private Shared Trigger As BaseObjectState
    		Private Shared externalReferences1 As IDictionary(Of NodeId, IList(Of IReference))
    		Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))
    			SyncLock Lock
    				externalReferences1 = externalReferences
    
    				Trigger = New BaseObjectState(Nothing)
    				Trigger.NodeId = New NodeId(1, NamespaceIndex)
    				Trigger.BrowseName = New QualifiedName("Plant", NamespaceIndex)
    				Trigger.DisplayName = Trigger.BrowseName.Name
    				Trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType
    				' ensure trigger can be found via the server object.
    
    				If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
    					references = New List(Of IReference)()
    					externalReferences1(ObjectIds.ObjectsFolder) = references
    				End If
    
    				Trigger.AddReference(ReferenceTypeIds.Organizes, True, ObjectIds.ObjectsFolder)
    				references.Add(New NodeStateReference(ReferenceTypeIds.Organizes, False, Trigger.NodeId))
    				AddPredefinedNode(SystemContext, Trigger)
    
    '				#Region "property"
    				Dim [property] As New PropertyState(Trigger)
    				[property].NodeId = New NodeId(2, NamespaceIndex)
    				[property].BrowseName = New QualifiedName("Level", NamespaceIndex)
    				[property].DisplayName = [property].BrowseName.Name
    				[property].TypeDefinitionId = VariableTypeIds.PropertyType
    				[property].ReferenceTypeId = ReferenceTypeIds.HasProperty
    				[property].DataType = DataTypeIds.Int32
    				[property].ValueRank = ValueRanks.Scalar
    				[property].ArrayDimensions = Nothing
    				' read able
    				[property].OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
    				' write able     
    				[property].AccessLevel = AccessLevels.CurrentReadOrWrite
    				[property].UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Trigger.AddChild([property])
    				AddPredefinedNode(SystemContext, [property])
    '				#End Region
    				' save in dictionary
    				' Assest
    '				#Region "Assest"
    				Dim Asset As New BaseObjectState(Nothing)
    				Asset.NodeId = New NodeId(3, NamespaceIndex)
    				Asset.BrowseName = New QualifiedName("Asset", NamespaceIndex)
    				Asset.TypeDefinitionId = ObjectTypeIds.BaseEventType
    				Asset.DisplayName = Asset.BrowseName.Name
    				Trigger.AddChild(Asset)
    				AddPredefinedNode(SystemContext, Asset)
    '				#End Region
    				' Flow Computer
    '				#Region "MassFlow"
    				Dim MassFlow As New PropertyState(Asset)
    				MassFlow.NodeId = New NodeId(4, NamespaceIndex)
    				MassFlow.BrowseName = New QualifiedName("MassFlow", NamespaceIndex)
    				MassFlow.DisplayName = MassFlow.BrowseName.Name
    				MassFlow.TypeDefinitionId = VariableTypeIds.PropertyType
    				MassFlow.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				MassFlow.DataType = DataTypeIds.Int32
    				MassFlow.ValueRank = ValueRanks.Scalar
    				MassFlow.ArrayDimensions = Nothing
    				' read able
    				MassFlow.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
    				' write able     
    				' MassFlow.AccessLevel = AccessLevels.CurrentReadOrWrite;
    				'MassFlow.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
    				Asset.AddChild(MassFlow)
    				AddPredefinedNode(SystemContext, MassFlow)
    '				#End Region
    '				#Region "temperature"
    				Dim temperature As New PropertyState(Asset)
    				temperature.NodeId = New NodeId(5, NamespaceIndex)
    				temperature.BrowseName = New QualifiedName("Temperture", NamespaceIndex)
    				temperature.DisplayName = temperature.BrowseName.Name
    				temperature.TypeDefinitionId = VariableTypeIds.PropertyType
    				temperature.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				temperature.DataType = DataTypeIds.Int32
    				temperature.ValueRank = ValueRanks.Scalar
    				temperature.ArrayDimensions = Nothing ' read able
    				temperature.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
    				temperature.AccessLevel = AccessLevels.CurrentReadOrWrite
    				temperature.UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Asset.AddChild(temperature)
    				AddPredefinedNode(SystemContext, temperature)
    
    '				#End Region
    
    '				#Region "pressure"
    				Dim pressure As New PropertyState(Asset)
    				pressure.NodeId = New NodeId(6, NamespaceIndex)
    				pressure.BrowseName = New QualifiedName("Pressure", NamespaceIndex)
    				pressure.DisplayName = pressure.BrowseName.Name
    				pressure.TypeDefinitionId = VariableTypeIds.PropertyType
    				pressure.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				pressure.DataType = DataTypeIds.Int32
    				pressure.ValueRank = ValueRanks.Scalar
    				pressure.ArrayDimensions = Nothing ' read able
    				pressure.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
    				pressure.AccessLevel = AccessLevels.CurrentReadOrWrite
    				pressure.UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Asset.AddChild(pressure)
    				AddPredefinedNode(SystemContext, pressure)
    
    '				#End Region
    
    			End SyncLock
    		End Sub

    I think it is something wrong with 

    If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
    references = New List(Of IReference)()
    externalReferences1(ObjectIds.ObjectsFolder) = references
    End If

    Trigger.AddReference(ReferenceTypeIds.Organizes, True, ObjectIds.ObjectsFolder)
    references.Add(New NodeStateReference(ReferenceTypeIds.Organizes, False, Trigger.NodeId))
    AddPredefinedNode(SystemContext, Trigger)

    when I run the code.. there only one Node

    and that is the last Node

    pressure.

    can someone help me?

    Thursday, April 03, 2014 8:05 PM

All replies

  • I used Teleriks Online coverter and it converted like your VB code reads. Then I used a Tangible demo C# to VB converter and I believe the code converted a bit differently and is below. Maybe it will work or have the same problem. Sometimes a Telerik conversion will not work correctly where a Tangible conversion will or vice versa I've found over time.

    I didn't read through all your VB code and this code but this if statement from you code and from this code are different unless I read the wrong things. Although they could both do the same thing for all I know.

    If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
         externalReferences1(ObjectIds.ObjectsFolder) = InlineAssignHelper(references, New List(Of IReference)())
    End If

    If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
         references = New List(Of IReference)()
         externalReferences1(ObjectIds.ObjectsFolder) = references
    End If

    Private Shared references As IList(Of IReference) = Nothing
    		Private Shared Trigger As BaseObjectState
    		Private Shared externalReferences1 As IDictionary(Of NodeId, IList(Of IReference))
    		Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))
    			SyncLock Lock
    				externalReferences1 = externalReferences
    
    				Trigger = New BaseObjectState(Nothing)
    				Trigger.NodeId = New NodeId(1, NamespaceIndex)
    				Trigger.BrowseName = New QualifiedName("Plant", NamespaceIndex)
    				Trigger.DisplayName = Trigger.BrowseName.Name
    				Trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType
    				' ensure trigger can be found via the server object.
    
    				If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
    					references = New List(Of IReference)()
    					externalReferences1(ObjectIds.ObjectsFolder) = references
    				End If
    
    				Trigger.AddReference(ReferenceTypeIds.Organizes, True, ObjectIds.ObjectsFolder)
    				references.Add(New NodeStateReference(ReferenceTypeIds.Organizes, False, Trigger.NodeId))
    				AddPredefinedNode(SystemContext, Trigger)
    
    '				#Region "property"
    				Dim [property] As New PropertyState(Trigger)
    				[property].NodeId = New NodeId(2, NamespaceIndex)
    				[property].BrowseName = New QualifiedName("Level", NamespaceIndex)
    				[property].DisplayName = [property].BrowseName.Name
    				[property].TypeDefinitionId = VariableTypeIds.PropertyType
    				[property].ReferenceTypeId = ReferenceTypeIds.HasProperty
    				[property].DataType = DataTypeIds.Int32
    				[property].ValueRank = ValueRanks.Scalar
    				[property].ArrayDimensions = Nothing
    				' read able
    				[property].OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
    				' write able     
    				[property].AccessLevel = AccessLevels.CurrentReadOrWrite
    				[property].UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Trigger.AddChild([property])
    				AddPredefinedNode(SystemContext, [property])
    '				#End Region
    				' save in dictionary
    				' Assest
    '				#Region "Assest"
    				Dim Asset As New BaseObjectState(Nothing)
    				Asset.NodeId = New NodeId(3, NamespaceIndex)
    				Asset.BrowseName = New QualifiedName("Asset", NamespaceIndex)
    				Asset.TypeDefinitionId = ObjectTypeIds.BaseEventType
    				Asset.DisplayName = Asset.BrowseName.Name
    				Trigger.AddChild(Asset)
    				AddPredefinedNode(SystemContext, Asset)
    '				#End Region
    				' Flow Computer
    '				#Region "MassFlow"
    				Dim MassFlow As New PropertyState(Asset)
    				MassFlow.NodeId = New NodeId(4, NamespaceIndex)
    				MassFlow.BrowseName = New QualifiedName("MassFlow", NamespaceIndex)
    				MassFlow.DisplayName = MassFlow.BrowseName.Name
    				MassFlow.TypeDefinitionId = VariableTypeIds.PropertyType
    				MassFlow.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				MassFlow.DataType = DataTypeIds.Int32
    				MassFlow.ValueRank = ValueRanks.Scalar
    				MassFlow.ArrayDimensions = Nothing
    				' read able
    				MassFlow.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
    				' write able     
    				' MassFlow.AccessLevel = AccessLevels.CurrentReadOrWrite;
    				'MassFlow.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
    				Asset.AddChild(MassFlow)
    				AddPredefinedNode(SystemContext, MassFlow)
    '				#End Region
    '				#Region "temperature"
    				Dim temperature As New PropertyState(Asset)
    				temperature.NodeId = New NodeId(5, NamespaceIndex)
    				temperature.BrowseName = New QualifiedName("Temperture", NamespaceIndex)
    				temperature.DisplayName = temperature.BrowseName.Name
    				temperature.TypeDefinitionId = VariableTypeIds.PropertyType
    				temperature.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				temperature.DataType = DataTypeIds.Int32
    				temperature.ValueRank = ValueRanks.Scalar
    				temperature.ArrayDimensions = Nothing ' read able
    				temperature.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
    				temperature.AccessLevel = AccessLevels.CurrentReadOrWrite
    				temperature.UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Asset.AddChild(temperature)
    				AddPredefinedNode(SystemContext, temperature)
    
    '				#End Region
    
    '				#Region "pressure"
    				Dim pressure As New PropertyState(Asset)
    				pressure.NodeId = New NodeId(6, NamespaceIndex)
    				pressure.BrowseName = New QualifiedName("Pressure", NamespaceIndex)
    				pressure.DisplayName = pressure.BrowseName.Name
    				pressure.TypeDefinitionId = VariableTypeIds.PropertyType
    				pressure.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				pressure.DataType = DataTypeIds.Int32
    				pressure.ValueRank = ValueRanks.Scalar
    				pressure.ArrayDimensions = Nothing ' read able
    				pressure.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
    				pressure.AccessLevel = AccessLevels.CurrentReadOrWrite
    				pressure.UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Asset.AddChild(pressure)
    				AddPredefinedNode(SystemContext, pressure)
    
    '				#End Region
    
    			End SyncLock
    		End Sub


    Hello. I'm old and retired. I like to program if you could call what I do programming. However I'd like to code for you! If you've got the dime then I've got the time. Call me, landline, @ BR-549.


    Thursday, April 03, 2014 8:38 PM
  • it has errors in it 
    Thursday, April 03, 2014 10:20 PM
  • What sort of errors are you getting?

    Note that this is Windows Store App code, so your VB project must also be that type of project.


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

    Thursday, April 03, 2014 10:38 PM
  • Error 1 Delegate 'Opc.Ua.NodeValueSimpleEventHandler' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.

    there are 4 errors like that:

    all for 

      pressure.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)

    it does not like the OnRead

    even when I add AddressOf

    it does not work the correct way

    it stall only adding the last node 

    Pressure but not the other nodes

    I think somehow the other node are being over written but I do not know how

    and again this code works in C#

    it uses the same .dll files in C#

    • Edited by Btb4198 Thursday, April 03, 2014 11:11 PM
    Thursday, April 03, 2014 11:05 PM
  • Change that statement to:

    [property].OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
    For all 4 errors you can just add the 'AddressOf'.

    A converter will not catch these because neither the 'OnRead' method nor the 'NodeValueSimpleEventHandler' is defined in the code being converted.  The converter has no reliable way to know that 'AddressOf' is required if you're just converting the snippet.  If you're converting a project the converter should be able to resolve everything either in the source code of the project or by reflecting on referenced assemblies.


    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter


    Thursday, April 03, 2014 11:10 PM
  • yeah I did that

    it still did not work

    i even turned

    [property]
    to

    property1

     
    Friday, April 04, 2014 12:06 AM
  • ok I am sure it is something wrong with that if statment 

    I ran the debugger in the C# and VB and I saw that in VB it is not getting set 

    but I really do not know VB well

    so I do not know why

    it is going in to the if statement but it is not being set right

    VB:

                    If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
                        references = New List(Of IReference)()
                        externalReferences1(ObjectIds.ObjectsFolder) = references
                    End If

    C#

       if (!externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, out references))
                    {
                        externalReferences1[ObjectIds.ObjectsFolder] = references = new List<IReference>();
                    }

    Friday, April 04, 2014 3:04 AM
  • You can't make static variables private variables.  A application has two different types of memory.  One type of memory is on the execution stack and is created and destroyed as you call methods and exits methods.  It is also local so only accessible to the local class and not to other classes.  This type memory can either be public or private.  Making it public isn't always equivalent to making it static.  Making it public still places the variable on the execution stack.

    Making a variable static puts the memory on the Global memory spaces.  Global memory is public and is in an area where other processes can access the memory.  A dll can access static (Global memory) space put cannot access public memory on the execution stack.

    I first discovered this issue in the early 1980's when writing assembly language programs that were called from XBasic which came with my first 8086 PC.  I had to make my global assembly language variable static for XBasic to access these variable.

    Then again I had problems in Window 95 writing mixed language applications (assembly, c, basic, fortran).  I even had a case where I had a PC card with embedded processor that had to communicate with a C language application (similar to a dll application) where I had to compile the embedded processor code as static memory (not public).  Public didn't work. 

    The solution is to use shared like what you did.  But I think you still also need to make them public.  I think C# will automatically make a static variable public while basic has an option to make shared either private or public.
    Friday, April 04, 2014 3:33 AM
  • this is how I declare the variables in C#

    static IList<IReference> references = null;
            static BaseObjectState Trigger;
            static IDictionary<NodeId, IList<IReference>> externalReferences1;

    and this is how they were convert in to VB

     Private Shared references As IList(Of IReference) = Nothing
            Private Shared Trigger As BaseObjectState
            Private Shared externalReferences1 As IDictionary(Of NodeId, IList(Of IReference))

    is 

    should they be private Shared ?

    Friday, April 04, 2014 3:37 AM
  • ok I did some more troubleshooting... comparing the C# code to the VB code and I found where the VB code starts to act up.

    here :

    VB:

       Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))

      externalReferences has an error in it, in the vb code but not in the C# code...  now a .dll file calls that function  in both C# and VB so that is not the problem .. the problem most be that 

    this line in c#

    public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)

    was not convert correctly in to VB

    to this line 

     Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))

    can anyone see why this line is wrong ?

    Friday, April 04, 2014 4:00 AM
  • I not sure what other parts of you program are using these objects.  If you are using dlls that are trying to access these objects, you won't get a compile error but will get execution errors.

    jdweng

    Friday, April 04, 2014 4:00 AM
  • the .dll files are working for the C# code...

    so it should work for the VB code

    right?

    Friday, April 04, 2014 4:04 AM
  • Are the compiler options set the same?  You are failing very early in the code so if options like x86, 32 vs 64, or Net Library version are different this might cause the errors.

    jdweng


    Can you post the stacktrace inner exceptions?
    Friday, April 04, 2014 4:09 AM
  • No.  I wish it was easy to get a map of the compiled code to check the location of the variables were located like in the good old days.  The map use to have the static variables listed and I could check if the compiler/linker was putting the variables in the same area in VB and C#.

    jdweng

    Friday, April 04, 2014 4:13 AM
  • They should be, I have not changed them from the default.  

    how do i check ?

    Also does that line look right in VB?

    Friday, April 04, 2014 4:15 AM
  • I checked everything.  My best guess is to change the variables from Private Shared to Public Shared.  Is there any other code that access this code like a call the class constructor with NEW that may be different?

    I would add an exception handler (try/catch) around the code and then capture the ex.StackTrace message where ex is parameter in the catch.

    Try

    Catch ex as Exception

         Console.WriteLine(ex.StackTrace)

    End Try


    jdweng

    Friday, April 04, 2014 4:38 AM
  • no the .dll file calls that function

    and passes  externalReferences

    also changing Private Shared to Public Shared will not help because it come in with the error ..

    so it have to be this line:

    Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))

    I mean the .dll files wok with the C# code

    and that line was the 1st that was different then the C# code 

    Friday, April 04, 2014 4:43 AM
  • I think we have a chicken and egg issue.  I don't think the error is with the function definition, but with the parameters that are being passed to the function.  I think that if the private shared variables were in public static memory that the issue would go away.  I think the root cause of the problem is to make the Private Shared variables public.

    Can you tell me if the class you are using is public or private?  The reason you cannot make the variables public shared is the class is defined incorrectly.  You can't make the scope of a variable at a higher visability than its parent. 


    jdweng

    Friday, April 04, 2014 9:41 AM
  • The class is public

    I did what you said, but I still get the same error in  ExternalReferences 

    #Region "INodeManager Members"
    		''' <summary>
    		''' Does any initialization required before the address space can be used.
    		''' </summary>
    		''' <remarks>
    		''' The externalReferences is an out parameter that allows the node manager to link to nodes
    		''' in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
    		''' should have a reference to the root folder node(s) exposed by this node manager.  
    		''' </remarks>
    		''' 
            Public Shared references As IList(Of IReference) = Nothing
            Public Shared Trigger As BaseObjectState
            Public Shared externalReferences1 As IDictionary(Of NodeId, IList(Of IReference))
            Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))
                SyncLock Lock
                    externalReferences1 = externalReferences
    
                    Trigger = New BaseObjectState(Nothing)
                    Trigger.NodeId = New NodeId(1, NamespaceIndex)
                    Trigger.BrowseName = New QualifiedName("Plant", NamespaceIndex)
                    Trigger.DisplayName = Trigger.BrowseName.Name
                    Trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType
                    ' ensure trigger can be found via the server object.
    
                    If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
                        references = New List(Of IReference)()
                        externalReferences1(ObjectIds.ObjectsFolder) = references
                    End If
    
                    Trigger.AddReference(ReferenceTypeIds.Organizes, True, ObjectIds.ObjectsFolder)
                    references.Add(New NodeStateReference(ReferenceTypeIds.Organizes, False, Trigger.NodeId))
                    AddPredefinedNode(SystemContext, Trigger)
    
                    '				#Region "property"
                    Dim property1 As New PropertyState(Trigger)
                    property1.NodeId = New NodeId(2, NamespaceIndex)
                    property1.BrowseName = New QualifiedName("Level", NamespaceIndex)
                    property1.DisplayName = property1.BrowseName.Name
                    property1.TypeDefinitionId = VariableTypeIds.PropertyType
                    property1.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    property1.DataType = DataTypeIds.Int32
                    property1.ValueRank = ValueRanks.Scalar
                    property1.ArrayDimensions = Nothing
                    ' read able
                    property1.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                    ' write able     
                    property1.AccessLevel = AccessLevels.CurrentReadOrWrite
                    property1.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Trigger.AddChild(property1)
                    AddPredefinedNode(SystemContext, property1)
                    '				#End Region
                    ' save in dictionary
                    ' Assest
                    '				#Region "Assest"
                    Dim Asset As New BaseObjectState(Nothing)
                    Asset.NodeId = New NodeId(3, NamespaceIndex)
                    Asset.BrowseName = New QualifiedName("Asset", NamespaceIndex)
                    Asset.TypeDefinitionId = ObjectTypeIds.BaseEventType
                    Asset.DisplayName = Asset.BrowseName.Name
                    Trigger.AddChild(Asset)
                    AddPredefinedNode(SystemContext, Asset)
                    '				#End Region
                    ' Flow Computer
                    '				#Region "MassFlow"
                    Dim MassFlow As New PropertyState(Asset)
                    MassFlow.NodeId = New NodeId(4, NamespaceIndex)
                    MassFlow.BrowseName = New QualifiedName("MassFlow", NamespaceIndex)
                    MassFlow.DisplayName = MassFlow.BrowseName.Name
                    MassFlow.TypeDefinitionId = VariableTypeIds.PropertyType
                    MassFlow.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    MassFlow.DataType = DataTypeIds.Int32
                    MassFlow.ValueRank = ValueRanks.Scalar
                    MassFlow.ArrayDimensions = Nothing
                    ' read able
                    MassFlow.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                    ' write able     
                    ' MassFlow.AccessLevel = AccessLevels.CurrentReadOrWrite;
                    'MassFlow.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                    Asset.AddChild(MassFlow)
                    AddPredefinedNode(SystemContext, MassFlow)
                    '				#End Region
                    '				#Region "temperature"
                    Dim temperature As New PropertyState(Asset)
                    temperature.NodeId = New NodeId(5, NamespaceIndex)
                    temperature.BrowseName = New QualifiedName("Temperture", NamespaceIndex)
                    temperature.DisplayName = temperature.BrowseName.Name
                    temperature.TypeDefinitionId = VariableTypeIds.PropertyType
                    temperature.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    temperature.DataType = DataTypeIds.Int32
                    temperature.ValueRank = ValueRanks.Scalar
                    temperature.ArrayDimensions = Nothing ' read able
                    temperature.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                    temperature.AccessLevel = AccessLevels.CurrentReadOrWrite
                    temperature.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Asset.AddChild(temperature)
                    AddPredefinedNode(SystemContext, temperature)
    
                    '				#End Region
    
                    '				#Region "pressure"
                    Dim pressure As New PropertyState(Asset)
                    pressure.NodeId = New NodeId(6, NamespaceIndex)
                    pressure.BrowseName = New QualifiedName("Pressure", NamespaceIndex)
                    pressure.DisplayName = pressure.BrowseName.Name
                    pressure.TypeDefinitionId = VariableTypeIds.PropertyType
                    pressure.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    pressure.DataType = DataTypeIds.Int32
                    pressure.ValueRank = ValueRanks.Scalar
                    pressure.ArrayDimensions = Nothing ' read able
                    pressure.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                    pressure.AccessLevel = AccessLevels.CurrentReadOrWrite
                    pressure.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Asset.AddChild(pressure)
                    AddPredefinedNode(SystemContext, pressure)
    
                    '#End Region
    
                End SyncLock
            End Sub
    
    		 Public Sub CreateNode(ByVal name1 As String, ByVal counter1 As String, ByVal value1 As String)
    			SyncLock Lock
    				Dim temp As New PropertyState(Trigger)
    				temp.NodeId = New NodeId(counter1, NamespaceIndex)
    				temp.BrowseName = New QualifiedName(name1, NamespaceIndex)
    				temp.DisplayName = temp.BrowseName.Name
    				temp.TypeDefinitionId = VariableTypeIds.PropertyType
    				temp.ReferenceTypeId = ReferenceTypeIds.HasProperty
    				temp.DataType = DataTypeIds.Int32
    				temp.ValueRank = ValueRanks.Scalar
    				temp.TypeDefinitionId = value1
    				temp.ArrayDimensions = Nothing ' read able
    				temp.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
    				temp.AccessLevel = AccessLevels.CurrentReadOrWrite
    				temp.UserAccessLevel = AccessLevels.CurrentReadOrWrite
    				Trigger.AddChild(temp)
    				AddPredefinedNode(SystemContext, temp)
    				AddReferences(externalReferences1)
    
    
    
    
    			End SyncLock
    
    		 End Sub

    Friday, April 04, 2014 12:49 PM
  • Maybe you could zip your project to a folder and place that folder on your Microsoft OneDrive (used to be SkyDrive) in a public folder then in a post provide a link to the public folder so the project could be downloaded and tested unless it is proprietary in nature. Although if it's a windows Store App I've never worked with one and I don't have Windows 8 if that is necessary for those apps.

    Hello. I'm old and retired. I like to program if you could call what I do programming. However I'd like to code for you! If you've got the dime then I've got the time. Call me, landline, @ BR-549.

    Friday, April 04, 2014 1:45 PM
  • Can you post the stacktrace?

    jdweng

    Friday, April 04, 2014 1:46 PM
  • is this the stacktrace ?

    >	OPC-UA Server1.exe!OPC_UA_Server.EmptyNodeManager.CreateAddressSpace(System.Collections.Generic.IDictionary(Of Opc.Ua.NodeId, System.Collections.Generic.IList(Of Opc.Ua.IReference)) externalReferences = Count = 0) Line 75	Basic
     	Opc.Ua.Server.dll!Opc.Ua.Server.MasterNodeManager.Startup() Line 277 + 0xc bytes	C#
     	Opc.Ua.Server.dll!Opc.Ua.Server.StandardServer.StartApplication(Opc.Ua.ApplicationConfiguration configuration = {Opc.Ua.ApplicationConfiguration}) Line 2767 + 0xb bytes	C#
     	Opc.Ua.Core.dll!Opc.Ua.ServerBase.Start(Opc.Ua.ApplicationConfiguration configuration = {Opc.Ua.ApplicationConfiguration}) Line 283 + 0xe bytes	C#
     	OPC-UA Server1.exe!OPC_UA_Server.Program1.Main() Line 39 + 0xd bytes	Basic
     	[External Code]	
    


    • Edited by Btb4198 Friday, April 04, 2014 1:59 PM
    Friday, April 04, 2014 1:58 PM
  • Mr.Monkeyboy,

    what is  Microsoft OneDrive?

    and how do I get it?

    if you send me your email, I can send you a drop box link

    Friday, April 04, 2014 2:03 PM
  • https://onedrive.live.com/redir?resid=CC8AF223519E2440!107&authkey=!AEvhOkp7aboQUkU&ithint=file%2c.zip
    Friday, April 04, 2014 2:14 PM
  • where you able to view the code ?

    I have been trying to troubleshoot it for a while now and I still do not know what is wrong with it..

    Friday, April 04, 2014 8:58 PM
  • the .dll file that called that function, just makes a  new  variable and pass it along to the function.. So I made a new variable in the function 

    Dim externalReferences As NewOfNodeId, OfIReference))

    but I am sill getting the same runtime error :

    Saturday, April 05, 2014 1:45 AM
  • this is how it looks in C#

    I do not know why it is so different 

    Saturday, April 05, 2014 1:48 AM
  • Add exception handlers to the code below to get the StackTrace.  I think I may of found the issue.

    From : Private Shared references As IList(Of IReference) = Nothing
    To :  Private Shared references As New IList(Of IReference)

       Public Sub CreateNode(ByVal name1 As String, ByVal counter1 As String, ByVal value1 As String)
            Try
                SyncLock Lock()
                    Dim temp As New PropertyState(Trigger)
                    temp.NodeId = New NodeId(counter1, NamespaceIndex)
                    temp.BrowseName = New QualifiedName(name1, NamespaceIndex)
                    temp.DisplayName = temp.BrowseName.Name
                    temp.TypeDefinitionId = VariableTypeIds.PropertyType
                    temp.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    temp.DataType = DataTypeIds.Int32
                    temp.ValueRank = ValueRanks.Scalar
                    temp.TypeDefinitionId = value1
                    temp.ArrayDimensions = Nothing ' read able
                    temp.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                    temp.AccessLevel = AccessLevels.CurrentReadOrWrite
                    temp.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Trigger.AddChild(temp)
                    AddPredefinedNode(SystemContext, temp)
                    AddReferences(externalReferences1)
    
    
    
    
                End SyncLock
            Catch ex As Exception
                Console.WriteLine("Error Message : {0}", ex.Message)
                Console.WriteLine("Stack Trace : {0}", ex.StackTrace)
            End Try
        End Sub
        Private Shared references As New IList(Of IReference)
        Private Shared Trigger As BaseObjectState
        Private Shared externalReferences1 As IDictionary(Of NodeId, IList(Of IReference))
    
        Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))
            Try
                SyncLock Lock()
                    externalReferences1 = externalReferences
    
                    Trigger = New BaseObjectState(Nothing)
                    Trigger.NodeId = New NodeId(1, NamespaceIndex)
                    Trigger.BrowseName = New QualifiedName("Plant", NamespaceIndex)
                    Trigger.DisplayName = Trigger.BrowseName.Name
                    Trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType
                    ' ensure trigger can be found via the server object.
    
                    If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
                        references = New List(Of IReference)()
                        externalReferences1(ObjectIds.ObjectsFolder) = references
                    End If
    
                    Trigger.AddReference(ReferenceTypeIds.Organizes, True, ObjectIds.ObjectsFolder)
                    references.Add(New NodeStateReference(ReferenceTypeIds.Organizes, False, Trigger.NodeId))
                    AddPredefinedNode(SystemContext, Trigger)
    
                    '				#Region "property"
                    Dim [property] As New PropertyState(Trigger)
                    [property].NodeId = New NodeId(2, NamespaceIndex)
                    [property].BrowseName = New QualifiedName("Level", NamespaceIndex)
                    [property].DisplayName = [property].BrowseName.Name
                    [property].TypeDefinitionId = VariableTypeIds.PropertyType
                    [property].ReferenceTypeId = ReferenceTypeIds.HasProperty
                    [property].DataType = DataTypeIds.Int32
                    [property].ValueRank = ValueRanks.Scalar
                    [property].ArrayDimensions = Nothing
                    ' read able
                    [property].OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
                    ' write able     
                    [property].AccessLevel = AccessLevels.CurrentReadOrWrite
                    [property].UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Trigger.AddChild([property])
                    AddPredefinedNode(SystemContext, [property])
                    '				#End Region
                    ' save in dictionary
                    ' Assest
                    '				#Region "Assest"
                    Dim Asset As New BaseObjectState(Nothing)
                    Asset.NodeId = New NodeId(3, NamespaceIndex)
                    Asset.BrowseName = New QualifiedName("Asset", NamespaceIndex)
                    Asset.TypeDefinitionId = ObjectTypeIds.BaseEventType
                    Asset.DisplayName = Asset.BrowseName.Name
                    Trigger.AddChild(Asset)
                    AddPredefinedNode(SystemContext, Asset)
                    '				#End Region
                    ' Flow Computer
                    '				#Region "MassFlow"
                    Dim MassFlow As New PropertyState(Asset)
                    MassFlow.NodeId = New NodeId(4, NamespaceIndex)
                    MassFlow.BrowseName = New QualifiedName("MassFlow", NamespaceIndex)
                    MassFlow.DisplayName = MassFlow.BrowseName.Name
                    MassFlow.TypeDefinitionId = VariableTypeIds.PropertyType
                    MassFlow.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    MassFlow.DataType = DataTypeIds.Int32
                    MassFlow.ValueRank = ValueRanks.Scalar
                    MassFlow.ArrayDimensions = Nothing
                    ' read able
                    MassFlow.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
                    ' write able     
                    ' MassFlow.AccessLevel = AccessLevels.CurrentReadOrWrite;
                    'MassFlow.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                    Asset.AddChild(MassFlow)
                    AddPredefinedNode(SystemContext, MassFlow)
                    '				#End Region
                    '				#Region "temperature"
                    Dim temperature As New PropertyState(Asset)
                    temperature.NodeId = New NodeId(5, NamespaceIndex)
                    temperature.BrowseName = New QualifiedName("Temperture", NamespaceIndex)
                    temperature.DisplayName = temperature.BrowseName.Name
                    temperature.TypeDefinitionId = VariableTypeIds.PropertyType
                    temperature.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    temperature.DataType = DataTypeIds.Int32
                    temperature.ValueRank = ValueRanks.Scalar
                    temperature.ArrayDimensions = Nothing ' read able
                    temperature.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
                    temperature.AccessLevel = AccessLevels.CurrentReadOrWrite
                    temperature.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Asset.AddChild(temperature)
                    AddPredefinedNode(SystemContext, temperature)
    
                    '				#End Region
    
                    '				#Region "pressure"
                    Dim pressure As New PropertyState(Asset)
                    pressure.NodeId = New NodeId(6, NamespaceIndex)
                    pressure.BrowseName = New QualifiedName("Pressure", NamespaceIndex)
                    pressure.DisplayName = pressure.BrowseName.Name
                    pressure.TypeDefinitionId = VariableTypeIds.PropertyType
                    pressure.ReferenceTypeId = ReferenceTypeIds.HasProperty
                    pressure.DataType = DataTypeIds.Int32
                    pressure.ValueRank = ValueRanks.Scalar
                    pressure.ArrayDimensions = Nothing ' read able
                    pressure.OnSimpleReadValue = New NodeValueSimpleEventHandler(onRead)
                    pressure.AccessLevel = AccessLevels.CurrentReadOrWrite
                    pressure.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                    Asset.AddChild(pressure)
                    AddPredefinedNode(SystemContext, pressure)
    
                    '				#End Region
    
                End SyncLock
            Catch ex As Exception
                Console.WriteLine("Error Message : {0}", ex.Message)
                Console.WriteLine("Stack Trace : {0}", ex.StackTrace)
            End Try
        End Sub
    
    End Module
    


    jdweng

    Saturday, April 05, 2014 4:28 AM
  • Ok I did it

    but nothing came up on the command prompt 

    • Edited by Btb4198 Saturday, April 05, 2014 5:37 AM
    Saturday, April 05, 2014 5:33 AM
  • this is the code I have now :
     Public Shared references As IList(Of IReference) = New List(Of IReference)() ' = Nothing
            Public Shared Trigger As BaseObjectState
            Public Shared externalReferences1 As IDictionary(Of NodeId, IList(Of IReference)) = Nothing
    
            Public Overrides Sub CreateAddressSpace(ByVal externalReferences As IDictionary(Of NodeId, IList(Of IReference)))
                SyncLock Lock
                    Try
                        externalReferences1 = externalReferences
    
                        '  Dim externalReferences2 As New Dictionary(Of NodeId, IList(Of IReference))
    
                        Trigger = New BaseObjectState(Nothing)
                        Trigger.NodeId = New NodeId(1, NamespaceIndex)
                        Trigger.BrowseName = New QualifiedName("Plant", NamespaceIndex)
                        Trigger.DisplayName = Trigger.BrowseName.Name
                        Trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType
                        ' ensure trigger can be found via the server object.
    
                        If Not externalReferences1.TryGetValue(ObjectIds.ObjectsFolder, references) Then
                            references = New List(Of IReference)()
                            externalReferences1(ObjectIds.ObjectsFolder) = references
                        End If
    
                        Trigger.AddReference(ReferenceTypeIds.Organizes, True, ObjectIds.ObjectsFolder)
                        references.Add(New NodeStateReference(ReferenceTypeIds.Organizes, False, Trigger.NodeId))
                        AddPredefinedNode(SystemContext, Trigger)
    
                        '				#Region "property"
                        Dim property1 As New PropertyState(Trigger)
                        property1.NodeId = New NodeId(2, NamespaceIndex)
                        property1.BrowseName = New QualifiedName("Level", NamespaceIndex)
                        property1.DisplayName = property1.BrowseName.Name
                        property1.TypeDefinitionId = VariableTypeIds.PropertyType
                        property1.ReferenceTypeId = ReferenceTypeIds.HasProperty
                        property1.DataType = DataTypeIds.Int32
                        property1.ValueRank = ValueRanks.Scalar
                        property1.ArrayDimensions = Nothing
                        ' read able
                        property1.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                        ' write able     
                        property1.AccessLevel = AccessLevels.CurrentReadOrWrite
                        property1.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                        Trigger.AddChild(property1)
                        AddPredefinedNode(SystemContext, property1)
                        '				#End Region
                        ' save in dictionary
                        ' Assest
                        '				#Region "Assest"
                        Dim Asset As New BaseObjectState(Nothing)
                        Asset.NodeId = New NodeId(3, NamespaceIndex)
                        Asset.BrowseName = New QualifiedName("Asset", NamespaceIndex)
                        Asset.TypeDefinitionId = ObjectTypeIds.BaseEventType
                        Asset.DisplayName = Asset.BrowseName.Name
                        Trigger.AddChild(Asset)
                        AddPredefinedNode(SystemContext, Asset)
                        '				#End Region
                        ' Flow Computer
                        '				#Region "MassFlow"
                        Dim MassFlow As New PropertyState(Asset)
                        MassFlow.NodeId = New NodeId(4, NamespaceIndex)
                        MassFlow.BrowseName = New QualifiedName("MassFlow", NamespaceIndex)
                        MassFlow.DisplayName = MassFlow.BrowseName.Name
                        MassFlow.TypeDefinitionId = VariableTypeIds.PropertyType
                        MassFlow.ReferenceTypeId = ReferenceTypeIds.HasProperty
                        MassFlow.DataType = DataTypeIds.Int32
                        MassFlow.ValueRank = ValueRanks.Scalar
                        MassFlow.ArrayDimensions = Nothing
                        ' read able
                        MassFlow.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                        ' write able     
                        ' MassFlow.AccessLevel = AccessLevels.CurrentReadOrWrite;
                        'MassFlow.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
                        Asset.AddChild(MassFlow)
                        AddPredefinedNode(SystemContext, MassFlow)
                        '				#End Region
                        '				#Region "temperature"
                        Dim temperature As New PropertyState(Asset)
                        temperature.NodeId = New NodeId(5, NamespaceIndex)
                        temperature.BrowseName = New QualifiedName("Temperture", NamespaceIndex)
                        temperature.DisplayName = temperature.BrowseName.Name
                        temperature.TypeDefinitionId = VariableTypeIds.PropertyType
                        temperature.ReferenceTypeId = ReferenceTypeIds.HasProperty
                        temperature.DataType = DataTypeIds.Int32
                        temperature.ValueRank = ValueRanks.Scalar
                        temperature.ArrayDimensions = Nothing ' read able
                        temperature.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                        temperature.AccessLevel = AccessLevels.CurrentReadOrWrite
                        temperature.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                        Asset.AddChild(temperature)
                        AddPredefinedNode(SystemContext, temperature)
    
                        '				#End Region
    
                        '				#Region "pressure"
                        Dim pressure As New PropertyState(Asset)
                        pressure.NodeId = New NodeId(6, NamespaceIndex)
                        pressure.BrowseName = New QualifiedName("Pressure", NamespaceIndex)
                        pressure.DisplayName = pressure.BrowseName.Name
                        pressure.TypeDefinitionId = VariableTypeIds.PropertyType
                        pressure.ReferenceTypeId = ReferenceTypeIds.HasProperty
                        pressure.DataType = DataTypeIds.Int32
                        pressure.ValueRank = ValueRanks.Scalar
                        pressure.ArrayDimensions = Nothing ' read able
                        pressure.OnSimpleReadValue = New NodeValueSimpleEventHandler(AddressOf onRead)
                        pressure.AccessLevel = AccessLevels.CurrentReadOrWrite
                        pressure.UserAccessLevel = AccessLevels.CurrentReadOrWrite
                        Asset.AddChild(pressure)
                        AddPredefinedNode(SystemContext, pressure)
    
                        '#End Region
    
                    Catch ex As Exception
                        Console.WriteLine("Error Message : {0}", ex.Message)
                        Console.WriteLine("Stack Trace : {0}", ex.StackTrace)
                    End Try
    
                End SyncLock
            End Sub
    
    so what do you think is wrong with it ?
    Saturday, April 05, 2014 5:51 AM
  • You can add a ReadLine() to pause so you can see the error message or add a break point.  If you aren't getting any error messages than the error is occurring some place else in the code.

    Catch ex As Exception
                        Console.WriteLine("Error Message : {0}", ex.Message)
                        Console.WriteLine("Stack Trace : {0}", ex.StackTrace)
                        Console.ReadLine();
                    End Try
    


    jdweng

    Saturday, April 05, 2014 6:23 AM
  • tried that ...

    still no error

    Saturday, April 05, 2014 1:03 PM
  • it work in C#

    so it should work in VB right ?

    Saturday, April 05, 2014 1:03 PM
  • You aren't getting an exception so it should work.  I would start by adding watch items for each variable on both C# and VB and compare the difference.  Put a break point at the beginning of the function and then right click each variable and select "add watch item".  The variable will appear in the watch view.   You can then open the plus sign for each variable and look at all the properties.  We need to find out which property is different and why.

    jdweng

    Saturday, April 05, 2014 2:53 PM
  • what is a

    watch items?

    I watch what is different... i just do not know why..

    did you see the pictures I added to this forum ?

    you can see the different in the VB pic and the C# pic

    I just do not know why

    are how to fix it

    Saturday, April 05, 2014 4:29 PM
  • The differences between the two Call Stacks in the pictures is the parameters is the definition of the parameter list.  I would indicate that either NodeId, or IReference are defined different.  The watch would give more information about these two variables.  Where are NodeID and IReference defined?


    jdweng

    Saturday, April 05, 2014 5:38 PM
  •  

    IReference>

    IRefence is an interface inside one of the .dll files from the OPC foundation UA .dll files

    it is just this

    public interface IReference
    {
        // Properties
        bool IsInverse { get; }
        NodeId ReferenceTypeId { get; }
        ExpandedNodeId TargetId { get; }
    }
    

    and this is nodeID

    [DataContract(Namespace="http://opcfoundation.org/UA/2008/02/Types.xsd")]
    public class NodeId : IComparable, IFormattable, ICloneable
    {
        // Fields
        private object m_identifier;
        private IdType m_identifierType;
        private ushort m_namespaceIndex;
        private static readonly NodeId s_Null;
    
        // Methods
        static NodeId();
        internal NodeId();
        public NodeId(NodeId value);
        public NodeId(Guid value);
        public NodeId(byte[] value);
        public NodeId(string text);
        public NodeId(uint value);
        public NodeId(Guid value, ushort namespaceIndex);
        public NodeId(byte[] value, ushort namespaceIndex);
        public NodeId(object value, ushort namespaceIndex);
        public NodeId(string value, ushort namespaceIndex);
        public NodeId(uint value, ushort namespaceIndex);
        public object Clone();
        private static int CompareIdentifiers(IdType idType1, object id1, IdType idType2, object id2);
        public int CompareTo(object obj);
        public static NodeId Create(object identifier, string namespaceUri, NamespaceTable namespaceTable);
        public override bool Equals(object obj);
        public string Format();
        public void Format(StringBuilder buffer);
        public static void Format(StringBuilder buffer, object identifier, IdType identifierType, ushort namespaceIndex);
        private static void FormatIdentifier(StringBuilder buffer, object identifier, IdType identifierType);
        public override int GetHashCode();
        private void Initialize();
        [OnDeserializing]
        private void Initialize(StreamingContext context);
        public static bool IsNull(ExpandedNodeId nodeId);
        public static bool IsNull(NodeId nodeId);
        public static bool operator ==(NodeId value1, object value2);
        public static bool operator >(NodeId value1, NodeId value2);
        public static implicit operator NodeId(Guid value);
        public static implicit operator NodeId(uint value);
        public static implicit operator NodeId(byte[] value);
        public static implicit operator NodeId(string text);
        public static bool operator !=(NodeId value1, object value2);
        public static bool operator <(NodeId value1, NodeId value2);
        public static NodeId Parse(string text);
        internal void SetIdentifier(IdType idType, object value);
        internal void SetIdentifier(string value, IdType idType);
        internal void SetNamespaceIndex(ushort value);
        public static ExpandedNodeId ToExpandedNodeId(NodeId nodeId, NamespaceTable namespaceTable);
        public override string ToString();
        public string ToString(string format, IFormatProvider formatProvider);
    
        // Properties
        public object Identifier { get; }
        [DataMember(Name="Identifier", Order=1)]
        internal string IdentifierText { get; set; }
        public IdType IdType { get; }
        public bool IsNullNodeId { get; }
        public ushort NamespaceIndex { get; }
        public static NodeId Null { get; }
    }
    
    Expand Methods

    Sunday, April 06, 2014 2:39 AM
  • what is watcher and how do I use it ?
    Sunday, April 06, 2014 2:40 AM
  • ok I found watch, but it does not show anything 

    Sunday, April 06, 2014 4:01 AM
  • here are some pic I took:
    Sunday, April 06, 2014 4:28 AM
  • Sunday, April 06, 2014 4:32 AM
  • Sunday, April 06, 2014 4:32 AM
  • What isn't working?  It looks like you are executing all the code in VBnet.  The local variables looks also like they are being set.  Is there something different in the local variables?

    jdweng

    Sunday, April 06, 2014 7:10 AM
  • this for one
    Sunday, April 06, 2014 10:04 PM
  • Also this :

    only one node comes up...

    the last node

    Sunday, April 06, 2014 10:11 PM
  • this is how it should look

    this is the C# code running:

     

    Sunday, April 06, 2014 10:16 PM