📄 com.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7260
ClientLeft = 60
ClientTop = 450
ClientWidth = 4665
LinkTopic = "Form1"
ScaleHeight = 7260
ScaleWidth = 4665
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "接收"
Height = 375
Left = 480
TabIndex = 6
Top = 3120
Width = 615
End
Begin VB.CommandButton Command2
Caption = "发射"
Height = 375
Left = 600
TabIndex = 5
Top = 1440
Width = 495
End
Begin VB.CommandButton Command1
Caption = "清零"
Height = 375
Left = 600
TabIndex = 4
Top = 720
Width = 495
End
Begin VB.TextBox Text2
Enabled = 0 'False
Height = 2655
Left = 480
TabIndex = 3
Top = 4320
Width = 3855
End
Begin VB.TextBox Text1
Height = 3015
Left = 1320
MultiLine = -1 'True
TabIndex = 0
Top = 480
Width = 3015
End
Begin MSCommLib.MSComm MSComm1
Left = 240
Top = 2280
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
InputLen = 1
RThreshold = 1
SThreshold = 1
EOFEnable = -1 'True
InputMode = 1
End
Begin VB.Label Label2
Caption = "wrong code:"
Height = 255
Left = 240
TabIndex = 2
Top = 3960
Width = 1215
End
Begin VB.Label Label1
Caption = "full is 512 byte:"
Height = 255
Left = 1320
TabIndex = 1
Top = 120
Width = 1815
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Activate()
'MSComm1.EOFEnable = True
'MSComm1.PortOpen = True
With MSComm1
.CommPort = 1
.Settings = "9600,n,8,1"
.InputLen = 0
.RThreshold = 1
.PortOpen = True
End With
End Sub
Private Sub MSComm1_OnComm()
On Error GoTo err001
Dim GetChar As String
Select Case MSComm1.CommEvent
Case comEventOverrun '数据丢失。
Text2.Text = "数据丢失!" + "错误"
Case comEventBreak ' 收到 Break。
Case comEventCDTO ' CD (RLSD) 超时。
Text2.Text = " CD (RLSD) 超时。!" + "错误"
Case comEventCTSTO ' CTS Timeout。
Text2.Text = "CTS Timeout" + "错误"
Case comEventDSRTO ' DSR Timeout。
Text2.Text = "DSR Timeout。" + "错误"
Case comEventFrame ' Framing Error
Text2.Text = "Framing Error" + "错误"
Case comEventOverrun '数据丢失。
Text2.Text = "数据丢失。!" + "错误"
Case comEventRxOver '接收缓冲区溢出。
Text2.Text = "接收缓冲区溢出!" + "错误"
Case comEventRxParity ' Parity 错误。
Text2.Text = "Parity 错误!" + "错误"
Case comEventTxFull '传输缓冲区已满。
Text2.Text = "传输缓冲区已满!" + "错误"
Case comEventDCB '获取 DCB] 时意外错误
Text2.Text = "获取 DCB] 时意外错误!" + "错误"
Case comEvReceive ' 收到数据
' 接收数据
' 对数据进行处理
If MSComm1.InBufferCount Then
GetChar = MSComm1.Input
End If
Text1.Text = Text1.Text + GetChar
'执行某一函数(省略)
Case .comEvSend
'发送数据
Case .comEventRxParity
'对奇偶校验错误进行处理
End Select
Exit Sub
err001:
MsgBox Err.Description, vbCritical, "错误"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -