Author Topic: Binding TCP Drivers to one of two Ethernet Adapter  (Read 5822 times)

Slyd34

  • Newbie
  • *
  • Posts: 2
    • View Profile
Binding TCP Drivers to one of two Ethernet Adapter
« on: July 24, 2024, 11:18:42 AM »
Hey Archie,
I am using two Ethernet adapters on my pc one for office network and the other for industrial network.
Could it be possible to add a property to TCP Drivers for binding to a specific Ethernet adapter by entering the Ip address of the Ethernet adapter i want to use.
Or if i can add code in the TCP driver like ModbusTCP for Binding to the Ethernet adapter i want to use.

Thanks

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Binding TCP Drivers to one of two Ethernet Adapter
« Reply #1 on: July 24, 2024, 07:06:50 PM »
That is a function of .NET and Windows. I would guess that if the driver IP address is on the same subnet as the adapter, Windows would automatically route the packets to the correct Ethernet adapter.

Slyd34

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Binding TCP Drivers to one of two Ethernet Adapter
« Reply #2 on: July 25, 2024, 11:19:47 AM »
Thank you for your quick response Archie,
Thats what I gessed also but in fact Windows does poor management with two Adapters, when The Office network adapter has Internet on it then windows throws everything at it and discards the Industrial network adapter.

The Office Adapter is set to DHCP example: 10.10.14.18 with subnet Mask: 255.255.0.0
the Industrial Network adapter: 192.168.100.200 and PLC: 192.168.100.15, subnet Mask: 255.255.255.0
I tried to change the Matrix in bolth adapters with no luck.

When i disconnect the office adapter then communication to the Industrial Adapter works, Then i can reconnect to the office network adapter and it still works.

I also asked to chatGPT to see if there was a way to do this but i think the binding code has to execute before the driver connection.

Here is a sample of Network Ip binding code:

Imports System.Net
Imports System.Net.Sockets

Public Class ModbusTCPCom
    ' Existing properties and methods...

    Private Sub Connect()
        ' Specify the IP address of the network card you want to bind to
        Dim localIPAddress As String = "192.168.1.10" ' Replace with your network card IP
        Dim localEndPoint As New IPEndPoint(IPAddress.Parse(localIPAddress), 0) ' Port 0 means any available port

        ' Create a new TcpClient instance
        Dim tcpClient As New TcpClient()

        ' Bind the TcpClient to the local endpoint
        tcpClient.Client.Bind(localEndPoint)

        ' Now connect to the Modbus server
        tcpClient.Connect(Me.IPAddress, Me.TcpPort)

        ' Further setup and communication handling...
    End Sub

    ' Existing properties and methods...
End Class

Thanks