Serial Port Communication

kaedien

New member
Joined
Oct 2, 2008
Messages
2
Programming Experience
Beginner
Hello trying to build and API that will send data to COM6, 7 or 8 using the SerialPort component in the toolbox.
It works OK with COM1,2 or 3 but when I change it COM6,7 or 8 I get the following error: COM 6 or 7 or 8, does not exit .
here is my code

VB.NET:
Imports System
Imports System.IO.Ports
Public Class Form1
   

 Dim WithEvents SerialPort1 As SerialPort = New System.IO.Ports.SerialPort("COM6", 115200, Parity.None, 8, StopBits.One)


    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
        


        If Not (SerialPort1.IsOpen = True) Then
            SerialPort1.Open()
            SerialPort1.RtsEnable = True
            SerialPort1.DtrEnable = True

            SerialPort1.WriteTimeout = 100
            SerialPort1.Handshake = Handshake.None
        End If



        MessageBox.Show("Connected to the Serial Port")
       
        SerialPort1.WriteLine("a")

        
        MessageBox.Show("Wrote the char a in the serial port")

        
        Me.SerialPort1.Close()


        MessageBox.Show("Serial Port Closed")


    End Sub

    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click

        Me.Close()
    End Sub
End Class
 
Try running this and seeing what port names come back.

VB.NET:
For Each PortName As String In My.Computer.Ports.SerialPortNames
    Me.ListBox1.Items.Add(PortName)
Next

You can substitute My.Computer.Ports.SerialPortNames with System.IO.Ports.SerialPorts.GetPortNames().
 
okay let me try it.
But this application is supposed to run in a Smartphone.

So no that I deploy my application on the smartphone. it say COM 6,9,1 and 3 exist. then when I try to open COM 6 it says COM 6 does not exist this is getting really weird....
 
Back
Top