none
implementing time out with serial port read RRS feed

  • Question

  • I have taken over a program which sends commands out the serial port to a custom equipment.

    There is always a response unless someone inadvertently disconnects the cable.

    I am trying to figure out what is the best way to catch the situation where the cable is disconnected and there is no response.

    Do I do a Try/Catch with each SerialPort.Write and set the Timeout property of the serial port to 5 seconds?

    Saturday, April 27, 2019 8:05 PM

All replies

  • Hi,

    I think you set a Timer to determine the status of the serialport.

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim timer1 As New Timer With {.Enabled = True, .Interval = 1000}
            AddHandler timer1.Tick, Sub()
                                        If SerialPort1.IsOpen = False Then
    
                                        End If
    
                                    End Sub
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 29, 2019 1:50 AM