📄 formmodem.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Frm_Modem
BorderStyle = 3 'Fixed Dialog
Caption = "测试Modem"
ClientHeight = 3270
ClientLeft = 45
ClientTop = 330
ClientWidth = 5655
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3270
ScaleWidth = 5655
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton Cmd_Save
Caption = "保存设置"
Enabled = 0 'False
Height = 375
Left = 3840
TabIndex = 3
Top = 1920
Width = 1095
End
Begin VB.CommandButton Cmd_Test
Caption = "测试Modem"
Enabled = 0 'False
Height = 375
Left = 2280
TabIndex = 2
Top = 1920
Width = 1095
End
Begin VB.CommandButton Cmd_Search
Caption = "检测端口号"
Height = 375
Left = 720
TabIndex = 1
Top = 1920
Width = 1095
End
Begin VB.Frame Frame1
Caption = "端口号"
Height = 975
Left = 720
TabIndex = 0
Top = 795
Width = 4215
Begin VB.OptionButton Option_Com
Caption = "COM4"
Height = 255
Index = 3
Left = 3120
TabIndex = 8
Top = 480
Width = 735
End
Begin VB.OptionButton Option_Com
Caption = "COM3"
Height = 255
Index = 2
Left = 2160
TabIndex = 7
Top = 480
Width = 735
End
Begin VB.OptionButton Option_Com
Caption = "COM2"
Height = 255
Index = 1
Left = 1200
TabIndex = 6
Top = 480
Width = 735
End
Begin VB.OptionButton Option_Com
Caption = "COM1"
Height = 255
Index = 0
Left = 240
TabIndex = 5
Top = 480
Width = 735
End
End
Begin MSCommLib.MSComm MSComm
Left = 120
Top = 240
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin MSComctlLib.ProgressBar ProgressBar
Height = 255
Left = 720
TabIndex = 4
Top = 2640
Visible = 0 'False
Width = 4215
_ExtentX = 7435
_ExtentY = 450
_Version = 393216
Appearance = 1
End
Begin VB.Label Lab
AutoSize = -1 'True
Height = 180
Left = 720
TabIndex = 9
Top = 2640
Width = 90
End
End
Attribute VB_Name = "Frm_Modem"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public ComX As Integer
'系统自动检测端口号
'方法:打开/关闭端口,如果出错,表示不可用端口
Private Sub Cmd_Search_Click()
On Error GoTo ComErr '如果打开端口号出错,则跳转,注意:不能跳转到循环体内。
Dim i As Integer
ComX = -1
Lab.Caption = ""
ProgressBar.Visible = True
ProgressBar.Value = 0 '设置进度条为0
For i = 0 To 3 '禁用所有的选项
Option_Com(i).Enabled = False
Next
For i = 1 To 4
ProgressBar.Value = 25 * i
If MSComm.PortOpen Then MSComm.PortOpen = False '先关闭端口
MSComm.CommPort = i '设置MSCOMM的端口号
If MSComm.PortOpen Then MSComm.PortOpen = False
If Not MSComm.PortOpen Then MSComm.PortOpen = True
MsgBox i
If ComX = -1 Then ComX = i '选定第一个可用的端口号
ComNext:
Next
If ComX = -1 Then End '无可用端口号,则退出
For i = 0 To 3 '启用所有的选项
Option_Com(i).Enabled = True
Next
Option_Com(ComX - 1).Value = True
ProgressBar.Visible = False
ProgressBar.Value = 0
Exit Sub
ComErr:
Resume ComNext '返回到循环体内
End Sub
Private Sub Cmd_Test_Click()
On Error GoTo ComErr
Cmd_Test.Enabled = False
Dim T, M As Single
Dim L, i As Integer
Dim ComBuf As String
For i = 0 To 3
If Option_Com(i).Value Then
ComX = i + 1
End If
Next
If MSComm.PortOpen Then MSComm.PortOpen = False
MSComm.CommPort = ComX
If MSComm.PortOpen = False Then MSComm.PortOpen = True
MSComm.Output = "AT+VCID=1" + vbCr
T = Timer
Lab.Caption = ""
ProgressBar.Visible = True
ProgressBar.Value = 0
Do
ComBuf = ComBuf + MSComm.Input
L = InStr(1, ComBuf, "OK")
M = Timer - T
If M <= 1 Then
ProgressBar.Value = Int(100 * M)
End If
'Loop Until L <> 0 Or M > 1
Loop Until M > 1
ProgressBar.Visible = False
If L = 0 Then
Lab = "不是Modem端口。"
Cmd_Save.Enabled = False
Else
Lab = "COM" + Trim(Str(ComX)) + "为Modem端口号。"
Cmd_Save.Enabled = True
End If
MSComm.Output = "ATS0=0" + vbCr
Exit Sub
ComErr:
Lab = "COM" + Trim(Str(ComX)) + "端口不可用。"
End Sub
Private Sub Form_Load()
Dim i As Integer
ComX = 0 '设置COMX的初值
ProgressBar.Value = 0
'初始化COM,使所有的COM均不选中状态
For i = 0 To 3
Option_Com(i).Value = False
Next
End Sub
Private Sub Option_Com_Click(Index As Integer)
Cmd_Test.Enabled = True
Cmd_Save.Enabled = False
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -