Alright, here is my issue. I am using the IO.Ports.SerialPort namespace
for the following method. In a previous method, I already set the
serial port up using the proper baudrate, parity, etc.
The issue I am having is that the code will execute fine the first time
it runs through, but any time after that it is called, the timeout
exception occurs. Any ideas on why this might happen?
Here is the code...
Public Sub GetSonyGageValues(ByVal serialPort As IO.Ports.SerialPort)
Try
Dim byteArrList As New ArrayList
Dim intCheckSum As Integer
byteArrList.Clear()
intCheckSum = 0
serialPort.ReadTimeout = 500
serialPort.WriteTimeout = 50
serialPort.DiscardInBuffer()
serialPort.Write("R" & vbCrLf)
Dim strData As String = serialPort.ReadLine
If strData.Length 0 Then
Dim tempArray() As String
'parses out the information gathered from the COM port
to a temp location
tempArray =
Split(strData.TrimEnd(vbCrLf).TrimEnd(vbCr), " ")
Dim intloop As Integer
For intloop = 0 To tempArray.Length - 1
Dim arrLoc As Integer = CInt("&h" &
Hex(tempArray(intloop).Substring(0, 2)))
If InStr(tempArray(intloop).Substring(5, 8),
"Error") Then
sngSonyValues(arrLoc) = 4096
Else
If tempArray(intloop).Substring(5, 1) = "+"
Then
sngSonyValues(arrLoc) =
CSng(tempArray(intloop).Substring(6, 7))
Else
sngSonyValues(arrLoc) =
CSng(tempArray(intloop).Substring(5, 8))
End If
End If
Next
End If
Catch tex As TimeoutException
_boolMuxError = True
InputBadReadings()
Catch ioex As IO.IOException
'do nothing as this may occur when going into calibration
Catch invalopEx As System.InvalidOperationException
'do nothing as this may occur when going into calibration
Catch ex As Exception
tListener.AddMethodError(ex)
End Try
End Sub