我已经将PDU码与Unicode码相互转换做完了,关键是如何进行通信,希望各位高人指点一二!!
Const prex = "0891"
Const midx = "11000D91"
Const sufx = "000800"
Private Sub Command1_Click()
Dim tep As String
Dim temp As String
Dim i As Integer
Dim b As Integer
tep = Text1.Text
i = Len(tep)
b = i / 4
If i = b * 4 Then
b = b - 1
tep = Left(tep, b * 4)
Else
tep = Left(tep, b * 4)
End If
chg = ""
For i = 1 To b
temp = "&H" & Mid(tep, (i - 1) * 4 + 1, 4)
chg = chg & ChrW(CInt(Val(temp)))
Next i
'Print chg
Text5.Text = chg
End Sub
Private Sub Command2_Click()
Dim tl As Integer
Dim num, ltem, rtem, ttem As String
Dim ti As Integer
ttem = ""
num = Text2.Text '利用text2输入手机号码
tl = Len(num) '取出num数据长度
If tl <> 11 And tl <> 13 Then '判断tl是不是不等于11和13
MsgBox "wrong number." & tl ' 若不等于则提示出错
End If
If tl = 11 Then '如果tl等于11是真
tl = tl + 2 '将tl加2
num = "86" & num
End If
For ti = 1 To tl Step 2 'ti由1到13单步进2
ltem = Mid(num, ti, 1) '取num的值,由ti位置每次取1
rtem = Mid(num, ti + 1, 1) '取num的值,由ti+1位置每次取1
If ti = tl Then rtem = "F" '如果ti=tl是真,rtem=F
ttem = ttem & rtem & ltem '根据手机短信格式需要将其每两位取反。
Next ti
telc = ttem
Text3.Text = telc '利用text3输出处理后的号码
End Sub
Private Sub Command3_Click()
Dim si, sb As Integer
Dim stmp As Integer
Dim stemp As String
smsg = Text4.Text '利用text4控件输入短信内容
sb = Len(smsg) '取短信的长度
ascg = "" '转换之前设PDU码为空
For si = 1 To sb
stmp = AscW(Mid(smsg, si, 1)) '从si位置取值,每次取一个值进行PDU码转换
If Abs(stmp) < 127 Then '如果stmp(一个十六进制值)小于127为真值,即为数字,执行下一条语句。
stemp = "00" & Hex(stmp)
Else
stemp = Hex(stmp)
End If
ascg = ascg & stemp
Next si
ascg = Trim(ascg) '去掉空格符
Text6.Text = ascg
End Sub
Public Sub readsms(rnum As String)
mobcomm.Output = "AT+CMGF=1" + vbCr
mobcomm.Output = "AT+CMGR=" & rnum + vbCr
End Sub
Private Sub Command4_Click()
End
End Sub