📄 form1.vb
字号:
'
'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
Me.optCom2.Text = "COM &2"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Label8)
Me.GroupBox1.Controls.Add(Me.btnTest)
Me.GroupBox1.Controls.Add(Me.txtPortNum)
Me.GroupBox1.Controls.Add(Me.txtTimeout)
Me.GroupBox1.Controls.Add(Me.Label4)
Me.GroupBox1.Controls.Add(Me.txtBaudrate)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.optCom2)
Me.GroupBox1.Controls.Add(Me.optCom1)
Me.GroupBox1.Location = New System.Drawing.Point(7, 11)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(198, 99)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "COM Setup"
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(132, 20)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(58, 14)
Me.Label8.TabIndex = 8
Me.Label8.Text = "Port check"
'
'btnExit
'
Me.btnExit.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.btnExit.Location = New System.Drawing.Point(251, 488)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing.Size(61, 23)
Me.btnExit.TabIndex = 14
Me.btnExit.Text = "&Close"
'
'linkAuthor
'
Me.linkAuthor.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.linkAuthor.Location = New System.Drawing.Point(7, 496)
Me.linkAuthor.Name = "linkAuthor"
Me.linkAuthor.Size = New System.Drawing.Size(81, 12)
Me.linkAuthor.TabIndex = 15
Me.linkAuthor.TabStop = True
Me.linkAuthor.Text = "Contact Author"
'
'lbHex
'
Me.lbHex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lbHex.Location = New System.Drawing.Point(8, 242)
Me.lbHex.Name = "lbHex"
Me.lbHex.Size = New System.Drawing.Size(305, 41)
Me.lbHex.TabIndex = 16
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(8, 226)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(114, 14)
Me.Label6.TabIndex = 17
Me.Label6.Text = "Received Data (Hex)"
'
'cboStatusLine
'
Me.cboStatusLine.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cboStatusLine.Location = New System.Drawing.Point(83, 304)
Me.cboStatusLine.Name = "cboStatusLine"
Me.cboStatusLine.Size = New System.Drawing.Size(97, 21)
Me.cboStatusLine.Sorted = True
Me.cboStatusLine.TabIndex = 18
'
'btnCheck
'
Me.btnCheck.Enabled = False
Me.btnCheck.Location = New System.Drawing.Point(185, 306)
Me.btnCheck.Name = "btnCheck"
Me.btnCheck.Size = New System.Drawing.Size(43, 19)
Me.btnCheck.TabIndex = 19
Me.btnCheck.Text = "Check"
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(84, 288)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(82, 14)
Me.Label7.TabIndex = 20
Me.Label7.Text = "Status line"
'
'lblAsync
'
Me.lblAsync.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.lblAsync.Location = New System.Drawing.Point(7, 411)
Me.lblAsync.Name = "lblAsync"
Me.lblAsync.Size = New System.Drawing.Size(82, 14)
Me.lblAsync.TabIndex = 26
Me.lblAsync.Text = "Async flow"
'
'LinkLabel1
'
Me.LinkLabel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.LinkLabel1.Location = New System.Drawing.Point(119, 496)
Me.LinkLabel1.Name = "LinkLabel1"
Me.LinkLabel1.Size = New System.Drawing.Size(99, 12)
Me.LinkLabel1.TabIndex = 30
Me.LinkLabel1.TabStop = True
Me.LinkLabel1.Text = "www.codeworks.it"
'
'btnInBuffer
'
Me.btnInBuffer.Location = New System.Drawing.Point(8, 371)
Me.btnInBuffer.Name = "btnInBuffer"
Me.btnInBuffer.Size = New System.Drawing.Size(151, 23)
Me.btnInBuffer.TabIndex = 32
Me.btnInBuffer.Text = "Bytes on Rx buffer"
'
'lblInBuffer
'
Me.lblInBuffer.BackColor = System.Drawing.Color.Khaki
Me.lblInBuffer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lblInBuffer.Location = New System.Drawing.Point(170, 372)
Me.lblInBuffer.Name = "lblInBuffer"
Me.lblInBuffer.Size = New System.Drawing.Size(139, 19)
Me.lblInBuffer.TabIndex = 33
Me.lblInBuffer.Text = "?"
Me.lblInBuffer.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.ClientSize = New System.Drawing.Size(319, 514)
Me.Controls.Add(Me.lblInBuffer)
Me.Controls.Add(Me.btnInBuffer)
Me.Controls.Add(Me.chkAddCR)
Me.Controls.Add(Me.LinkLabel1)
Me.Controls.Add(Me.chkEvents)
Me.Controls.Add(Me.lblAsync)
Me.Controls.Add(Me.lbAsync)
Me.Controls.Add(Me.txtBytes2Read)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.btnCheck)
Me.Controls.Add(Me.cboStatusLine)
Me.Controls.Add(Me.Label6)
Me.Controls.Add(Me.lbHex)
Me.Controls.Add(Me.linkAuthor)
Me.Controls.Add(Me.btnExit)
Me.Controls.Add(Me.chkDTR)
Me.Controls.Add(Me.chkRTS)
Me.Controls.Add(Me.chkAutorx)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.btnRx)
Me.Controls.Add(Me.txtRx)
Me.Controls.Add(Me.txtTx)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.btnTx)
Me.Controls.Add(Me.btnCloseCom)
Me.Controls.Add(Me.btnOpenCom)
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "VB.Net Serial comunication example"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnOpenCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenCom.Click
moRS232 = New Rs232()
Try
'// Setup parameters
With moRS232
.Port = miComPort
.BaudRate = Int32.Parse(txtBaudrate.Text)
.DataBit = 8
.StopBit = Rs232.DataStopBit.StopBit_1
.Parity = Rs232.DataParity.Parity_None
.Timeout = Int32.Parse(txtTimeout.Text)
End With
'// Initializes port
moRS232.Open()
'// Set state of RTS / DTS
moRS232.Dtr = (chkDTR.CheckState = CheckState.Checked)
moRS232.Rts = (chkRTS.CheckState = CheckState.Checked)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -