Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

Serial Port ReadTimeout Property

I have an application that will read the entire line of a string then parse it out accordingly, what im seeing is that is I set me ReadTimeout to a different number i think the serial port is closing both it gets all the data.... How can I Close the port or control the Readouttime better by just looking for a CRLF rather then an actual variable time.
Public Sub GetDSIInput(ByVal serialPort As IO.Ports.SerialPort, ByVal pfile As PartfileLibrary.Gages)
        Dim bytes(4096) As Byte
        Try
            serialPort.ReadTimeout = 5000
            serialPort.DiscardInBuffer()
 
            Dim strData As String = String.Empty
 
            If Not serialPort.IsOpen Then
                strData = String.Empty
            Else
                strData = serialPort.ReadLine
            End If
 
            If strData.Length > 0 Then
                Dim tempArray() As String
                strData = strData.Replace(vbCrLf, vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")
                'parses out the information gathered from the COM port to a temp location
                tempArray = Split(strData, vbTab)
 
                If serialPort.BaudRate = 9600 Then
                    DSICollector = "585 Plus"
                    Get585PlusData(tempArray)
                Else
                    DSICollector = "501/440"
                    Get501Data(tempArray)
                End If
            End If
 
        Catch tex As TimeoutException
            'do nothing as this will happen while waiting
        Catch ioError As System.IO.IOException
            'do nothing as this will occur sometimes when closing the thread
        Catch ex As Exception
            tListener.AddMethodError(ex)
        End Try
    End Sub

Open in new window

Avatar of ajnt__
ajnt__
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi cmdolcet,

I have written some software to do exactly this, I'm just booting up the old system to get the source code for you...

Ajnt
ASKER CERTIFIED SOLUTION
Avatar of ajnt__
ajnt__
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial