Hi all, I have this little problem with these devices connected with my computer. I got 4 devices connected through switch and this works fine, the communication and all. However these devices seem to have some buggy connection.
Now, I connect to these devices and the devices respond, however sometimes they get bugged out and do not respond properly. If I restart my application then the devices work again. Here is some code
Public Shared ConB As New TcpClient
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ConB.Connect(ipB, 1701)
Dim bytesB(ConB.ReceiveBufferSize) As Byte
ConB.GetStream().Read(bytesB, 0, CInt(ConB.ReceiveBufferSize))
returndataB = Encoding.ASCII.GetString(bytesB)
If InStr(returndataBk, "Ready for user") > 0 Then
senddataBk = Encoding.ASCII.GetBytes("user admin" & vbCr)
ConB.GetStream().Write(senddataB, 0, senddataB.Length)
ConB.GetStream().Read(bytesB, 0, CInt(ConB.ReceiveBufferSize))
returndataB = Encoding.ASCII.GetString(bytesB)
If InStr(returndataB, "Access OK") > 0 Then
stateBok = True
Else
stateBok = False
End If
End If
End Sub
OK, so the problem is, the device always responds with "Ready for user", but when I send it "user admin" it should respond with "Access OK", however it sometimes it responds with "Ready for user" again, and this will continue to happen until I restart my app and the connection gets connected again.
My question is can I somehow close the connection and reopen it considering that the ConB is a public TcpClient and I need it in other methods. This has to be done only upon startup of the app, I need all four devices to respond with "Access OK".
Thanks.