How to read multiple modbus tcp/ip devices at a time?

Posted by Stirthe under VB.NET on 7/2/2013 | Points: 10 | Views : 2213 | Status : [Member] | Replies : 0
How to connect multiple devices at a time? IP addresses as xxx.xx.xx.100, xxx.xx.xx.101, xxx.xx.xx.102, xxx.xx.xx.103, xxx.xx.xx.104, xxx.xx.xx.105, etc and same port number 8000. I am sending request to connected device & the device gives the response. I am able to read data from a device. Timer used for checking connection status & polling with 100ms interval. How to connect & polling multiple devices at a time without blocking to other?

Dim tcpclient As System.Net.Sockets.TcpClient
Dim serverStream As NetworkStream
Dim outStream As Byte()
Dim inStream(8192) As Byte
Dim sendstring As String
Dim client_connected as Boolean = False

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

// interval 100ms
If client_connected = False Then
tcpclient_1 = New System.Net.Sockets.TcpClient
tcpclient_1.SendTimeout = 10
tcpclient_1.ReceiveTimeout = 10

tcpclient_1.Connect("xxx.xx.xx.100", 8000)
client_connected = True
label1.text = "connected"

sendstring = "xxxx"
serverStream = tcpclient_1.GetStream()
outStream = System.Text.Encoding.Default.GetBytes()
serverStream.Write(outStream, 0, outStream.Length)

Dim responseData As [String] = [String].Empty
responseData = serverStream.Read(inStream, 0, _
label2.text = responseData
Catch ex As Exception
client_connected = False
label1.text = "disconnected"
End Try
label1.text = "connected"
End If
End Sub


(No response found.)

Login to post response