微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机控制GPS/GSM原理(虚拟串口)

单片机控制GPS/GSM原理(虚拟串口)

时间:11-17 来源:互联网 点击:

Private Function Sendsms(num As String, msg As String) As Boolean 短信发送
Dim PDU, psmsc, pnum, pmsg, buf As String
Dim Leng As String
Dim Length As Integer
Length = Len(msg)
Length = 2 * Length
Leng = Hex(Length)
If Length < 16 Then Leng = "0" & Leng
psmsc = Trim(telc("8613800758500"))
pnum = Trim(telc(num))
pmsg = Trim(StrConv(msg, vbUnicode))
PDU = prex & psmsc & midx & pnum & sufx & Leng & pmsg
Sleep (1)
Call Portopen_Test
Mobcomm.Output = "AT+CMGF=0" + vbCr
Mobcomm.Output = "AT+CMGS=" & Str(15 + Length) + vbCr
Sleep (500)
If Mobcomm.InBufferCount > 0 Then
Mobcomm.InputLen = 0
buf = Mobcomm.Input
If InStr(buf, ">") Then
Mobcomm.Output = PDU & Chr$(26)
buf = ""
End If
End If
If Mobcomm.InBufferCount > 0 Then
Mobcomm.InputLen = 0
buf = Mobcomm.Input
If InStr(buf, "OK") Then

buf = ""
Sendsms = True
End If
End If
End Function
Private Sub readsms(rnum As String) 接收信息
Mobcomm.Output = "AT+CMGF=1" + vbCr
Mobcomm.Output = "AT+CMGR=" & rnum + vbCr
End Sub
Private Sub Command1_Click()
myActiveX.Active = False
myActiveX.ComPort = Combo1(1).Text
myActiveX.baudrate = Int(Val(Combo2(1).Text))
MsgBox "设置端口号为:" & Combo1(1).Text & ",波特率为:" & Combo2(1).Text & tl
myActiveX.Active = True
End Sub
Private Sub Command2_Click()
msg.Text = ""
End Sub
Private Sub Command3_Click()
DebugText "================= SIM卡信息 ====================="
DebugText " SIM卡IMSI: " + myActiveX.IMSI
DebugText " 短信中心: " + myActiveX.SCA
DebugText " 所属网络: " + myActiveX.Provider
DebugText " 短信数目: " + myActiveX.SMSMemUsed
DebugText " 短信容量: " + myActiveX.SMSMemTotal
= 0
Mobcomm.InputLen = 0
Sleep (100)
Mobcomm.Output = "AT+CMGF=1" + vbCr
Sleep (400)

Mobcomm.InBufferCount = 0
Mobcomm.Output = "AT+CMGD=" + index.Text + Chr(13) + Chr(10)
Sleep (400)
mobcomm.OutBufferCount = 0
mobcomm.Output = "13138529082" + vbCr
If Mobcomm.InBufferCount > 0 Then
Instring = Mobcomm.Input
If InStr(Instring, "OK") Then
MsgBox "成功删除第" + index.Text + "条信息!", vbOKOnly, "提示"
Else
MsgBox "信息删除不成功!"
End If
End If
rmsg.Text = Mid(Instring.Text, 1, InStr(Instring, Chr(13) + Chr(10)))
rmsg.Text = Unicode2AscII(stringdeal(Instring))
rmsg.Text = Mid(Instring, 11)
Sleep (100)
mobcomm.OutBufferCount = 0
mobcomm.Output = Text1.Text + Chr(26)
Sleep (100)
End If
If InStr(Instring, "OK") Then
End If
If Mobcomm.PortOpen = True Then
Mobcomm.PortOpen = False
End If
myActiveX.Active = True
If Mobcomm.PortOpen = False Then
Mobcomm.PortOpen = True
End If
Mobcomm.Output = "AT+CMGD=" & index.Text + vbCr
Sleep (300)
If Mobcomm.InBufferCount > 0 Then
Mobcomm.InputLen = 0
temp$ = Mobcomm.Input
Mobcomm.InBufferCount = 0
If InStr(buf, "OK") Then
MsgBox "该信息已删除!"
Else
MsgBox "信息删除不成功!"
End If
End If
End Sub
Private Sub Form_Load()
Combo1(1).ListIndex = 0 选择端口和波特率
Combo2(1).ListIndex = 4
myActiveX.Active = True 打开模块
End SubPrivate Sub msgsend_Click()
Dim MsgAdr As String
Dim TelNo As String
Dim Smsg As String
Dim PDU As String
Dim Leng As String
Dim Length As Integer
Dim AllLength As Integer
Length = 2 * Len(msg.Text)
Leng = Hex(Length)
If Len(Leng) = 1 Then
Leng = "0" & Leng
End If
AllLength = 15 + Length
MsgAdr = Trim(telc("8613800758500")) 肇庆动感地带短信信中心地址
TelNo = Trim(telc(teln.Text)) 手机号码
Smsg = Trim(AscII2Unicode(msg.Text)) 短信息内容
PDU = midx & TelNo & sufx & Leng & Smsg
PDU = "0011000D91683167006059F100080108828265E55FEB4E50"
AllLength = 23
myActiveX.Active = False
If Mobcomm.PortOpen = False Then
Mobcomm.PortOpen = True
SMSend AllLength, PDU 调用短信息发送程序
End If
If Mobcomm.PortOpen = True Then
Mobcomm.PortOpen = False
myActiveX.Active = True
End If
myActiveX.SendTextSMS Trim(teln.Text), Trim(msg.Text)
If Sendsms(Trim(teln.Text), Trim(msg.Text)) = True Then
If Sendsms = True Then
MsgBox "信息发送成功!"
End If
End Sub
Private Function stringdeal(ByVal st As String)
stringdeal = Mid(st, InStr(st, Chr(10)) + 16)
End Function
Private Sub rm_Click() 阅读信息
Dim N As Integer
Dim Instring As String
= 0
Mobcomm.InputLen = 0
Sleep (100)
Instring = ""
Mobcomm.Output = "AT+CMGF=0" + vbCr
Sleep (400)
If Mobcomm.InBufferCount > 0 Then
Instring = Mobcomm.Input
Mobcomm.InBufferCount = 0
Mobcomm.OutBufferCount = 0
If InStr(Instring, "OK") Then
Mobcomm.Output = "AT+CMGR=" + index.Text + Chr(13) + Chr(10)
End If
Instring = ""
End IfSleep (500)If Mobcomm.InBufferCount > 0 Then
Instring = Mobcomm.Input

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top