After writing <send short message via mobile phone on PC> (http://www.csdn.net/Develop/article/17/17690.shtm), I plan to write the Chinese text message to send, but the graduation thesis time is too tight, has been delayed, several netizens have sent emails to me over the past few days, and many netizens have followed this topic. Moreover, the csdn e-mail journal has included my article, I am very pleased and feel that I should finish my unfinished work as soon as possible. Otherwise, I am too sorry for everyone.
Sending and receiving text messages in text mode is simple and easy to implement, but the biggest drawback is that you cannot send and receive Chinese text messages. however, the PDU mode can completely solve this problem. The PDU mode supports both Chinese text messages and English text messages, which is perfect. you can send and receive text messages in PDU mode in three encoding formats: 7-bit, 8-bit, and ucs2. 7-bit encoding is used to send Common ASCII characters, 8-bit encoding is usually used to send data messages, and ucs2 encoding is used to send Unicode characters. To send Chinese text messages, select ucs2, that is, the Chinese Unicode code.
First, we will introduce two functions in VB: chrw () and ASCW (). you must be familiar with the CHR () and ASC () functions and may be unfamiliar with chrw () and ASCW. the chrw function returns a string that contains Unicode. If Unicode is not supported on the platform, the function is the same as the CHR function. The ASCW function returns the Unicode character code. If Unicode is not supported on the platform, same as ASC functions. Here is an example of each of the two functions:
? ASCW ("short ")
30701
? Chrw (26482)
Bytes
We can see that these two functions can convert Chinese and Unicode codes, which is very convenient for encoding and decoding. After we get the Chinese Unicode code, we can compile the PDU string.
Let's take a look at the composition of the PDU string. We can see this PDU string (used when I debug the program): quit. We break it down:
08 length of SMSC address information (91683110301405f0 8-bit bytes in total)
91 SMSC address format (ton/NPI)
683110301405f0 SMSC address (8613010341500 Nanjing SMS service center number)
11 basic parameters (TP-MTI/VFP) (sent, received as 84)
00 Mr Message Reference
Length of the 0d target SIM card number (683159717456f4 is counted by Arabic numerals)
91 same as above
683159717456f4 SIM card number of the recipient's mobile phone (8613057575064)
00 common GSM type, point-to-point mode
08 ucs2 Encoding
00 Validity Period
16 user information length (5982679c6536523077ed4fe1002c8bf756de590d002e length 22 bytes)
5982679c6536523077ed4fe1002c8bf756de590d002e ("if you receive a text message, please reply." Unicode code)
After we understand the composition of the PDU code, we can start encoding. The red part above is what we want to implement.
First, let's take a look at the SMSC address: 683110301405f0 and 8613010341500f (the last bit of SMSC is supplemented with F to form a 14-bit complement). We can find that you only need to check the parity. similarly, 683159717456f4 and 8613057575064 are the same.
For the length of user information, we can use the Len function in VB, for example, "hello". We use Len ("hello") to get 2, then 2*2 = 4 is the user information length 04 (Here we want to convert it to hexadecimal notation, And it is two digits ). for Unicode codes, we can use the ASCW () function to extract the Unicode codes from Chinese characters one by one.
The specific implementation code for sending text messages is as follows (for more information, see the previous article ):
If mscomm1.portopen = false then mscomm1.portopen = true
Length = Len ("if you receive a text message, please reply.") * 2
Mscomm1.output = "at + cmgf = 0" + vbcr "send text messages in PDU Mode
Mscomm1.output = "at + cmgs =" & STR (15 + length) + vbcr
Mscomm1.output = "success" & CHR $ (26)
Start = Timer
Pause = 1
While timer <start + pause
Doevents
Wend
Reco = mscomm1.input
If instr (reco, "OK") Then sendsms = true
If instr (reco, "error") Then sendsms = false
Mscomm1.output = "at + cmgs =" & STR (15 + length) + in vbcr, 15 is the number of digits 11000d91683159717456f400080016. length is the number of digits of the limit.
At this point, the sending of text messages is basically complete, and the receiving of text messages is simpler, mainly decoding, that is, applying the chrw () function. writing this article is just a sigh of relief. Let's explain it to everyone. Thank you for your attention.