i use vb.net 2012 and a pin terminal on serialport.
Everthing works fine (sending en receiving), i want that the communication stop after 500 milliseconds if there no reaction from the terminal , reason pin terminal stopped or serial cable loose .
How can i achieve this?
This is code i have So far, but code does not work:
Imports System.IO.Ports
Imports System.IO
Imports System.Threading
Public Shared Sub Main()
Dim mySerialPort As New SerialPort("COM1")
mySerialPort.BaudRate = 9600
mySerialPort.Parity = Parity.Even
mySerialPort.StopBits = StopBits.One
mySerialPort.DataBits = 7
mySerialPort.Handshake = Handshake.None
mySerialPort.ReadTimeout = 500
mySerialPort.WriteTimeout = 500
mySerialPort.RtsEnable = False
mySerialPort.NewLine = vbCr
Dim readThread As New Thread(AddressOf Read)
Try
mySerialPort.Open()
If mySerialPort.IsOpen Then
mySerialPort.Write("test")
mySerialPort.ReadLine
End If
Catch TimeOut As TimeoutException
MessageBox.Show(TimeOut.Message)
End Try
end sub