
Public doc As Object
Public app As Object
Dim a As Boolean

Private Sub CommandButton1_Click()

Set app = CreateObject("Mbpoll.Application")
Set doc = CreateObject("mbpoll.Document")

app.Connection = 1

app.IPAddress = "127.0.0.1"
app.ServerPort = 502
app.IPVersion = 4
app.ConnectTimeout = 1000




res = app.OpenConnection()

'Read 10 holding registers from slave ID 1, address 0 (40001) every 100ms
res = doc.ReadHoldingRegisters(1, 0, 1, 100)

End Sub





Private Sub CommandButton2_Click()

a = False
    For i = 2 To 1000
 
         Cells(i, 1) = doc.SRegisters(0)
         Cells(2, 3) = doc.SRegisters(0)
         Cells(i, 2) = Time + Date
         tt = Timer
         dd = Date
         While Timer < tt + 1 And dd = Date
            DoEvents
         Wend
         If a = True Then
          status = app.CloseConnection()
          Exit For
         End If
    Next i

End Sub





Private Sub CommandButton3_Click()
a = True
status = app.CloseConnection()
End Sub