⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lineterm.vb

📁 C#串口编程。详细讲解
💻 VB
字号:
Imports JH.CommBase

Public Class LineTerm
    Inherits CommLine

    Public Sub SendCommand(ByVal s As String)
        Send(s)
    End Sub

    Public Sub TransactCommand(ByVal s As String)
        Dim r As String
        r = Transact(s)
        Console.WriteLine("RESPONSE: " + r)
        Prompt()
    End Sub

    Public Sub Prompt()
        Console.WriteLine("Type string to send and press ENTER. Empty string to close com port.")
    End Sub

    Protected Overrides Function CommSettings() As CommBaseSettings
        Dim cs As New CommLineSettings()
        cs.SetStandard("COM1:", 19200, Handshake.none)
        cs.rxFilter = New ASCII() {ASCII.LF, ASCII.SOH}
        cs.rxTerminator = ASCII.CR
        cs.txTerminator = New ASCII() {ASCII.CR}
        Setup(cs)
        Return cs
    End Function

    Protected Overrides Sub OnRxLine(ByVal s As String)
        Console.WriteLine("RECEIVED: " + s)
        Prompt()
    End Sub

    Protected Overrides Sub OnTxDone()
        Console.WriteLine("TRANSMISSION COMPLETE")
        Prompt()
    End Sub

End Class
Module Module1

    Sub Main()
        Dim t As New LineTerm()
        Dim c As String
        Console.WriteLine("Press ENTER to open com port")
        Console.ReadLine()
        If t.Open() Then
            Console.WriteLine("COM PORT OPEN")
            t.Prompt()
            While True
                c = Console.ReadLine().Trim
                If c = "" Then Exit While
                t.SendCommand(c)
                't.TransactCommand(c)
            End While
            t.Close()
        End If
        Console.WriteLine("COM PORT CLOSED")
        Console.WriteLine("Press ENTER to close program.")
        Console.ReadLine()
    End Sub

End Module

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -