📄 串口通迅v0.1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form RS232_VB
Caption = "串口调试器"
ClientHeight = 5190
ClientLeft = 60
ClientTop = 450
ClientWidth = 7155
Icon = "串口通迅V0.1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 5190
ScaleWidth = 7155
StartUpPosition = 2 '屏幕中心
Begin MSCommLib.MSComm MSComm
Left = 240
Top = 2280
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton Button_RECV_C
Caption = "清空接收文本框"
Height = 375
Left = 2640
TabIndex = 6
Top = 4680
Width = 1575
End
Begin VB.CommandButton Button_SEND_C
Caption = "清空发送数据"
Height = 375
Left = 4440
TabIndex = 5
Top = 2280
Width = 1335
End
Begin VB.CommandButton Button_SEND
Caption = "发送数据"
Height = 375
Left = 1800
TabIndex = 4
Top = 2280
Width = 1215
End
Begin VB.TextBox Text_RECV
Height = 1575
Left = 1200
TabIndex = 1
Top = 2880
Width = 5535
End
Begin VB.TextBox Text_SEND
Height = 1695
Left = 1200
TabIndex = 0
Top = 360
Width = 5535
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "作者:zjz868@163.com"
Height = 180
Left = 5160
TabIndex = 7
Top = 4920
Width = 1800
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "接收数据"
Height = 180
Left = 240
TabIndex = 3
Top = 3720
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "发送数据"
Height = 180
Left = 240
TabIndex = 2
Top = 840
Width = 720
End
End
Attribute VB_Name = "RS232_VB"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Button_RECV_C_Click()
Text_RECV.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Button_SEND_C_Click()
Text_SEND.Text = ""
Text_SEND.SetFocus
End Sub
Private Sub Button_SEND_Click() ' 发送数据
Dim X As String
If Text_SEND.Text = "" Then '发送不能为空
X = MsgBox("发送数据不能为空", 16)
Exit Sub
End If
If Not MSComm.PortOpen Then
MSComm.PortOpen = True
End If
MSComm.Output = Text_SEND.Text + Chr$(13) '发送数据
For i = 1 To 2000000 '延时
Next
End Sub
Private Sub Form_Load()
MSComm.CommPort = 1 '设置串口1
MSComm.Settings = "9600,n,8,1" '波特率9600bit/s,无效验,8位数据,1位停止位
MSComm.InputLen = 0 '读取接收缓冲区的所有字符
MSComm.InBufferSize = 1024 '设置接收缓冲区为1024字节
MSComm.OutBufferSize = 512 '设置发送缓冲区为512字节
MSComm.PortOpen = True '打开串口
MSComm.SThreshold = 0 '不触发事件
MSComm.RThreshold = 1 '每一个字符到接收缓冲区都触发接收事件
MSComm.InBufferCount = 0 '清除发送区的数据
MSComm.OutBufferCount = 0 '清除接收区的缓冲区数据
Text_SEND.Text = "" '清空发送文本
Text_RECV.Text = "" '清空接收文本
End Sub
Private Sub MSComm_OnComm()
Select Case MSComm.CommEvent '检验串口事件
'错误处理
Case comEventOverrun ' 数据丢失
Text_SEND.Text = "" '清空发送缓冲区
Text_RECV.Text = "" '清空接收缓冲区
Text_SEND.SetFocus
Exit Sub
Case comEventRxOver '接收缓冲区溢出
Text_SEND.Text = "" '清空发送缓冲区
Text_RECV.Text = "" '清空接收缓冲区
Text_SEND.SetFocus
Exit Sub '事件处理
Case comEventTxFull '发送缓冲区已满
Text_SEND.Text = "" '清空发送缓冲区
Text_RECV.Text = "" '清空接收缓冲区
Text_SEND.SetFocus
Exit Sub '事件处理
Case comEvReceive '接收缓冲区有数据
Dim str As String
str = MSComm.Input '从接收队列中读入字符串
Text_RECV.Text = Text_RECV.Text + str '读出字符串送显
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -