_serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate) _serialPort.Parity = SetPortParity(_serialPort.Parity)
_serialPort.DataBits = SetPortDataBits(_serialPort.DataBits) _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits) _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake)
' Set the read/write timeouts _serialPort.ReadTimeout = 500 _serialPort.WriteTimeout = 500
_serialPort.Open() _continue = True readThread.Start()
Console.Write(\) name = Console.ReadLine()
Console.WriteLine(\)
While (_continue)
message = Console.ReadLine()
If sComparer.Equals(\, message) Then
_continue = False Else
_serialPort.WriteLine( _ String.Format(\{1}\, name, message))
End If end while
readThread.Join() _serialPort.Close() End Sub
Public Shared Sub Read() While (_continue) Try
Dim message As String = _serialPort.ReadLine()
Console.WriteLine(message) Catch ex As TimeoutException ' Do nothing End Try End While End Sub
Public Shared Function SetPortName(ByVal defaultPortName As String) As String
Dim newPortName As String
Console.WriteLine(\)
Dim s As String
For Each s In SerialPort.GetPortNames() Console.WriteLine(\, s) Next s
Console.Write(\, defaultPortName)
newPortName = Console.ReadLine()
If newPortName = \ Then
newPortName = defaultPortName End If
Return newPortName End Function
Public Shared Function SetPortBaudRate(ByVal defaultPortBaudRate As Integer) As Integer Dim newBaudRate As String
Console.Write(\, defaultPortBaudRate)
newBaudRate = Console.ReadLine()
If newBaudRate = \ Then newBaudRate = defaultPortBaudRate.ToString() End If
Return Integer.Parse(newBaudRate)
End Function
Public Shared Function SetPortParity(ByVal defaultPortParity As Parity) As Parity Dim newParity As String
Console.WriteLine(\options:\)
Dim s As String
For Each s In [Enum].GetNames(GetType(Parity)) Console.WriteLine(\, s) Next s
Console.Write(\, defaultPortParity.ToString())
newparity = Console.ReadLine()
If newparity = \ Then newparity = defaultPortParity.ToString() End If
Return CType([Enum].Parse(GetType(Parity), newParity), Parity) End Function
Public Shared Function SetPortDataBits(ByVal defaultPortDataBits As Integer) As Integer Dim newDataBits As String
Console.Write(\, defaultPortDataBits)
newDataBits = Console.ReadLine()
If newDataBits = \ Then newDataBits = defaultPortDataBits.ToString() End If
Return Integer.Parse(newDataBits) End Function
Public Shared Function SetPortStopBits(ByVal defaultPortStopBits As StopBits) As StopBits Dim newStopBits As String
Console.WriteLine(\options:\)
Dim s As String For Each s In [Enum].GetNames(GetType(StopBits))
Console.WriteLine(\, s) Next s
Console.Write(\, defaultPortStopBits.ToString())
newStopBits = Console.ReadLine()