📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
BackColor = &H80000004&
Caption = "接收数据"
ClientHeight = 7485
ClientLeft = 45
ClientTop = -45
ClientWidth = 7275
BeginProperty Font
Name = "楷体_GB2312"
Size = 14.25
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 7485
ScaleWidth = 7275
StartUpPosition = 1 '所有者中心
Begin VB.Timer Timer1
Interval = 100
Left = 4320
Top = 4680
End
Begin VB.CommandButton Command4
BackColor = &H8000000A&
Caption = "关闭端口(&C)"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 3840
MouseIcon = "Form1.frx":030A
MousePointer = 99 'Custom
Picture = "Form1.frx":0614
Style = 1 'Graphical
TabIndex = 12
ToolTipText = "关闭端口"
Top = 240
Width = 1272
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 2040
TabIndex = 10
Top = 5760
Width = 4695
End
Begin VB.CommandButton Command3
Caption = "串口设置(&K)"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 360
MouseIcon = "Form1.frx":091E
MousePointer = 99 'Custom
Picture = "Form1.frx":0C28
Style = 1 'Graphical
TabIndex = 4
Top = 240
Width = 1335
End
Begin VB.CommandButton Command2
BackColor = &H8000000A&
Caption = "退出(&E)"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 5520
MouseIcon = "Form1.frx":0F32
MousePointer = 99 'Custom
Picture = "Form1.frx":123C
Style = 1 'Graphical
TabIndex = 3
Top = 240
Width = 1272
End
Begin MSCommLib.MSComm MSComm1
Left = 4200
Top = 4080
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
BaudRate = 2400
ParitySetting = 2
DataBits = 7
End
Begin VB.TextBox Text4
BackColor = &H00FF8080&
BeginProperty Font
Name = "黑体"
Size = 13.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 2715
Left = 240
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 1320
Width = 6795
End
Begin VB.CommandButton Command1
BackColor = &H8000000A&
Caption = "开始接收(&S)"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 2160
MaskColor = &H80000004&
MouseIcon = "Form1.frx":1546
MousePointer = 99 'Custom
Picture = "Form1.frx":1850
Style = 1 'Graphical
TabIndex = 1
Top = 240
Width = 1272
End
Begin VB.Label Label9
Caption = $"Form1.frx":1B5A
BeginProperty Font
Name = "楷体_GB2312"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H8000000D&
Height = 975
Left = 240
TabIndex = 14
Top = 6360
Width = 6615
End
Begin VB.Label Label8
Alignment = 2 'Center
AutoSize = -1 'True
BackStyle = 0 'Transparent
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000FF&
Height = 330
Left = 5040
TabIndex = 13
Top = 4680
Width = 1440
End
Begin VB.Label Label7
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "存盘路径为:"
ForeColor = &H000000FF&
Height = 285
Left = 240
TabIndex = 11
Top = 5760
Width = 1890
End
Begin VB.Label Label6
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Label6"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 2160
TabIndex = 9
Top = 5280
Width = 630
End
Begin VB.Label Label5
AutoSize = -1 'True
BackColor = &H00FF00FF&
BackStyle = 0 'Transparent
Caption = "握手协议 :"
ForeColor = &H000000FF&
Height = 285
Left = 240
TabIndex = 8
Top = 5280
Width = 1905
End
Begin VB.Label Label4
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Label4"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 2160
TabIndex = 7
Top = 4800
Width = 630
End
Begin VB.Label Label3
AutoSize = -1 'True
BackColor = &H00FF00FF&
BackStyle = 0 'Transparent
Caption = "串口为 :"
ForeColor = &H000000FF&
Height = 285
Left = 240
TabIndex = 6
Top = 4800
Width = 1920
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Label2"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 210
Left = 2160
TabIndex = 5
Top = 4320
Width = 630
End
Begin VB.Label Label1
AutoSize = -1 'True
BackColor = &H00FF00FF&
BackStyle = 0 'Transparent
Caption = "串口设置为:"
ForeColor = &H000000FF&
Height = 285
Left = 240
TabIndex = 0
Top = 4320
Width = 1905
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Pd As Boolean
Private Sub Command1_Click()
Label8.Caption = "正在接收..."
' 保存输入子串的缓冲区
Dim Instring As String
MSComm1.PortOpen = True
On Error Resume Next
'轮询数据
10 Do
DoEvents
Loop Until MSComm1.InBufferCount >= 64
Instring = MSComm1.Input
Open Trim(Text1.Text) For Append As #1
Print #1, Instring
Close
Text4 = Text4 + Instring
GoTo 10
End Sub
Private Sub Command2_Click()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End
End Sub
Private Sub Command3_Click()
frmProperties.Show
End Sub
Private Sub Command4_Click()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False: Label8.Caption = "端口关闭!"
End Sub
Private Sub Form_Load()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
Me.Show
Form1.MSComm1.Settings = GetSetting(App.Title, "Properties", "Settings", "2400,e,7,1")
Label2.Caption = Form1.MSComm1.Settings
Form1.MSComm1.CommPort = GetSetting(App.Title, "Properties", "CommPort", 1)
Label4.Caption = Form1.MSComm1.CommPort
Form1.MSComm1.Handshaking = GetSetting(App.Title, "Properties", "Handshaking", 0)
Label6.Caption = Form1.MSComm1.Handshaking
Dim Time0 As String
Time0 = Trim(CStr(Time))
If Time0 < "0:10:00" And Time0 > "0:00:00" Then
Text1.Text = App.Path + "\" + Trim(Str(Year(Date))) + Trim(Str(Month(Date))) + Trim(Str(Day(Date) - 1)) + ".txt"
Else
Text1.Text = App.Path + "\" + Trim(Str(Year(Date))) + Trim(Str(Month(Date))) + Trim(Str(Day(Date))) + ".txt"
End If
Pd = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End
End Sub
Private Sub Text3_Change()
End Sub
Private Sub Text4_Change()
Pd = True
End Sub
Private Sub Timer1_Timer()
Dim Time0 As String
Time0 = Trim(CStr(Time))
If Time0 = "0:10:00" Then
Text1.Text = App.Path + "\" + Trim(Str(Year(Date))) + Trim(Str(Month(Date))) + Trim(Str(Day(Date))) + ".txt"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -