Results 1 to 3 of 3

Thread: Serial Port Communication - Error: port does not exist

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2015
    Posts
    53

    Exclamation Serial Port Communication - Error: port does not exist

    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 Region
    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
    My values are set as follows:
    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?
    Last edited by Lalaluye; Sep 23rd, 2015 at 01:54 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width