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

📄 form1.vb

📁 WINCE 下的串口源码,VB.NET2003编写
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()

        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        MyBase.Dispose(disposing)
    End Sub

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.Timer1 = New System.Windows.Forms.Timer
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(256, 192)
        Me.Button1.Size = New System.Drawing.Size(80, 32)
        Me.Button1.Text = "Button1"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(160, 40)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Size = New System.Drawing.Size(48, 32)
        Me.TextBox1.Text = ""
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(264, 40)
        Me.TextBox2.Multiline = True
        Me.TextBox2.Size = New System.Drawing.Size(48, 32)
        Me.TextBox2.Text = ""
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(368, 40)
        Me.TextBox3.Multiline = True
        Me.TextBox3.Size = New System.Drawing.Size(48, 32)
        Me.TextBox3.Text = ""
        '
        'Timer1
        '
        Me.Timer1.Enabled = True
        '
        'Form1
        '
        Me.ClientSize = New System.Drawing.Size(538, 320)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Text = "Form1"

    End Sub

    Public Shared Sub Main()
        Application.Run(New Form1)
    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' //Timer1.Enabled(1)
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim m_cs232 As New CRs232

        m_cs232.openPort() '打开串口
        Dim send() As Byte = {&H1, &H2, &H3}
        m_cs232.write(send)  '发送

        Dim i As Integer = m_cs232.GetReadBuffer() '得到串口输入缓冲区当前字节数


        Dim rev() As Byte
        rev = m_cs232.read(3)  '读取3个字节
        TextBox1.Text = rev(0).ToString
        TextBox2.Text = rev(1).ToString

        TextBox3.Text = rev(2).ToString


        m_cs232.clsPort() '清空串口输入缓冲区
        m_cs232.closePort() '最后别忘记关了串口
    End Sub

    Private Sub PictureBox1_ParentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'PictureBox1.l()
    End Sub
End Class

⌨️ 快捷键说明

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