📄 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 = 5250
ClientLeft = 60
ClientTop = 375
ClientWidth = 5700
LinkTopic = "Form1"
ScaleHeight = 5250
ScaleWidth = 5700
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Interval = 300
Left = 4080
Top = 4320
End
Begin VB.CommandButton Command5
Caption = "Command5"
Height = 495
Left = 4200
TabIndex = 6
Top = 1920
Width = 1335
End
Begin MSComDlg.CommonDialog CmdLg
Left = 5040
Top = 4440
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Text2
Height = 2415
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Top = 120
Width = 3975
End
Begin VB.CommandButton Command4
Caption = "发送"
Height = 495
Left = 4200
TabIndex = 4
Top = 120
Width = 1335
End
Begin VB.CommandButton Command3
Caption = "打开串口"
Height = 495
Left = 4200
TabIndex = 3
Top = 1020
Width = 1335
End
Begin VB.CommandButton Command2
Caption = "关闭串口"
Height = 495
Left = 4200
TabIndex = 2
Top = 3720
Width = 1335
End
Begin VB.TextBox Text1
Height = 2415
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 2760
Width = 3975
End
Begin VB.CommandButton Command1
Caption = "读取文件"
Height = 495
Left = 4200
TabIndex = 0
Top = 2820
Width = 1335
End
Begin MSCommLib.MSComm MSComm
Left = 4440
Top = 4440
_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()
On Error Resume Next
Dim sdat As Integer
Dim rdat As String
CmdLg.ShowOpen
If CmdLg.FileName = "" Then Exit Sub
Open CmdLg.FileName For Binary As #1
While Not EOF(1)
Line Input #1, rdat
rdat = Int(rdat)
sdat = sdat & rdat
If Text2.Text = "" Then
Text2.Text = rdat
Else
Text2.Text = Text2.Text & vbCrLf & rdat
End If
Wend
Close #1
End Sub
Private Sub Command2_Click()
If MSComm.PortOpen = False Then
MsgBox "设备已关闭", vbInformation + vbOKOnly, "警告"
Exit Sub
Else
MSComm.PortOpen = False
End If
End Sub
Private Sub Command3_Click()
If MSComm.PortOpen = True Then
MsgBox "设备已打开", vbInformation + vbOKOnly, "警告"
Exit Sub
Else
MSComm.PortOpen = True
End If
End Sub
Private Sub Command4_Click()
If MSComm.PortOpen = True Then
MSComm.Output = Text2.Text
Else
MsgBox "串口未打开", vbInformation + vbOKOnly, "警告"
End If
End Sub
Private Sub Form_Load()
MSComm.CommPort = 1
MSComm.Settings = "19200,N,8,1"
MSComm.InputLen = 0
MSComm.PortOpen = True
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
Dim a As Integer
If MSComm.PortOpen = True Then
a = MSComm.Input
If a = "" Then Exit Sub
If Text1.Text = "" Then
Text1.Text = Hex(a)
Else
Text1.Text = Text1.Text & vbCrLf & Hex(a)
End If
Else
'MsgBox "串口未打开", vbInformation + vbOKOnly, "警告"
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -