# Visual Basic > Visual Basic .NET > VS 2019 Connection timeout - Modbus TCP

## Vizier87

Hi everyone,

I'm attempting to handshake with a Modbus TCP-based ethernet connection of an electric energy meter, ADF400L. (I know the site said Modbus-RTU, but the manual I have said Modbus-TCP though. At this point I'm not sure if they're different?)

It came with a manual, with a MODBUS communication address table.

So naturally I'm just attempting to see if I can just pull some data from it. Here's my code I cobbled up from a tutorial:



```
Imports EasyModbus


Public Class Form1

    Dim ModC As New ModbusClient

    Private Sub ButtonConnect_Click(sender As Object, e As EventArgs) Handles ButtonConnect.Click


        ModC.IPAddress = TextBoxIP.Text
        ModC.Port = 502
        ModC.Connect()

        TimerRead.Start()
    End Sub

    Private Sub BtnDisconnect_Click(sender As Object, e As EventArgs) Handles BtnDisconnect.Click

        TimerRead.Stop()
        ModC.Disconnect()

    End Sub

    Private Sub TimerRead_Tick(sender As Object, e As EventArgs) Handles TimerRead.Tick

        ListBox1.Items.Clear()

        For i = 0 To 100
            Dim vals() As Integer = ModC.ReadHoldingRegisters(i, 2)

            For Each ival In vals
                ListBox1.Items.Add(ival)
            Next



        Next

    End Sub
End Class
```

The IP address I used was reasoned out using IPConfig after connecting the device to my PC, so after that I copied the text and pasted it into the Textbox. So far it seems intuitive.

However, I got an error "connection timeout". Can anyone point me in the right direction here for troubleshooting this?

Thanks.
Vizier87

----------


## OptionBase1

> *The IP address I used was reasoned out using IPConfig after connecting the device to my PC*, so after that I copied the text and pasted it into the Textbox. So far it seems intuitive.
> 
> However, I got an error "connection timeout". Can anyone point me in the right direction here for troubleshooting this?
> 
> Thanks.
> Vizier87


Based on your description, you are most likely using the wrong IP address and/or wrong port, but the bolded section above doesn't completely make sense to me.  How would running ipconfig on your PC tell you what the IP address of this remote device is?

Before even trying to run a single line of code that connects to this device, you should be doing simple communications testing against the IP address you think this thing has.  Can you ping that IP address?  If it has a web interface, can you connect to it with your web browser?  Etc.

Good luck.

----------


## Vizier87

Thanks for the reply.

I disconnected my LAN and connected this device to my pc, and ran ipcomfig. This IP appeared later which is dissimilar from my internet IP. Do you think I got the correct IP?

Thanks for the suggestion, I'll try pinging it and find the right web interface.

----------


## OptionBase1

> Thanks for the reply.
> 
> I disconnected my LAN and connected this device to my pc, and ran ipcomfig. This IP appeared later which is dissimilar from my internet IP. Do you think I got the correct IP?
> 
> Thanks for the suggestion, I'll try pinging it and find the right web interface.


Based on those steps, I can't see how the IP address you see in ipconfig has any relevance to this energy meter.  I would suspect that the energy meter comes configured to obtain an IP address via DHCP, or, if it does come with a hard-coded IP address by default, then that should be explicitly stated in whatever documentation there is for said device.  In any event, I would suspect that the intention for this device would be for it to be plugged in to a switch or router on your network and not plugged "ethernet to ethernet" directly into your PC.  Doing so would likely require the use of a crossover cable in order to communicate, and that goes down a much lengthier discussion that has absolutely 0 relevance to VB.NET, so I'll leave it at that.

The IP address you saw didn't happen to start with 169, did it (169.254.x.x)?  Because that is the Windows default "I can't get an IP address from a DHCP server, so here's an IP address" range, and would have nothing to do with connecting to this energy meter.

I'm not sure I can assist further, sounds like you've got some homework you need to do on your end as far as reading any and all documentation for this device.

Good luck.

----------


## Vizier87

> Based on those steps, I can't see how the IP address you see in ipconfig has any relevance to this energy meter.  I would suspect that the energy meter comes configured to obtain an IP address via DHCP, or, if it does come with a hard-coded IP address by default, then that should be explicitly stated in whatever documentation there is for said device.  In any event, I would suspect that the intention for this device would be for it to be plugged in to a switch or router on your network and not plugged "ethernet to ethernet" directly into your PC.  Doing so would likely require the use of a crossover cable in order to communicate, and that goes down a much lengthier discussion that has absolutely 0 relevance to VB.NET, so I'll leave it at that.
> 
> The IP address you saw didn't happen to start with 169, did it (169.254.x.x)?  Because that is the Windows default "I can't get an IP address from a DHCP server, so here's an IP address" range, and would have nothing to do with connecting to this energy meter.
> 
> I'm not sure I can assist further, sounds like you've got some homework you need to do on your end as far as reading any and all documentation for this device.
> 
> Good luck.


Oh my, you're right. It's 169.xxx.xxx 

Aww shucks man. I'm not really getting much response from the company.

This is the manual from the company.

On page 8, it mentions a page for IP addresses so I tried setting it. 



However, I couldn't ping it though.



I apologize for this being out of VB.NET already, but if you allow me to extend my questions further, if a crossover cable the next logical step, would this product be suitable?

Thanks.

----------


## OptionBase1

> I apologize for this being out of VB.NET already, but if you allow me to extend my questions further, if a crossover cable the next logical step, would this product be suitable?
> 
> Thanks.


Sorry, I don't want to to suggest anything at this point that makes you have to spend any money, because I have no idea if it will help you or not.

----------


## Vizier87

> Sorry, I don't want to to suggest anything at this point that makes you have to spend any money, because I have no idea if it will help you or not.


It's okay, thanks. You've made a difference.

Cheers!

----------

