Send short messages via mobile phone on PC

Source: Internet
Author: User
A long time ago, I noticed some mobile phone Short Message sending software. I thought it was amazing, but I never wanted to develop my own mobile phone Short Message software. my graduation thesis is coming soon. My graduation project is the development of the data center security system, mainly the monitoring of the data center environmental coefficient and the implementation of the alarm function, this includes short message alerts and dial-up alerts.

There are currently three methods to implement short messages on mobile phones:

1. the mobile gateway sends short messages. This method does not require additional hardware, but you need to apply for a gateway from the Telecom Department. This method is suitable for development by some large network communication companies. Currently, Huawei, ZTE and other companies are doing this, and there are corresponding Development Kits for developers to use.

2. sending Short Chinese messages to mobile phones via GSM modem on the computer. This is a method suitable for development in small projects. The required hardware includes a mobile phone that provides a GSM modem, and corresponding data lines or infrared adapters. this method is easy to code and can be implemented only when you are familiar with at commands and serial port programming. It also has low hardware requirements and can automatically send and receive short messages.

3. through the text message sending functions provided by some websites, such as Sina and Netease all provide services in this regard. This method is the simplest and least resource required among the three methods, however, the dependency on the website is too strong, and the dependency on the network is also unavoidable. It is not applicable to project development.

The second method can be used to send and receive short messages in three modes: block mode, text mode, and PDU. The driver support provided by block machine manufacturers has not yet been found by any manufacturers to support this text message sending mode, while the PDU mode is complicated to develop, in addition, you need to write special functions to convert the text to the PDU format, which is cumbersome. relatively speaking, the development and convenience of the text mode is also simple, which is a good choice. However, the development of the text mode can only send ASCII code, and the Unicode code in Chinese cannot be sent.
 
Sending text messages in text mode is actually very simple. As long as you have a basic understanding of the AT command, you can write a short message sending program. However, there are few articles that have been introducing this method, many people think that this method is too simple to mention. however, for simple applications, this method is also a good choice.
 
First, add the MSComm control to the project. Generally, the MSComm control may not be listed in the part bar. You can right-click the part bar and select "part ", alternatively, select components in the project menu, and then select Microsoft comm Control 6.0. after the MSComm control is added, you can set some basic parameters. if you are using a Nokia mobile phone, you must also install data Suite (you can download one from the Nokia Development Forum), and choose 3 from MSComm's comport. If you are using another mobile phone, to use the infrared interface, you must install the infrared driver. select the corresponding port. the following code sets some basic parameters:
Mscomm1.settings = "9600, N, 9600" '000000', no parity check, 8-bit data, one stop bit
Mscomm1.inputlen = 0' read the entire buffer
Mscomm1.portopen = true' Open Port
The code for sending a short message is as follows:
Mscomm1.output = "at + cmgf = 1" + vbcr 'sets the sending mode. Note: vbcr must be added.
Mscomm1.output = "at + csca =" & CHR $ (34) & "8613010341500" & CHR $ (34) & ", 129" + vbcr "8613010341500 is a short message center, numbers vary across regions. You must set a local short message number.
Mscomm1.output = "at + cmgs =" & CHR $ (34) & "13057575064" & CHR $ (34) & ", 129" + vbcr '13057575064 is the recipient's mobile phone number
Mscomm1.output = "test" & CHR $ (26) 'chr $ (26) is CTR + z
The above is a simple short message implementation. You can develop more sophisticated programs and functions based on the AT Instruction Set combined with the VB serial control, such as receiving short messages and dialing.

 

After writing <send short message via mobile phone on PC>, I plan to write a short Chinese message. However, my graduation thesis is too tight and 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): 0891683110301405f011000d91683159717456f4000800165982679c6536523077ed4fe1

002c8bf756de590d002e. 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 * 2) + vbcr
Mscomm1.output = "0891683110301405f011000d91683159717456f4000800165982679c6536523077ed

4fe1002c8bf756de590d002e "& 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 * 2) + in vbcr, 15 is the number of digits 11000d91683159717456f400080016. length * 2 is the number of digits of 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. after writing this article, I just took a sigh of relief. I 'd like to explain it to you. Thank you for your attention. if you need source code, you can send me an email: tmjpd@21cn.com.

.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.