SerialPort.DataReceived Event : SerialPort « Development « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Development » SerialPortScreenshots 
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
1.SerialPort Class Represents a serial port resource.
2.Available Ports
3.Available Parity options
4.Available Stop Bits options
5.Available Handshake options
6.SerialPort.GetPortNames Method Gets an array of serial port names for the current computer.
www__._ja___v__a__2_s_.__c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.