📄 frminit.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form FrmInit
Caption = "TC35连接与初始化设置"
ClientHeight = 2520
ClientLeft = 60
ClientTop = 450
ClientWidth = 5175
LinkTopic = "Form1"
ScaleHeight = 2520
ScaleWidth = 5175
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Cmdcancel
Caption = "退出系统"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3840
TabIndex = 6
Top = 1680
Width = 1095
End
Begin VB.TextBox SMSCTxt
Height = 375
Left = 2160
TabIndex = 5
Top = 960
Width = 2055
End
Begin MSCommLib.MSComm MSComm1
Left = 4440
Top = 360
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton CmdQuit
Caption = "断开"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2400
TabIndex = 3
Top = 1680
Width = 1215
End
Begin VB.CommandButton CmdConnect
Caption = "系统连接与初始化"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 120
TabIndex = 2
Top = 1680
Width = 2055
End
Begin VB.ComboBox CmbPort
Height = 315
Left = 2160
TabIndex = 1
Top = 360
Width = 1935
End
Begin VB.Label Label2
Caption = "短消息中心号码:"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 375
Left = 120
TabIndex = 4
Top = 960
Width = 1815
End
Begin VB.Label Label1
Caption = "请选择您使用的端口:"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 255
Left = 120
TabIndex = 0
Top = 360
Width = 2295
End
End
Attribute VB_Name = "FrmInit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Option Explicit
Dim port(5)
Private Function timedelay(n As Integer) '延时函数
Dim savetime As Double
savetime = timeGetTime()
While timeGetTime < savetime + n '循环等待
DoEvents '转让控制权,以便让操作系统处理其它的事件
Wend
End Function
Private Function ATCMD(s1 As String, s2 As String) As Boolean
Dim dummyar As Integer
Dim receivebuffer As String, tmpbool As Boolean
MSComm1.InBufferCount = 0
MSComm1.Output = s1 + vbCr
timedelay (100)
If MSComm1.InBufferCount > 0 Then
receivebuffer = receivebuffer + MSComm1.Input
If InStr(receivebuffer, "OK") Then
tmpbool = True
End If
If InStr(receivebuffer, "ERROR") Then
tmpbool = False
End If
End If
ATCMD = tmpbool
End Function
Private Sub Cmdcancel_Click()
Unload Me
End
End Sub
Private Sub CmdConnect_Click()
Dim cs As String, cn As String, cf As String
Dim smscNO As String
On Error GoTo err
portitem = Val(CmbPort.Text) 'PortItem为全局变量,保存串行端口号
MSComm1.CommPort = portitem
MSComm1.PortOpen = True '打开端口
If Not ATCMD("AT", "连接测试") Then
GoTo connectFail
End If
MsgBox "连接成功!"
cn = "AT+CNMI=2,1,0,0,1"
If SMSCTxt.Text = "" Then
GoTo smscfail
Else
smscNO = Trim(SMSCTxt.Text)
cs = "AT+CSCA=" & Chr$(34) & smscNO & Chr$(34)
SMSCTxt.Enabled = False
End If
cf = "AT+CMGF=0"
If Not ATCMD(cn, "选择新的短消息提示") Then
GoTo InitFail
End If
If Not ATCMD(cs, "短消息服务中心号码设置") Then
GoTo InitFail
End If
If Not ATCMD(cf, "选择短消息支持文字格式") Then
GoTo InitFail
End If
MsgBox "初始化正常!"
Unload Me
Exit Sub
err:
MsgBox "对不起,您选择的端口已经被打开,请选择别的端口", vbOKOnly, "通知"
Exit Sub
connectFail: MsgBox "连接失败!"
Exit Sub
InitFail: MsgBox "初始化出错!"
Exit Sub
smscfail: MsgBox "请输入短消息中心号码!"
End Sub
Private Sub CmdQuit_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
SMSCTxt.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
port(0) = "1"
port(1) = "2"
port(2) = "3"
port(3) = "4"
port(4) = "5"
For i = 0 To 4
CmbPort.AddItem port(i)
Next i
CmbPort.ListIndex = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -