I'm trying to open a port using "Imports System.IO.Ports" and this function:
Code:#Region "Manager Variables" 'property variables Private _baudRate As String = String.Empty ' Private _parity As String = String.Empty Private _stopBits As String = String.Empty Private _dataBits As String = String.Empty Private _portName As String = String.Empty Private _transType As TransmissionType Private _msg As String Private _type As MessageType 'global manager variables Private comPort As New SerialPort() Private write As Boolean = True #End RegionMy values are set as follows:Code:Public Function OpenPort() As Boolean Try 'first check if the port is already open 'if its open then close it If comPort.IsOpen = True Then comPort.Close() End If comPort.BaudRate = Integer.Parse(_baudRate) comPort.DataBits = Integer.Parse(_dataBits) comPort.StopBits = DirectCast([Enum].Parse(GetType(StopBits), _stopBits), StopBits) comPort.Parity = DirectCast([Enum].Parse(GetType(Parity), _parity), Parity) comPort.PortName = _portName comPort.Open() 'display message _type = MessageType.Normal _msg = "Port opened at " + DateTime.Now + "" + Environment.NewLine + "" MsgBox(_type, _msg) 'return true Return True Catch ex As Exception MsgBox(MessageType.[Error], ex.Message) Return False End Try End Function
comPort.BaudRate = 9600
comPort.DataBits = 8
comPort.StopBits = 1
comPort.PortName = COM18
comport.Parity = "None"
But I get jumped to "Catch ex As Exception" with an error message - COM18 does not exist at line "comport.Open()"
I'm pretty sure it exists as it shows up on my device manager.
Edit: I used the System.IO.Ports.SerialPort.GetPortNames() to see all the available ports and COM18 is not listed. But it shows up on the device manager. Is it not a serial port?




Reply With Quote
