Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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.
Posted
Updated 1-Dec-10 13:27pm
v2
Comments
LloydA111 1-Dec-10 16:40pm    
It dosen't sound very helpfull, but have you tried stepping through the code with VS?

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