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

📄 form1.vb

📁 通过串口实现PC机和下位机的通信
💻 VB
📖 第 1 页 / 共 3 页
字号:
Imports System.Security.Cryptography
Imports System.IO
Imports System
Imports System.Text
Imports System.Object
Imports System.Text.Encoding
Imports System.Data.OleDb
Imports System.Security
Public Class Form1
    Inherits System.Windows.Forms.Form



    '// Private members
    Private miComPort As Integer
    Friend WithEvents btnOpenCom As System.Windows.Forms.Button
    Friend WithEvents btnCloseCom As System.Windows.Forms.Button
    Friend WithEvents btnTx As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtTx As System.Windows.Forms.TextBox
    Friend WithEvents btnRx As System.Windows.Forms.Button
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtBytes2Read As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents optCom2 As System.Windows.Forms.RadioButton
    Friend WithEvents optCom1 As System.Windows.Forms.RadioButton
    Friend WithEvents txtTimeout As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents txtBaudrate As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents chkAutorx As System.Windows.Forms.CheckBox
    Friend WithEvents chkRTS As System.Windows.Forms.CheckBox
    Friend WithEvents chkDTR As System.Windows.Forms.CheckBox
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Private WithEvents moRS232 As Rs232
    Private mlTicks As Long
    Private Delegate Sub CommEventUpdate(ByVal source As Rs232, ByVal mask As Rs232.EventMasks)

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ComponentModel.IContainer


    'Required by the Windows Form Designer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents cboStatusLine As System.Windows.Forms.ComboBox
    Friend WithEvents btnCheck As System.Windows.Forms.Button
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents chkEvents As System.Windows.Forms.CheckBox
    Friend WithEvents chkAddCR As System.Windows.Forms.CheckBox
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents txtPortNum As System.Windows.Forms.TextBox
    Friend WithEvents btnTest As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.chkRTS = New System.Windows.Forms.CheckBox
        Me.btnTx = New System.Windows.Forms.Button
        Me.txtTimeout = New System.Windows.Forms.TextBox
        Me.txtTx = New System.Windows.Forms.TextBox
        Me.chkAutorx = New System.Windows.Forms.CheckBox
        Me.btnOpenCom = New System.Windows.Forms.Button
        Me.txtBaudrate = New System.Windows.Forms.TextBox
        Me.btnRx = New System.Windows.Forms.Button
        Me.txtBytes2Read = New System.Windows.Forms.TextBox
        Me.chkDTR = New System.Windows.Forms.CheckBox
        Me.chkEvents = New System.Windows.Forms.CheckBox
        Me.chkAddCR = New System.Windows.Forms.CheckBox
        Me.txtPortNum = New System.Windows.Forms.TextBox
        Me.btnTest = New System.Windows.Forms.Button
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.optCom1 = New System.Windows.Forms.RadioButton
        Me.btnCloseCom = New System.Windows.Forms.Button
        Me.optCom2 = New System.Windows.Forms.RadioButton
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Label8 = New System.Windows.Forms.Label
        Me.btnExit = New System.Windows.Forms.Button
        Me.cboStatusLine = New System.Windows.Forms.ComboBox
        Me.btnCheck = New System.Windows.Forms.Button
        Me.Label7 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'chkRTS
        '
        Me.chkRTS.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.chkRTS.Location = New System.Drawing.Point(212, 90)
        Me.chkRTS.Name = "chkRTS"
        Me.chkRTS.Size = New System.Drawing.Size(63, 19)
        Me.chkRTS.TabIndex = 3
        Me.chkRTS.Text = "RTS"
        Me.ToolTip1.SetToolTip(Me.chkRTS, "Set state of RTS Line")
        '
        'btnTx
        '
        Me.btnTx.Enabled = False
        Me.btnTx.Location = New System.Drawing.Point(216, 131)
        Me.btnTx.Name = "btnTx"
        Me.btnTx.Size = New System.Drawing.Size(60, 20)
        Me.btnTx.TabIndex = 7
        Me.btnTx.Text = "发送"
        Me.ToolTip1.SetToolTip(Me.btnTx, "Sends data to COM Port")
        '
        'txtTimeout
        '
        Me.txtTimeout.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtTimeout.Location = New System.Drawing.Point(69, 24)
        Me.txtTimeout.Name = "txtTimeout"
        Me.txtTimeout.Size = New System.Drawing.Size(49, 21)
        Me.txtTimeout.TabIndex = 3
        Me.txtTimeout.Text = "1500"
        Me.ToolTip1.SetToolTip(Me.txtTimeout, "COM Port timeout in ms")
        '
        'txtTx
        '
        Me.txtTx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtTx.Location = New System.Drawing.Point(7, 134)
        Me.txtTx.Name = "txtTx"
        Me.txtTx.Size = New System.Drawing.Size(200, 21)
        Me.txtTx.TabIndex = 6
        Me.txtTx.Text = ""
        Me.ToolTip1.SetToolTip(Me.txtTx, "Type data you want to send")
        '
        'chkAutorx
        '
        Me.chkAutorx.Location = New System.Drawing.Point(8, 342)
        Me.chkAutorx.Name = "chkAutorx"
        Me.chkAutorx.Size = New System.Drawing.Size(185, 15)
        Me.chkAutorx.TabIndex = 13
        Me.chkAutorx.Text = "自动接收"
        Me.ToolTip1.SetToolTip(Me.chkAutorx, "After a Tx tries to Rx bytes")
        '
        'btnOpenCom
        '
        Me.btnOpenCom.Location = New System.Drawing.Point(210, 19)
        Me.btnOpenCom.Name = "btnOpenCom"
        Me.btnOpenCom.Size = New System.Drawing.Size(95, 27)
        Me.btnOpenCom.TabIndex = 1
        Me.btnOpenCom.Text = "打开端口"
        Me.ToolTip1.SetToolTip(Me.btnOpenCom, "Initializes and Open COM port")
        '
        'txtBaudrate
        '
        Me.txtBaudrate.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtBaudrate.Location = New System.Drawing.Point(69, 60)
        Me.txtBaudrate.Name = "txtBaudrate"
        Me.txtBaudrate.Size = New System.Drawing.Size(49, 21)
        Me.txtBaudrate.TabIndex = 5
        Me.txtBaudrate.Text = "9600"
        Me.ToolTip1.SetToolTip(Me.txtBaudrate, "COM Port Baudrate")
        '
        'btnRx
        '
        Me.btnRx.Enabled = False
        Me.btnRx.Location = New System.Drawing.Point(8, 300)
        Me.btnRx.Name = "btnRx"
        Me.btnRx.Size = New System.Drawing.Size(58, 23)
        Me.btnRx.TabIndex = 10
        Me.btnRx.Text = "接收"
        Me.ToolTip1.SetToolTip(Me.btnRx, "Reads COM Buffer")
        '
        'txtBytes2Read
        '
        Me.txtBytes2Read.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtBytes2Read.Location = New System.Drawing.Point(245, 305)
        Me.txtBytes2Read.Name = "txtBytes2Read"
        Me.txtBytes2Read.Size = New System.Drawing.Size(65, 21)
        Me.txtBytes2Read.TabIndex = 12
        Me.txtBytes2Read.Text = "2"
        Me.ToolTip1.SetToolTip(Me.txtBytes2Read, "Bytes to read from COM buffer (this number effects also CommEvent)")
        '
        'chkDTR
        '
        Me.chkDTR.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.chkDTR.Location = New System.Drawing.Point(260, 90)
        Me.chkDTR.Name = "chkDTR"
        Me.chkDTR.Size = New System.Drawing.Size(63, 19)
        Me.chkDTR.TabIndex = 4
        Me.chkDTR.Text = "DTR"
        Me.ToolTip1.SetToolTip(Me.chkDTR, "Set state of DTR Line")
        '
        'chkEvents
        '
        Me.chkEvents.Enabled = False
        Me.chkEvents.FlatStyle = System.Windows.Forms.FlatStyle.System
        Me.chkEvents.Location = New System.Drawing.Point(186, 342)
        Me.chkEvents.Name = "chkEvents"
        Me.chkEvents.Size = New System.Drawing.Size(96, 19)
        Me.chkEvents.TabIndex = 29
        Me.chkEvents.Text = "自动发送"
        Me.ToolTip1.SetToolTip(Me.chkEvents, "Enables notification events (CommEvent)")
        '
        'chkAddCR
        '
        Me.chkAddCR.Location = New System.Drawing.Point(212, 156)
        Me.chkAddCR.Name = "chkAddCR"
        Me.chkAddCR.Size = New System.Drawing.Size(79, 13)
        Me.chkAddCR.TabIndex = 31
        Me.chkAddCR.Text = "Add CR"
        Me.ToolTip1.SetToolTip(Me.chkAddCR, "Add a CR at the end of Tx Message")
        '
        'txtPortNum
        '
        Me.txtPortNum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPortNum.Location = New System.Drawing.Point(132, 36)
        Me.txtPortNum.Name = "txtPortNum"
        Me.txtPortNum.Size = New System.Drawing.Size(49, 21)
        Me.txtPortNum.TabIndex = 6
        Me.txtPortNum.Text = "1"
        Me.ToolTip1.SetToolTip(Me.txtPortNum, "Enter port number")
        '
        'btnTest
        '
        Me.btnTest.Location = New System.Drawing.Point(132, 61)
        Me.btnTest.Name = "btnTest"
        Me.btnTest.Size = New System.Drawing.Size(50, 20)
        Me.btnTest.TabIndex = 7
        Me.btnTest.Text = "测试"
        Me.ToolTip1.SetToolTip(Me.btnTest, "Test port availability")
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(240, 290)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(82, 14)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "Bytes to read"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(69, 10)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(82, 14)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Timeout (ms)"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(69, 46)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(82, 14)
        Me.Label4.TabIndex = 4
        Me.Label4.Text = "BaudRate"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(7, 164)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(90, 14)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "接收数据(HEX)"

⌨️ 快捷键说明

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