本文整理汇总了VB.NET中System.IO.Ports.SerialPort.DataReceived事件的典型用法代码示例。如果您正苦于以下问题:VB.NET SerialPort.DataReceived事件的具体用法?VB.NET SerialPort.DataReceived怎么用?VB.NET SerialPort.DataReceived使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.IO.Ports.SerialPort
的用法示例。
在下文中一共展示了SerialPort.DataReceived事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: PortDataReceived
' 导入命名空间
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
mySerialPort.RtsEnable = True
AddHandler mySerialPort.DataReceived, AddressOf DataReceivedHandler
mySerialPort.Open()
Console.WriteLine("Press any key to continue...")
Console.WriteLine()
Console.ReadKey()
mySerialPort.Close()
End Sub
Private Shared Sub DataReceivedHandler(
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