At present, the application of GSM is very extensive, but in actual project applications, I found that many people will ignore a very important thing: a SIM card is only 2-100,000 times, exceeding this time, SIM The card will be damaged, in fact, this can be solved by the AT parameter setting. It is possible to enter the AT CSMS = 1 at CNMMI = 2, 2, 0, 0, 1 when the device is started, and then return AT CNMA immediately. There are many information about GSM on the Internet. I will send a software that I have made here. If you want the whole software, you can leave your mailbox!
Option Explicitpublic Indata As String 'Serial Dip String DIM P AS String, D AS String, T AS String, TXT AS STRING, E AS Integer
Private sub check1_click () if check1.value the closeoncomm check1.enabled = false Dim Txstring as string mscomm1.output = "at csms = 1" & chr (10) & chr (13) delay 2 mscomm1.output = "AT CNMI = 2,2,0,0,1 "& chr (10) & chr (13) delay 2 Check1.enabled = true openatabasemm end if end sub
Private sub combo1_click ()
IF mscomm1.portopen = 1 ThenMscomm1.Portopen = 0mscomm1.settings = combo1.text ", n, 8, 1" 'if Combo1.text = "1200" Then mscomm1.settings = "1200 ,,"
Mscomm1.Portopen = 1ELSEMSCOMM1.SETTINGS = Combo1.Text ", N, 8, 1" 'if Combo1.text = "1200" Then Mscomm1.Settings = "1200,"
END IF
End SubPrivate Sub combo1_dropdown () Combo1.ClearCombo1.AddItem "1200", 0Combo1.AddItem "2400", 1Combo1.AddItem "4800", 2Combo1.AddItem "9600", 3Combo1.AddItem "19200", 4Combo1.AddItem "38400", 5COMBO1.Additem "57600", 6Combo1.Additem "115200", 7nd Sub
Private Sub Command10_Click () CloseonCommdim Txstring AS Stringdim i as in
Mscomm1.output = "at cmgf = 0" & vbcrlfdelay 1mscomm1.output = "at cmgl = 3" & chr (13) & chr (10) delay 1txString = mscomm1.inputdim atext () as string'Text8.selText = Txstringatext = Split (TxString, Chr (13) & chr (10)) 'text8.text = atext (4) if len (atext (4)) <15 Ten TEXT4.SELTEXT = "No message, please check!" & vbcrlfselse for i = 2 TO (Ubound (atExt) - 1) / 2 - 1 text8.text = Atext (i * 2) supersms1.conpdu text8.text, p, d, t, txt, 1, e'text4. Text = SMSALLTEXT 'Get parsing data text4.seltext = "phone number:" & p & vbrlf _ & "time:" & t & vbcrlf _ & "content:" & TXT & VBCRLF _ & " "error Code:" & E & vbCrLf'Text4.SelText = TxStringNext iEnd IfOpenOnCommEnd SubPrivate Sub Command11_Click () CloseOnCommDim TxString As StringMSComm1.Output = "at cmgf = 0" & vbCrLfDelay 1MSComm1.Output = "at cmgl = 4" & CHR (13) & chr (10) delay 1txString = mscomm1.inputtext4.seltext = TxStringOpenonCommend Sub
Private sub fascist2_click ()
On Local Error Resume NextCloseonCommdim Sinput As Stringdim A as string'dim Sif Text1.text <> "" THEN MSCOMM1.OTPUT = "At CSCA =" "& Text1.Text &" "" & Chr (13) & chr (10) Delay 2 SINPUT = MSCOMM1.INPUT IF INSTR (SINPUT, "OK") = 0 THEN MSGBOX ("SMS Center setting failed, please reset!") Openoncomm exit subsideness f i'Delay 1mscomm1.output = " AT CMGF = 0 "& chr (13) & chr (10) Delay 2'IF MScomm1.input = CHR (13) & chr (13) & chr (10) & chr (79) & chr (75) & chr (13) & chr (10) THENA = MSCOMM1.INPUT IF INSTR (A, "OK") <> 0 THEN MSCOMM1.Output = "at cmgs =" & text6.text & chr (13) & chr (10) 'Delay 1' IF mscomm1.input = chr (13) & chr (13) & chr (10) & chr (62) & chr (32) THEN DELAY 3 mscomm1.output = text5.text & chr (26) Delay 4 DIM SINPUTT SINPUTT = MSCOMM1.INPUT IF INSTR (SINPUTTT, "OK") <> 0 THEN MSGBOX ("Send Success!") Else Msgbox ("Send Failure, please Re-send!") End if Else Msgbox ("SMS Mode Configuration Error, please reconfigure! ") End ifopenonComm
End Sub
Private Sub Command3_Click () unload mend Sub
Private submmand4_click () 'DIM TXINPUT (1 to 65534) AS BytecloseonCommdim TxString AS Stringdim i AS Integer
Mscomm1.output = "at cmgf = 0" & vbcrlfdelay 1mscomm1.output = "at cmgl = 0" & chr (13) & chr (10) delay 1txstring = mscomm1.inputdim atExt () as string'Text8.selText = Txstringatext = Split (TxString, Chr (13) & chr (10)) 'text8.text = atext (4) if len (Atext (4)) <15 TEXT4.SELTEXT = "Nothing is not read new information, please wait! "& vbcrfelse for i = 2 to (Ubound (atExt) - 1) / 2 - 1 text8.text = ATEXT (i * 2) supersms1.conpdu text8.text, p, d, t, txt, 1, e'text4 .Text = SMSALLTEXT 'Get parsing data text4.seltext = "Phone number:" & p & vbcrlf _ & "time:" & t & vbcrlf _ & "content:" & txt & vbcrlf _ & "Error Code:" & E & VBCRLF'TEXT4.SELTEXT = TXStringNext Iend Ifopenoncommend SUB
Private sub fascist6_click () closeoncommmscomm1.output = "at cmgf = 0" & chr (13) & chr (10) delay 1mscomm1.output = "at cmgl = 4" & chr (13) & chr (10)
Delay 2Dim smsalltext as stringsmsalltext = mscomm1.inputdim optext () AS STRINGDIM I as integeratext = split (smsalltext, chr (13) & chr (10)) DIM J AS Integer
If LEN (4)) <15 TEXT4.SELTEXT = "memory is empty, no SMS" & vbcrfelsefor J = 2 to (Ubound (atExt) - 1) / 2 - 1 text8.text = ATEXT (j * 2 ) SuperSMs1.conpdu text8.text, p, d, t, txt, 1, e
'Text4.text = SMSALLTEXT' Get parsing data text4.seltext = "Phone number:" & p & vbrlf _ & "time:" & t & vbrlf _ & "content:" & txt & vbCrLf _ & "error Code:" & E & vbCrLfNext jEnd IfOpenOnCommEnd SubSub Conv () SuperSMS1.SMS_Phone = Text2.TextSuperSMS1.SMS_CSCA = Text1.TextSuperSMS1.SMS_STXT = Text3.TextText5.Text = SuperSMS1.SMS_SMain'Text8.Text = SuperSMS1. Ansitext (Text7.text) text6.text = supersms1.sms_slenend subprivate submmand5_click () text4.text = "" End Sub
Private sub fascist7_click () CloseonComm
Mscomm1.output = "at cmgd =" & text7.text & vbcrlfdim deltext as stringdelay 3deltext = mscomm1.inputif inStr (delText, "OK") <> 0 TEEN TEXT4.SELTEXT = "Delete SMS" & Text7.Text & " Success "& vbcrlf Deltext =" "else text4.seltext =" delete SMS "& text7.text &" failed, please re-check "& vbcrlf DelText =" "End ifopenoncommend SUB
Private Sub Command8_Click () 'On Error ResMe NextCloseoncomm
If InStr (Command8.Caption, "Serial off") <> 0 Then MSComm1.PortOpen = False Command8.Caption = "open port" Command7.Enabled = False Command6.Enabled = False Command4.Enabled = False Command1.Enabled = False Command9 .Enabled = False Command10.Enabled = False Command2.Enabled = False Command11.Enabled = False Label5.Enabled = False Else MSComm1.PortOpen = 1 Command8.Caption = "Close COM" 'If flag2 = True Then MSComm1.Output = "at "& vbCrLfDim attextDelay 2attext = MSComm1.InputIf InStr (attext," OK ") <> 0 Then Command2.Enabled = True Command7.Enabled = True Command6.Enabled = True Command4.Enabled = True Command1.Enabled = True Command9.Enabled = True Command10.Enabled = True Command11.Enabled = True Label5.Enabled = True Text4.SelText = "already connected!" & vbCrLf Else Text4.SelText = "serial no response, please check!" & vbCrLf End IfEnd IfOpenOnCommEnd SubPrivate Sub Command9_Click () Closeoncommdim TxString As Stringdim i as integer
Mscomm1.output = "at cmgf = 0" & vbcrlfdelay 1mscomm1.output = "at cmgl = 1" & chr (13) & chr (10) delay 1txstring = mscomm1.inputdim atext () as string'Text8.selText = TXStringatext = Split (TxString, Chr (13) & chr (10)) 'text8.text = atext (4) if len (Atext (4)) <15 TEXT4.SELTEXT = "No read information, please check!" & vbcrlfselse for i = 2 TO (Ubound (atExt) - 1) / 2 - 1 text8.text = Atext (i * 2) supersms1.conpdu text8.text, p, d, t, txt, 1, e'text4. Text = SMSALLTEXT 'Get parsing data text4.seltext = "phone number:" & p & vbrlf _ & "time:" & t & vbcrlf _ & "content:" & TXT & VBCRLF _ & " "Error code:" & E & VBCRLF'TEXT4.SELTEXT = TXSTRINGNEXT IEND IEND IEND iFOpenoncommend Sub
Private Sub Text4_KeyPress (KeyAscii As Integer) On Error Resume NextMSComm1.Output = Chr (KeyAscii) End SubPrivate Sub Form_Load () On Error Resume Next MSComm1.PortOpen = False MSComm1.CommPort = 1 MSComm1.InputMode = comInputModeText MSComm1.Settings = "57600 , N, 8, 1 "MSCOMM1.INPUTLEN = 0 'Set the byte accommoded from the serial buffer to all mscomm1.portopen = true' opens the serial port command8.caption =" Close the serial port "'Command8.Value = 0 Commmand8.Value = 0 Combo1. Text = "57600" 'closeoncomm mscomm1.output = "at" & chr (13) & chr (10) delay 2' text4.text = strconv (mscomm1.input, vbunicode) Dim Aafirst As string aafirst = mscomm1.input if INSTR (Aafirst, "OK") = 0 THEN MSGBOX ("AT is not connected, please check if the Mode is connected!") 'Command8.caption = "Open the serial port" Command1.enabled = 0 command4.enabled = 0 comMand6.enabled = 0 Command7 .Enabled = 0 command10.enabled = 0 command2.enabled = 0 command11.1Abled = 0 command11.enabled = 0 label5.enabled = 0 else aafirst = "Text4.seltext =" device has been successful, please test! "& Vbcrlf'Command8.caption = "Close the serial port" mscomm1.output = "at cnmi = 1, 1, 0, 0, 1" & vbcrlf Command1.enabled = 1 command4.enabled = 1 command6.enabled = 1 command7.enabled = 1 Command2.Enabled = 1 Command9.Enabled = 1 Command10.Enabled = 1 Command11.Enabled = 1 Label5.Enabled = 1 End If Delay 1 'inData = "" OpenOnComm End SubPrivate Sub Command1_Click () On Local Error Resume Next
Closeoncomm Dim Stt1 'As Stringif Text1.Text <> "" "" THEN MSCOMM1.OUTPUT = "At CSCA =" "& Text1.Text &" "" "& chr (13) delay 3 stt1 = mscomm1.input if INSTR STT1, "OK") = 0 THEN MSGBOX ("SMS center number setting is unsuccessful, please check!") EXIT SUB END IFDELAY 1MSCOMM1.OUTPUT = "AT CMGF = 1" & chr (13) Delay 2'IF MSCOMM1 .NPUT = CHR (13) & chr (13) & chr (10) & chr (79) & chr (75) & chr (13) & chr (10) Thendim att 'as string att = mscomm1.input' Text4. Text = strconv (att, vbunicode) if INSTR (ATT, "OK") <> 0 THEN MSCOMM1.Output = "at cmgs =" "" & text2.text & "" "" & chr (13) delay 1 ' IF mscomm1.input = chr (13) & chr (13) & chr (10) & chr (62) & chr (32) THEN MSCOMM1.OUTPUT = TEXT3.TEXT & CHR (26) DELAY 4 DIM STT 'AS STRING STT = Mscomm1.input if INSTR (STT, " CMGS") <> 0 THEN MSGBOX ("Send Success!") Else Msgbox ("Send Failure, Check!") End ifelse msgbox ("SMS mode setting is unsuccessful, please Check! ") End IF
Openoncommend Subflic Sub Closeoncomm () mscomm1.rthreshold = 0mscomm1.inputMode = CominputModeText
End subpublic sub openoncomm () mscomm1.rthreshold = 1mscomm1.inputMode = CominputModeBinary
End Subpublic Sub Delay (Howlong As Date) 'Delay DIM Temptime As Date Temptime = Dateadd ("S", Howlong, Now) While Temptime> Now Doevents' Let Windows to deal with other things Wendend Sub
Private sub text1_change () Convend Subprivate Sub Text2_change ()
Convend Sub
Private sub text3_change () Convend Sub
Private Sub MSComm1_OnComm () 'serial port interrupt' On Error Resume NextStatic bFlag As BooleanStatic Xbyte As LongSelect Case MSComm1.CommEvent 'Select Event Case comEvReceive' character is received Dim InByte () As Byte 'defines a pointer in the binary data received InByte = Mscomm1.input 'Data Transfer to Pointer DIM TEMP AS Long Dim Temp1 AS Long Dim Temp2 As Long Counttrue = 1 for J = 0 To Ubound (Inbyte)' Cycling to Pointer Script "'IFHEX = 1 THEN '16 Bao display processing' indATA = Indata & HEX (InbyTe (j)) & "" Removes a byte to 16 binary display
'Else: if Inbyte (J) <128 and bflag = 0 Then IF Inbyte (j) = 13 THEN INDATA = Indata & VBCR' LF Else Indata = Indata & Chr (Inbyte (j)) 'ASCII Code Display Processing END IF ELSE 'At this time, the first half of the first half if bflag life' received the last half of the Chinese did not process TEMP1 = Xbyte temp2 = Inbyte (j) Temp = (Temp1 * 256 Temp2) - 65536 Indata = Indata & Chr (TEMP) BFLAG = 0 else if j <> ubound (inbyte) TEMP1 = Inbyte (j) Temp2 = Inbyte (j 1) TEMP = (Temp1 * 256 Temp2) - 65536 Indata = Indata & Chr (Temp) '& " * "& Temp &" *) "J = J 1 'This interrupt received the last byte is the first half of Chinese Else X Byte = Inbyte (j) 'Save this byte bflag = 1' Set the sign end if end if 'end if end if' counttrue = 1 Next JDOEVENTS