Send mobile phone text messages through the PC

xiaoxiao2021-03-06  14

Mobile SMS Send 2 Chinese Convert into Unicode Code Function Because the transmission of mobile phone short message is sent in the form of a PDU string, the Chinese characters are represented by the Unicode code, so they must first convert Chinese characters to Unicode Codes before sending Chinese short messages. The following functions will be implemented. This function is primarily applied to a format conversion function that comes with the VB: ChRW () converts Chinese into Unicode code.

Public Function CHG (RMSG As String) AS Stringdim Tep As Stringdim Temp As Stringdim I AS INTEGERDIM B AS INTEGERTEP = RMSGI = LEN (TEP) B = I / 4IF I = B * 4 THEN B = B - 1 TEP = Left (TEP , B * 4) ELSE TEP = Left (TEP, B * 4) end ifchg = "" for i = 1 to b Temp = "& H" & MID (TEP, (i - 1) * 4 1, 4) CHG = CHG & Chrw (CINT (Val (Temp)) Next Ind Function

2 SMS center mobile phone number PDU string conversion function is the same, in order to send a short message in PDU mode, the mobile phone number and the other party mobile number must also be converted to PDU format. The following functions are to achieve this conversion:

Public Function Telc (Num As String) AS STRINGDIM TL AS INTEGERDIM LTEM, RTEM, TTEM AS STRINGDIM TI AS INTEGERTTEM = "" TL = LEN (NUM) IF TL <> 11 and TL <> 13 THEN MSGBOX "WRONG NUMBER." & TL EXIT FUNCTIONEND IFIF TL = 11 THEN TL = TL 2 NUM = "86" & NUMEND IFOR TI = 1 to TL Step 2 Ltem = MID (Num, Ti, 1) RTEM = MID (Num, Ti 1, 1) IF Ti = TL THEN RTEM = "f" Ttem = Ttem & RTEM & Ltemnext Titelc = TTEMEND FUNCTION

The mobile phone number has two representations: 11 bits and 13 bits (with national code 86), the general mobile phone is expressed in 13-bit form, so the above functions have a function to automatically convert 11-bit format mobile phone number. For 13-bit form, then convert to a PDU string. 2 SMS send mobile phone SMS transmission mainly by means of VB's MSComm control, with a detailed introduction to the MSCOMM control, the previous technical introduction section. The sending of SMS is done by the AT CMGS instruction, and the PDU mode is transmitted, the function code is as follows:

Const prex = "0891" Const midx = "11000D91" Const sufx = "000800" Public Function Sendsms (csca As String, num As String, msg As String) As _Boolean Dim pdu, psmsc, pnum, pmsg As String Dim leng As String Dimleth as integer length = LEN (MSG) Length = 2 * length leng = hex (length) if length <16 Then Leng = "0" & ​​leng PSMSC = TRIM (Telc (CSCA)) PNUM = TRIM (Telc (NUM) ) PMSG = TRIM (ASG)) PDU = Prex & PSMSC & MIDX & PNUM & SUFX & Leng & Pmsgsleep (1) Mobcomm.output = "AT CMGF = 0" VBCR MOBCOMM.output = "AT CMGS = "& STR (15 length) vbcrMobcomm.output = PDU & ChR $ (26) Sleep (1) sendsms = trueEnd function Because the mobile phone can only handle one thing, this function is only responsible for sending SMS, about SMS send Successfully or not, and the part of the reading SMS is set together. It is determined whether the SMS transmission success is mainly determined by the AT CMGS command to perform the subsequent return code (see the AT instruction section of the foregoing). In order to prevent the phone from mistakenly because it is too busy, there is a certain way to make the phone have sufficient time to process the send and receive and delete the operation. The SLEEP () function is designed for this, and the program will be suspended after sending and deleting the operation, so that the phone is too busy. SMS reception 2 Unicode code decoding function is compared with the send SMS transmission, the main job of the mobile phone SMS receives the opposite. SMS transmission needs to convert the SMS content to be sent to a Unicode code, while the SMS receives the received Unicode code to a Chinese character. The following functions will implement decoding. Like the encoding function sent by SMS, this also applies a VB built-in function ascw () function to convert Unicode code to Chinese:

Public Function Ascg (SMSG As String) AS STRINGDIM SI, SB AS INTEGERDIM STMP AS INTEGERDIM STEMP AS STRINGSB = LEN (SMSG) ASCG = "" for Si = 1 to SB STMP = ASCW (MID (SMSG, Si, 1)) IF ABS (STMP) <127 THEN STEMP = "00" & HEX (STMP) Else STEMP = HEX (STMP) end if as ascg = ascg & strumpnext siascg = trim (ascg) end function

2 The SMS reception function is quite simple to receive the SMS, and only the following three lines of code are required. However, the technology it uses is never transmitted more than SMS, which mainly uses the Output property of the MSCOMM control and the AT CMGR command. Public Sub Readsms (Rnum As String) Mobcomm.output = "AT CMGF = 1" VBCRMOBCOMM.output = "AT CMGR =" & RNUM VBCREND SUB

'==================================================== ================================= ================== ============================================================================================================================================================================================================= ==============

I haven't read some mobile phone short messages, I feel that that is how magical, but I have never thought that I have developed a short message software for my mobile phone. I have graduated, I have to do graduation thesis, I choose graduation topics It is the development of the machine room safety system, mainly the monitoring of the environmental factor and the implementation of the alarm function, including mobile phone short message alarm and dial alarm.

Mobile phone short message implementation has three methods:

1. Send a short message via the mobile gateway, using this method does not require additional hardware, but it is necessary to apply for a gateway to the telecommunications department, which is suitable for some large network communication company development. At present, Huawei, ZTE and other companies do this. And there is also a corresponding development package for developers.

2. Send Chinese short messages to the phone on the computer, which is currently a way to compare small project development, and the required hardware includes a mobile phone, providing GSM MODEM, and the corresponding data cable or infrared adapter. This method is simple to encode, only need to be familiar with the AT instructions and serial programming, and the hardware demand is not high, and the short message can be automatically sent and received.

3. Implemented the SMS send function provided on some websites, such as Sina.com, NetEase provides this service, this method is the simplest, the simplest resources are minimal, but for the website The dependence is too strong, and the dependence on the network cannot be avoided, and it is not applicable to project development.

转载请注明原文地址:https://www.9cbs.com/read-49573.html

New Post(0)