Author Topic: ModbusTCP - Multiple Connector Issues  (Read 2958 times)

TSLJon

  • Newbie
  • *
  • Posts: 24
    • View Profile
ModbusTCP - Multiple Connector Issues
« on: September 09, 2013, 10:34:41 AM »
Firstly an excellent product thank you.

I'm writing some software in VB to query multiple PLC's. Each PLC responds to ModbusTCP and there are 14 of them.

If I add one ModbusTCP Connector to the main form it is fine. If I change the settings in the connector to the 1st PLC it is fine, if I change them to the 2nd PLC, it is fine.

If I add another ModbusTCP Connector it then screws them both up and no data from either connector. Is there some code to change to allow multiple ModbusConnectors to co-exist on one form? Or have I got to target different forms?

Appreciate anyones time! Just downloaded the latest AdvancedHMI3.8Beta today and built on this code.
« Last Edit: September 09, 2013, 10:37:08 AM by TSLJon »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP - Multiple Connector Issues
« Reply #1 on: September 09, 2013, 11:00:55 AM »
In ModbusTCPCom.vb at line 203, there is a subroutine named CreateDLLInstance. This is where it should allow links to multiple devices as long as the IP address are different. I don't have a way to test anything this week, but you may be able to put in a break point and step through that routine to see if it is creating 2 instances of the DLL object when you have 2 on the same form with different IP addresses.

TSLJon

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: ModbusTCP - Multiple Connector Issues
« Reply #2 on: September 09, 2013, 11:26:09 AM »
Hi Archie, thank you for the response appreciate it.

The setup is slightly strange in that the IP address is always the same as I use one external IP address to talk to the engines, and use different ports to access different engines.

For example:
1.1.1.1:50101 - Translates to an internal address of 192.168.1.1 on port 502
1.1.1.1:50102 - Translates to an internal address of 192.168.1.2 on port 502

And so on.

Will this work with the code or will I need to make sure the IP address is different? I can do that by using DNS settings I think which will give different internal values in VB.NET then sort itself out outside of the software. But will give unique values in VB?

Any thoughts?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ModbusTCP - Multiple Connector Issues
« Reply #3 on: September 09, 2013, 11:58:01 AM »
Try to change the CreateDLLInstance routine like below. There are 2 changes. I'm not able to test any of this, so I'm not 100% sure it will work as expected.

Code: [Select]
    Private Sub CreateDLLInstance()
        '* Still default, so ignore
        If m_IPAddress = "0.0.0.0" Then Exit Sub

        If DLL(0) IsNot Nothing Then
            '* At least one DLL instance already exists,
            '* so check to see if it has the same IP address
            '* if so, reuse the instance, otherwise create a new one
            Dim i As Integer
            While DLL(i) IsNot Nothing AndAlso DLL(i).IPAddress <> m_IPAddress AndAlso DLL(i).TcpipPort <> m_TcpipPort AndAlso i < 11
                i += 1
            End While
            MyDLLInstance = i
        End If

        If DLL(MyDLLInstance) Is Nothing Then
            DLL(MyDLLInstance) = New MfgControl.AdvancedHMI.Drivers.ModbusTCP.ModbusTcpDataLinkLayer(m_IPAddress)
            DLL(MyDLLInstance).TcpipPort = m_TcpipPort
            AddHandler DLL(MyDLLInstance).DataReceived, AddressOf DataLinkLayer_DataReceived
            AddHandler DLL(MyDLLInstance).ComError, AddressOf DataLinkLayer_ComError
        End If
    End Sub

TSLJon

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: ModbusTCP - Multiple Connector Issues
« Reply #4 on: September 09, 2013, 12:25:06 PM »
Hi Archie, great thanks for the code. I removed the old set of code and inserted the code you gave.

Error code as attached.

TSLJon

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: ModbusTCP - Multiple Connector Issues
« Reply #5 on: September 09, 2013, 01:50:04 PM »
Just done another test. I've reverted back to the original code and basically used a DNS address in one ModbusTCP and an External IP in another connector and all works fine :)

So if the code can be adapted to work on the same IP address but different ports I would be a very happy man! My other way is to simply create DNS entrys (E.g. engine1.provide.com, engine2.provider.com etc) to allow the code to route that way.

Appreciate all the help Archie thank you.