外国朋友寄给我的Ascii_7to8和Decode7Bit函数,简洁明了值得学习!

外国朋友寄给我的Ascii_7to8和Decode7Bit函数,简洁明了值得学习!

Shared Function Decode7Bit(ByVal str7BitCode As String) As String
Dim Inv7BitCode As String = InvertHexString(str7BitCode)
Dim Binary As String
Dim Result As String
Dim i As Integer
For i = 0 To Inv7BitCode.Length - 1 Step 2
Binary += ByteToBinary(CByte(Val("&H" & Inv7BitCode.Substring(i, 2))))
Next
Dim Temp As Integer
For i = 1 To Binary.Length 7
Temp = BinaryToInt(Binary.Substring(Binary.Length - i * 7, 7))
If Temp = 0 Then Temp = 64
Result = Result + ASCII_7to8(Temp) 'OLD >>>> 'Result = Result + ChrW(Temp)
Next
Return (Result)
End Function

#Region " ASCII_7to8 "
Shared ASCII_7to8() As String = { _
"@", _
"£", _
"$", _
"¥", _
"è", _
"é", _
"ù", _
"ì", _
"ò", _
"Ç", _
vbLf, _
"Ø", _
"ø", _
vbCr, _
"Å", _
"å", _
"Δ", _
"_", _
"Φ", _
"Γ", _
"Λ", _
"Ω", _
"Π", _
"Ψ", _
"Σ", _
"Θ", _
"Ξ", _
"1", _
"Æ", _
"æ", _
"ß", _
"É", _
" ", _
"!", _
Chr(34), _
"#", _
"¤", _
"%", _
"&", _
"'", _
"(", _
")", _
"*", _
"+", _
",", _
"-", _
".", _
"/", _
"0", _
"1", _
"2", _
"3", _
"4", _
"5", _
"6", _
"7", _
"8", _
"9", _
":", _
";", _
"<", _
"=", _
">", _
"?", _
"¡", _
"A", _
"B", _
"C", _
"D", _
"E", _
"F", _
"G", _
"H", _
"I", _
"J", _
"K", _
"L", _
"M", _
"N", _
"O", _
"P", _
"Q", _
"R", _
"S", _
"T", _
"U", _
"V", _
"W", _
"X", _
"Y", _
"Z", _
"Ä", _
"Ö", _
"Ñ", _
"Ü", _
"§", _
"¿", _
"a", _
"b", _
"c", _
"d", _
"e", _
"f", _
"g", _
"h", _
"i", _
"j", _
"k", _
"l", _
"m", _
"n", _
"o", _
"p", _
"q", _
"r", _
"s", _
"t", _
"u", _
"v", _
"w", _
"x", _
"y", _
"z", _
"ä", _
"ö", _
"ñ", _
"ü", _
"à" _
}
#End Region

AT指令:AT+CPMS介绍

这是我在SIEMENS AT COMMAND SET里面摘录的一段:

AT+CPMS Preferred SMS message storage

Revision according to GSM 07.05 Version 4.7.0

Test command

AT+CPMS=?

Response

+CPMS: (list of supported s),( list of supported s) ,(list
+of

supported s)

Parameter

Memory from which messages are read and deleted

SM SIM message storage

ME Mobile Equipment message storage

MT combination of “ME” and “SM” storages

Messages will be written and sent to this memory storage:

SM SIM message storage

ME Mobile Equipment message storage

MT combination of “ME” and “SM” storages

Memory in which received messages are preferred to be stored, if

routing to TE is not set (see AT+CNMI command with parameter

=2)

SM SIM message storage

ME Mobile Equipment message storage

MT combination of “ME” and “SM” storages

Read command

AT+CPMS?

Response

+CPMS:

,,,,,,,,<total3

Parameter

Memory from which messages are read and deleted

Number of messages currently in

Total number of messages that can be stored in

Write command

AT+CPMS= [,[,]]

Parameter

See Test command

See Test command

See Test command

+CPMS: ,,,,,

OK/ERROR/+CMS ERROR

Notes 1) The Mobil Equipment storage “ME” has capacity for 25 short messages

2) The storage “MT” is a combination of “ME” and “SM” storage. If “MT” is

chosen indices < 26 refer to ME” storage while indices 26 or higher are

associated with the “SM” storage

3) Incoming short messages with message class 2 (see GSM 03.38) will be

stored in the “SM” storage only. Therefore, the AT^SMGO:2 indication (see

AT^SMGO command) can occur without a preceding AT^SMGO:1 indication.

一些概念:

MEM1:读取和删除短信所在的内存空间。
MEM2:写入短信和发送短信所在的内存空间。
MEM3:接收到的短信的储存位置。

具体用法:

. 语句:
AT+CPMS=?
作用:

测试命令。用于得到手机所支持的储存位置的列表。在我的SIEMENS M55手机上返回:
AT+CPMS=?
+CPMS: (“MT”,”SM”,”ME”),(“MT”,”SM”,”ME”),(“MT”,”SM”,”ME”)

表示手机支持MT(手机终端),SM(SIM卡),ME(手机设备)

. 语句:
AT+CPMS=”MT”,”ME”,”SIM”
设置MEM1为MT,MEM2为ME,MEM3为SIM

. 语句:
AT+CPMS?

作用:
得到当前的设置。
例如通过第二条语句的设置以后返回:

AT+CPMS?
+CPMS: “MT”,7,150,”ME”,7,100,”SM”,0,50

表示MT里面有7条短信,总共可以储存150条。ME里面有7条,共可以储存150条。SIM卡上可以储存50条。

Encode Charactors to 7BitCode or UCS2 PDU string (vb.net)

Encode Charactors to 7BitCode or UCS2 PDU string (vb.net)

Public Function Encode7Bit(ByVal Content As String) As String
'Prepare
Dim CharArray As Char() = Content.ToCharArray
Dim c As Char
Dim t As String
For Each c In CharArray
t = CharTo7Bits(c) + t
Next
'Add "0"
Dim i As Integer
If (t.Length Mod 8) <> 0 Then
For i = 1 To 8 - (t.Length Mod 8)
t = "0" + t
Next
End If
'Split into 8bits
Dim result As String
For i = t.Length - 8 To 0 Step -8
result = result + BitsToHex(Mid(t, i + 1, 8))
Next
Return result
End Function

Private Function BitsToHex(ByVal Bits As String) As String
'Convert 8Bits to Hex String
Dim i, v As Integer
For i = 0 To Bits.Length - 1
v = v + Val(Mid(Bits, i + 1, 1)) * 2 ^ (7 - i)
Next
Dim result As String
result = Format(v, "X")
If result.Length = 1 Then
result = "0" + result
End If
Return result
End Function

Private Function CharTo7Bits(ByVal c As Char) As String
Dim Result As String
Dim i As Integer
For i = 0 To 6
If (Asc(c) And 2 ^ i) > 0 Then
Result = "1" + Result
Else
Result = "0" + Result
End If
Next
Return Result
End Function

Private Function EncodeUCS2(ByVal Content As String) As String
Dim i, j, v As Integer
Dim Result, t As String
For i = 1 To Content.Length Step 4
v = AscW(Mid(Content, i, 4))
t = Format(v, "X")
For j = 1 To 4 - t.Length
t = "0" & t
Next
Result += t
Next
Return Result
End Function