Readbyte Timeout...

I am trying to collect information from a serial device, but sometimes that device might not be connected. When it is not connected, the serialport.ReadByte line of code will just hang forever it seems. Is there a way I can set a timeout value to this

Below is my code....

serialPort.DiscardInBuffer()
serialPort.Write("1" & Chr(gage.MuxPort - 1) & Chr(Asc("1") Xor (gage.MuxPort - 1)))

Dim intloop As Integer
For intloop = 0 To 2
byteArrList.Add(serialPort.ReadByte)
If Not intloop = 2 Then
intCheckSum = intCheckSum Xor byteArrList(intloop)
End If
Next

Thanks,



Answer this question

Readbyte Timeout...

  • Jerry D

    Check the readtimeout property on the serialport object - seems to do what you need.

  • James Spink

    Yep, right after I posted this, I found that. The TimeoutException from the readtimeout property is exactly what I needed.

    Thanks all!!


  • Readbyte Timeout...