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

📄 form1.vb

📁 一个基于API的Vb.net的串口通讯控件
💻 VB
📖 第 1 页 / 共 2 页
字号:
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 txtRx 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 linkAuthor As System.Windows.Forms.LinkLabel
	Friend WithEvents lbHex As System.Windows.Forms.ListBox
	Friend WithEvents Label6 As System.Windows.Forms.Label
	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 lbAsync As System.Windows.Forms.ListBox
	Friend WithEvents lblAsync As System.Windows.Forms.Label
	Friend WithEvents chkEvents As System.Windows.Forms.CheckBox
	Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
	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
	<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.lbAsync = New System.Windows.Forms.ListBox
		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.txtRx = New System.Windows.Forms.TextBox
		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.linkAuthor = New System.Windows.Forms.LinkLabel
		Me.lbHex = New System.Windows.Forms.ListBox
		Me.Label6 = New System.Windows.Forms.Label
		Me.cboStatusLine = New System.Windows.Forms.ComboBox
		Me.btnCheck = New System.Windows.Forms.Button
		Me.Label7 = New System.Windows.Forms.Label
		Me.lblAsync = New System.Windows.Forms.Label
		Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
		Me.GroupBox1.SuspendLayout()
		Me.SuspendLayout()
		'
		'chkRTS
		'
		Me.chkRTS.Checked = True
		Me.chkRTS.CheckState = System.Windows.Forms.CheckState.Checked
		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, 134)
		Me.btnTx.Name = "btnTx"
		Me.btnTx.Size = New System.Drawing.Size(60, 17)
		Me.btnTx.TabIndex = 7
		Me.btnTx.Text = "Tx"
		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 = "ATZ"
		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 = "Automatically receive bytes"
		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 = "Open COM Port"
		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, 304)
		Me.btnRx.Name = "btnRx"
		Me.btnRx.Size = New System.Drawing.Size(58, 19)
		Me.btnRx.TabIndex = 10
		Me.btnRx.Text = "Rx"
		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.Checked = True
		Me.chkDTR.CheckState = System.Windows.Forms.CheckState.Checked
		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")
		'
		'lbAsync
		'
		Me.lbAsync.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.lbAsync.Location = New System.Drawing.Point(7, 376)
		Me.lbAsync.Name = "lbAsync"
		Me.lbAsync.Size = New System.Drawing.Size(305, 54)
		Me.lbAsync.TabIndex = 25
		Me.ToolTip1.SetToolTip(Me.lbAsync, "Async method sequence")
		'
		'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(124, 19)
		Me.chkEvents.TabIndex = 29
		Me.chkEvents.Text = "Enable events"
		Me.ToolTip1.SetToolTip(Me.chkEvents, "Enables notification events (CommEvent)")
		'
		'chkAddCR
		'
		Me.chkAddCR.Location = New System.Drawing.Point(216, 158)
		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, 64)
		Me.btnTest.Name = "btnTest"
		Me.btnTest.Size = New System.Drawing.Size(49, 17)
		Me.btnTest.TabIndex = 7
		Me.btnTest.Text = "Test"
		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(82, 14)
		Me.Label3.TabIndex = 8
		Me.Label3.Text = "Received Data"
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(7, 120)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(82, 14)
		Me.Label2.TabIndex = 5
		Me.Label2.Text = "Data to Tx"
		'
		'txtRx
		'
		Me.txtRx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
		Me.txtRx.Location = New System.Drawing.Point(7, 178)
		Me.txtRx.Multiline = True
		Me.txtRx.Name = "txtRx"
		Me.txtRx.Size = New System.Drawing.Size(305, 44)
		Me.txtRx.TabIndex = 9
		Me.txtRx.Text = ""
		'
		'optCom1
		'
		Me.optCom1.Checked = True
		Me.optCom1.Location = New System.Drawing.Point(10, 18)
		Me.optCom1.Name = "optCom1"
		Me.optCom1.Size = New System.Drawing.Size(64, 26)
		Me.optCom1.TabIndex = 0
		Me.optCom1.TabStop = True
		Me.optCom1.Text = "COM &1"
		'
		'btnCloseCom
		'
		Me.btnCloseCom.Enabled = False
		Me.btnCloseCom.Location = New System.Drawing.Point(211, 51)
		Me.btnCloseCom.Name = "btnCloseCom"
		Me.btnCloseCom.Size = New System.Drawing.Size(95, 27)
		Me.btnCloseCom.TabIndex = 2
		Me.btnCloseCom.Text = "Close COM Port"
		'
		'optCom2
		'
		Me.optCom2.Location = New System.Drawing.Point(10, 38)
		Me.optCom2.Name = "optCom2"
		Me.optCom2.Size = New System.Drawing.Size(66, 26)
		Me.optCom2.TabIndex = 1

⌨️ 快捷键说明

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