SMS send
2 Chinese conversion into unicode code function
Because the transmission of the 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 the Chinese characters to the Unicode code before sending Chinese short messages, and the following functions will implement this feature. 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 STRING DIM TEP AS STRING DIM TEMP AS STRING DIM I AS I AS INTEGER DIM B AS INTEGER TEP = RMSG 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 end function
2 SMS center mobile phone number PDU string conversion function
Also, in order to send a short message in the PDU mode, the mobile phone number and the other party's mobile number must also be converted to the PDU format. The following functions are to achieve this conversion:
Public Function Telc (Num As String) AS STRING DIM TL AS INTEGER DIM LTEM, RTEM, TTEM AS STRING DIM TI AS INTEGER TTEM = "" TL = LEN (NUM) IF TL <> 11 and TL <> 13 TEN MSGBOX "WRONG Number. "& TL EXIT FUNCTION END IF IF TL = 11 THEN TL = TL 2 NUM =" 86 "& Num End if for 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 & LTEM NEXT TI TELC = TTEM END 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
SMS transmission is mainly implemented by means of VB's MSCOMM control. About MSCOMM controls, the previous technical introduction section has a detailed introduction. 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 & PMSG Sleep (1) Mobcomm.output = "AT CMGF = 0" VBCR MOBCOMM.output = "AT CMGS = "& STR (15 length) VBCR Mobcomm.output = PDU & ChR $ (26) Sleep (1) sendsms = true end function Because the mobile phone can only handle one thing, this function is only responsible for sending SMS, About the SMS send success or not, 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
Compared to the sending of mobile phone SMS, the main job of the receiving of SMS is just 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 STRING DIM SI, SB AS INTEGER DIM STMP AS INTEGER DIM STEGER DIM STMP AS INTEGER DIM STEMP AS STRING SB = 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 asecg = ascg & strump next si ascg = trim (ascg) End Function2 mobile phone SMS reception function
Compared with the sending function of SMS, the SMS receives quite simple, 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" VBCR Mobcomm.output = "AT CMGR =" & RNUM VBCR End Sub