Click here to Skip to main content
15,920,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I an writing a program to read data from DT80 supporting Modbus RTU.My below VB. net2010 code is able to connnect DT80, but not reading register value to the form text box.
Please help me. Thanks in advance.

What I have tried:

Dim ModbusClient As EasyModbus.ModbusClient = New EasyModbus.ModbusClient(Me.TextBox1.Text, Me.TextBox2.Text)  'connecting using IP, port


    TextBox3.Text = ComError
    TextBox3.ForeColor = Color.Green
    Label4.Text = "Connected to Slave"
    Label4.ForeColor = Color.Green
    If TextBox3.Text = 0 Then
        Label4.Text = "logging......"
        Dim Regs As Integer()
        Regs = ModbusClient.ReadHoldingRegisters(4, 5)

        Me.TextBox4.Text = Regs(0)
        Me.TextBox5.Text = Regs(1)
        Me.TextBox6.Text = Regs(2)
        Me.TextBox7.Text = Regs(3)
        Me.TextBox8.Text = Regs(4)


    End If

Catch ex As Exception
    TextBox3.Text = 1
    TextBox3.ForeColor = Color.Red
    Label4.Text = "Connection Error!"
    Label4.ForeColor = Color.Red
End Try
Updated 11-Mar-17 1:11am

1 solution

Regs = ModbusClient.ReadHoldingRegisters(4, 5)

are you sure ? I thought holding registers were in the range(s)

30001-31000 Channel Variables 1-1000
34001-34053 System Variables 1-52
38000-38009 Digitals 1-8 & Relay
Share this answer
ramen79 13-Mar-17 2:49am    
i have tried with the below, unable to get data

Regs = ModbusClient.ReadHoldingRegisters(30001, 5)
Regs = ModbusClient.ReadHoldingRegisters(3, 5)
Garth J Lancaster 13-Mar-17 5:37am    
one thing that we found using MODBUS, was the register numbers needed to be offset by 1 'one' - can you please try Regs = ModbusClient.ReadHoldingRegisters(30000, 5)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900