📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 7440
ClientLeft = 60
ClientTop = 450
ClientWidth = 8955
LinkTopic = "Form1"
ScaleHeight = 7440
ScaleWidth = 8955
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton command2
Caption = "接收"
Height = 1455
Left = 6600
TabIndex = 2
Top = 1320
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "存储数据"
Height = 495
Left = 840
TabIndex = 1
Top = 1200
Width = 1095
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 4320
Top = 5760
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Text1
Height = 2535
Left = 3120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Text = "Form1.frx":0000
Top = 1320
Width = 3015
End
Begin MSCommLib.MSComm MSComm1
Left = 1680
Top = 5760
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
CommonDialog1.InitDir = "e:\王玉燕\串口"
CommonDialog1.Filter = "all files(*.*)|*.*|txt(*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
filenum = FreeFile()
CommonDialog1.ShowSave
fname = CommonDialog1.FileName
Open fname For Output As #filenum
Print #filenum, Text1.Text
Close filenum
End Sub
Private Sub Command2_Click()
With MSComm1
.Settings = "9600,N,8,1" '设置通信口参数
.InputMode = comInputModeBinary '设置接收数据模式为二进制形式
.InputLen = 1 '设置input一次从接收缓冲区读取字节数为1
.InBufferCount = 0 '清除接收缓冲区,等待计算机接收的字符数为0
.RThreshold = 1 '设置接收一个字节产生oncomm事件,打开接收
.SThreshold = 0
.PortOpen = True
End With
End Sub
Private Sub Command3_Click()
MSComm1.PortOpen = False
Text1 = ""
End Sub
Private Sub Form_Load()
Text1 = ""
End Sub
Private Sub MSComm1_OnComm()
Dim buffer As Variant
Dim arr() As Byte
Select Case MSComm1.CommEvent
Case comEvReceive
buffer = MSComm1.Input
arr = buffer '返回一组二进制数据
Text1 = Text1 + " " + Hex(arr(0))
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -