|
-
Sep 23rd, 2015, 01:22 PM
#1
Thread Starter
Member
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.
-
Sep 23rd, 2015, 02:50 PM
#2
Addicted Member
Re: Serial Port Communication - Error: port does not exist
It could be a system device. Not sure why they do that, but my PC has COM15 called Intel Active Management Technology. It does show up however with GetPortNames, but it's not something I can use.
Edit: I see from another thread that you're using a USB/Serial adapter. Can you use device manager to change its COM number?
Last edited by Maylar; Sep 23rd, 2015 at 02:54 PM.
-
Sep 23rd, 2015, 03:46 PM
#3
Thread Starter
Member
Re: Serial Port Communication - Error: port does not exist
I see the comport listed now that I use serialport.getportnames()
but I still encounter the error message, COM18 does not exist when I run the code..
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|