Click here to Skip to main content
14,970,456 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
how to write and get information about serial port.
Posted

Use this, to write on serial port

Public Class Tester
    Public Shared Sub Main
    
        Dim com1Port As IO.Ports.SerialPort = Nothing
        Try
            com1Port = My.Computer.Ports.OpenSerialPort("COM1")
            com1Port.WriteLine("serialData")
            com1Port.Write("serialData")
            com1Port.Close()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        Finally
            If (com1Port IsNot Nothing) Then com1Port.Dispose()
            com1Port = Nothing
        End Try
    End Sub
End Class
   
v2
Fot getting names of all port use this

Option Strict On
Imports System.Collections.ObjectModel
Public Module PortsTest
   Public Sub Main()
      Dim ports As ReadOnlyCollection(Of String) = _
      My.Computer.Ports.SerialPortNames
      For Each port As String In ports
         Console.WriteLine(port)
      Next
   End Sub
End Module
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900