Hi guys! Badly need your help. I'm working on a project in VB.net that will enable my application from sending SMS. I already have the code but I'm getting an error which is "The port 'COM15' does not exist." I've tried to search this error in google but it didn't help at all. Thanks in advance for your help.

Imports System.IO.Ports

Public Class Form1
Dim SerialPort1 As New System.IO.Ports.SerialPort()

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SerialPort1.PortName = "COM15"
SerialPort1.BaudRate = 9600
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.DataBits = 8
SerialPort1.Handshake = Handshake.RequestToSend
SerialPort1.DtrEnable = True
SerialPort1.RtsEnable = True
SerialPort1.NewLine = vbCrLf
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim message As String
message = RichTextBox1.Text

If SerialPort1.IsOpen() Then
SerialPort1.Write("AT" & vbCrLf)
SerialPort1.Write("AT+CMGF=1" & vbCrLf)
SerialPort1.Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf)
SerialPort1.Write(message & Chr(26))
MsgBox("Port not available")

End If

End Sub
End Class

Recommended Answers

All 3 Replies

Do you actually have 15 physical Serial Ports? I don't know for certain, but I suspect that you cannot just arbitrarily decide to give yourself another serial port without the appropriate hardware - at least not using this method. I don't see any mention of a "virtual" port in the docs at MSDN...

You can get a list of available ports using
Dim myAvailablePorts as String() = System.IO.Ports.SerialPort.GetPortNames()

Be aware however, per MSDN:

The port names are obtained from the system registry (for example, HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM). If the registry contains stale or otherwise incorrect data then the GetPortNames method will return incorrect data.

Thank you so much for your advice. It's really helpful!

You're welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.