📄 smstest.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form main1
Caption = "速率"
ClientHeight = 7605
ClientLeft = 60
ClientTop = 450
ClientWidth = 10905
LinkTopic = "Form1"
ScaleHeight = 7605
ScaleWidth = 10905
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox del_index
Height = 495
Left = 9120
TabIndex = 22
Text = "0"
Top = 6840
Width = 495
End
Begin VB.CommandButton sms_del
Caption = "删除"
Height = 495
Left = 9600
TabIndex = 21
Top = 6840
Width = 855
End
Begin VB.CommandButton sms_get
Caption = "接收"
Height = 495
Left = 9120
TabIndex = 20
Top = 6120
Width = 1335
End
Begin VB.TextBox sms_receive
Height = 1455
Left = 360
MultiLine = -1 'True
TabIndex = 19
Text = "smstest.frx":0000
Top = 6000
Width = 8535
End
Begin VB.TextBox sms_send
Height = 975
Left = 3960
TabIndex = 17
Text = "Text3"
Top = 4800
Width = 4935
End
Begin VB.TextBox tonumber
Height = 375
Left = 2160
TabIndex = 16
Text = "13906199166"
Top = 5280
Width = 1575
End
Begin VB.CheckBox find_sms_in
Caption = "侦测来信"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 9000
TabIndex = 14
Top = 2040
Width = 1575
End
Begin VB.CommandButton com_disconnect
Caption = "断开"
Height = 495
Left = 6720
TabIndex = 13
Top = 240
Width = 1095
End
Begin VB.CommandButton com_connect
Caption = "连接"
Height = 495
Left = 5280
TabIndex = 12
Top = 240
Width = 1095
End
Begin VB.TextBox com_set
Height = 495
Left = 3720
TabIndex = 11
Text = "19200,n,8,1"
Top = 240
Width = 1095
End
Begin VB.TextBox com_num
Height = 495
Left = 1560
TabIndex = 10
Text = "2"
Top = 240
Width = 975
End
Begin VB.CommandButton send_at
Caption = "发送"
Height = 495
Left = 9000
TabIndex = 7
Top = 1440
Width = 1335
End
Begin MSCommLib.MSComm MSComm1
Left = 10080
Top = 120
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton smssend
Caption = "短信发送"
Height = 735
Left = 9120
TabIndex = 6
Top = 4800
Width = 1215
End
Begin VB.TextBox com_out
Height = 1695
Left = 2160
MultiLine = -1 'True
TabIndex = 5
Text = "smstest.frx":0006
Top = 2160
Width = 6525
End
Begin VB.TextBox com_in
Height = 495
Left = 2160
TabIndex = 4
Text = "AT"
Top = 1440
Width = 6495
End
Begin VB.TextBox smsc
Height = 375
Left = 2160
TabIndex = 1
Text = "+8613800512500"
Top = 4800
Width = 1575
End
Begin VB.Line Line3
X1 = 480
X2 = 10560
Y1 = 5880
Y2 = 5880
End
Begin VB.Line Line2
X1 = 480
X2 = 10560
Y1 = 4080
Y2 = 4080
End
Begin VB.Line Line1
X1 = 360
X2 = 10560
Y1 = 1080
Y2 = 1080
End
Begin VB.Label Label7
Caption = "短信内容"
Height = 255
Left = 3960
TabIndex = 18
Top = 4320
Width = 1815
End
Begin VB.Label Label6
Caption = "对方号码"
Height = 375
Left = 360
TabIndex = 15
Top = 5280
Width = 1455
End
Begin VB.Label Label5
Caption = "速率"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2880
TabIndex = 9
Top = 240
Width = 735
End
Begin VB.Label Label4
Caption = "串口号"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 600
TabIndex = 8
Top = 240
Width = 735
End
Begin VB.Label Label3
Caption = "结果"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 480
TabIndex = 3
Top = 2160
Width = 1335
End
Begin VB.Label Label2
Caption = "at命令"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 480
TabIndex = 2
Top = 1440
Width = 1575
End
Begin VB.Label Label1
Caption = "短信中心"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 360
TabIndex = 0
Top = 4680
Width = 1335
End
End
Attribute VB_Name = "main1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'用Visual Basic设计手机短信收发程序
Dim connect_status As Integer
Public at_receive_temp As String
Public at_receive As String
Public at_receive_ready As Integer
'Unicode码编码函数
' 因为手机短消息的发送是以PDU串的形式发送出去的,中文字符以Unicode码来表示,所以在发送中文短消息之前必须首先将中文字符转换为Unicode码,下面的函数将实现这个功能。这个函数主要应用到VB自带的一个格式转换函数:ChrW()将中文转换为Unicode码。
Public Function ascg(smsg As String) As String
Dim si, sb As Integer
Dim stmp As Integer
Dim stemp As String
sb = Len(smsg)
ascg = ""
For si = 1 To sb
stmp = AscW(Mid(smsg, si, 1))
If Abs(stmp) < 127 Then
stemp = "00" & Hex(stmp)
Else
stemp = Hex(stmp)
End If
ascg = ascg & stemp
Next si
ascg = Trim(ascg)
End Function
'unicode 解码函数
'相比于手机短信的发送而言,手机短信的接收主要的工作正好与之相反。手机短信的发送需要将待发送的短信内容转换为Unicode码,而短信的接收则需要将接收到的Unicode码转换成中文字符。下面的函数将实现解码功能。同手机短信发送的编码函数一样,这里也应用了一个VB内置的函数AscW()函数来将Unicode码转换为中文:
Public Function chg(rmsg As String) As String
Dim tep As String
Dim Temp As String
Dim i As Integer
Dim b As Integer
tep = rmsg
i = Len(tep)
b = i / 4
If i <> b * 4 Then
b = b - 1
tep = Left(tep, b * 4)
End If
chg = ""
For i = 1 To b
Temp = "&H" & Mid(tep, 4 * i - 3, 4)
chg = chg & ChrW(CInt(Val(Temp)))
Next i
End Function
'短信中心手机号码的PDU串转换函数
'同上,为了发送以PDU模式发送短消息,必须将手机号码和对方手机号码也转换为PDU格式,下面的函数就是为了实现这种转换:
'手机号码有两种表示方法:11位和13位(带国家码86),一般手机发送时都是以13位形式表示的,所以以上的函数还有一个功能是自动将11位格式手机号码转换为13位形式,然后再转换为PDU串。
Public Function telc(num As String) As String
Dim tl As Integer
Dim ltem, rtem, ttem As String
Dim ti As Integer
If Left(num, 1) = "+" Then
num = Mid(num, 2, 13)
End If
ttem = ""
tl = Len(num)
If tl <> 11 And tl <> 13 Then
MsgBox "wrong number." & tl
Exit Function
End If
If tl = 11 Then
tl = tl + 2
num = "86" & num
End If
For ti = 1 To tl Step 2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -