Author Topic: EthernetIPforCLXCom.vb Object reference not set to an instance of an object  (Read 1990 times)

hektop

  • Newbie
  • *
  • Posts: 20
    • View Profile
Using v399 and VS express 2015, I get the error "Object reference not set to an instance of an object" in the EthernetIPforCLXCom.vb line 464. The following is the exception thrown:

Exception thrown: 'System.NullReferenceException' in AdvancedHMIDrivers.dll

Additional information: Object reference not set to an instance of an object.

If there is a handler for this exception, the program may be safely continued.


Line 464 has the following code "address.TransactionNumber = CUShort(DLL(MyDLLInstance).GetNextTransactionNumber(32767))" where transactionNumber = 0 and MyDLLInstance = 0.

I am recording all the PLC data into a SQL database. I am not using non of the graphical components, everything is hand coded. I create a thread for every PLC and inside that thread I loop all the tags that belong to the specific IP/PLC. I could ignore the error if I wanted to I just wanted to know if this was a bug or maybe I am doing something wrong how I am calling the Com driver.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Is your EthernetIPforCLXCom created in code or did you add that to a form?

When it hits that break point, hover over MyDLLInstance to see what the value is, then hove over DLL to see if the array has a element defined for the MyDLLInstance.

If you continue, the program, do you get any other messages?

hektop

  • Newbie
  • *
  • Posts: 20
    • View Profile
 EthernetIPforCLXCom is created from code like so:

Dim driverType As New AdvancedHMIDrivers.EthernetIPforSLCMicroCom 'creates a micrologix driver
driverType.IPAddress = _PLCinfo.IP 'saves SQL IP address into driver
driverType.PollRateOverride = 10000 'how often the driver gets data from PLC

After hovering the MyDLLInstance value is 0 and the DLL length is 101, each value from the DLL is equal to nothing.

After ignoring the error everything continues like normal.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
I just tried a real quick test, but did not get the exception:
Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim driver As New AdvancedHMIDrivers.EthernetIPforCLXCom(Me.components)
        driver.SynchronizingObject = Me
        driver.IPAddress = "192.168.2.9"

        Me.Text = driver.Read("DINTTag")
    End Sub
« Last Edit: October 14, 2015, 07:56:16 PM by Archie »

hektop

  • Newbie
  • *
  • Posts: 20
    • View Profile
I made a lot of changes to the code and now the error is not showing. I am not sure what was the problem though. Thanks for your reply, and sorry for the hustle.

dmroeder

  • Global Moderator
  • Full Member
  • *****
  • Posts: 208
    • View Profile

hektop

  • Newbie
  • *
  • Posts: 20
    • View Profile
haha, it happens.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
I just tried this same test with the SLCMicro driver, but still not getting the exception.

On a note of declaring a driver instance in code, be sure to to pass the parameter Me.Components, otherwise when you exit the application, it will not perform the ForwardClose which releases the resources in the PLC:

Dim driver As New AdvancedHMIDrivers.EthernetIPforSLCMicroCom(Me.components)