SerialPort.DataReceived Event
Imports System
Imports System.IO.Ports
Class PortDataReceived
Public Shared Sub Main()
Dim mySerialPort As New SerialPort("COM1")
mySerialPort.BaudRate = 9600
mySerialPort.Parity = Parity.None
mySerialPort.StopBits = StopBits.One
mySerialPort.DataBits = 8
mySerialPort.Handshake = Handshake.None
AddHandler mySerialPort.DataReceived, AddressOf DataReceviedHandler
mySerialPort.Open()
Console.WriteLine("Press any key to continue...")
Console.ReadKey()
mySerialPort.Close()
End Sub
Private Shared Sub DataReceviedHandler(sender As Object,e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Dim indata As String = sp.ReadExisting()
Console.WriteLine("Data Received:")
Console.Write(indata)
End Sub
End Class
Related examples in the same category