Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - Inviare SMS com modem gsm
Forum - Visual Basic 6 - Inviare SMS com modem gsm

Avatar
giusy_m86 (Normal User)
Pro


Messaggi: 143
Iscritto: 09/07/2008

Segnala al moderatore
Postato alle 9:41
Martedė, 13/10/2009
Salve, ho scritto un piccolo programma che mi permette di inviare SMS attraverso i comandi "AT", il problema č che oltre ad inviare il testo del messaggio invia anche tutti i comandi. Posto il codice
Codice sorgente - presumibilmente VB.NET

  1. Private Sub cmdInvio_Click()
  2. Dim numero As String
  3. Dim testo As String
  4.  
  5. numero = txtnumero.Text
  6. testo = txtmsg.Text
  7.  
  8. Call invia(numero, testo)
  9.  
  10. End Sub
  11.  
  12. Private Function invia(numero As String, testo As String)
  13.  
  14. MSComm1.Output = "AT+CMGF=1" & Chr$(13)
  15.  
  16. MSComm1.Output = "AT+CMGS=" & Chr$(34) & numero & Chr$(34) & Chr$(13)
  17.  
  18. MSComm1.Output = testo
  19.  
  20. MSComm1.Output = Chr$(26)
  21.  
  22. End Function


Dove č che sbaglio?8-|

PM Quote
Avatar
theprogrammer (Normal User)
Guru^2


Messaggi: 2509
Iscritto: 28/01/2009

Segnala al moderatore
Postato alle 10:02
Martedė, 13/10/2009
Forse dovrebbe essere

Testo quotato



MSComm1.Output = Chr$(26) & Chr$(13)



Ultima modifica effettuata da theprogrammer il 13/10/2009 alle 10:02
PM Quote
Avatar
giusy_m86 (Normal User)
Pro


Messaggi: 143
Iscritto: 09/07/2008

Segnala al moderatore
Postato alle 10:12
Martedė, 13/10/2009
Continuano ad arrivare tutti i comandi...Il messaggio che ricevo č il seguente:
AT
AT+CMGF=1
AT+CMGS="333333333"
Prova

io dovrei ricevere solo "Prova"

PM Quote
Avatar
theprogrammer (Normal User)
Guru^2


Messaggi: 2509
Iscritto: 28/01/2009

Segnala al moderatore
Postato alle 10:21
Martedė, 13/10/2009
Strano ... Prova a mostrare TUTTO il codice ... magari c'e' qualcosa nel resto ...

PM Quote
Avatar
giusy_m86 (Normal User)
Pro


Messaggi: 143
Iscritto: 09/07/2008

Segnala al moderatore
Postato alle 10:36
Martedė, 13/10/2009
Ecco l'intero codice:
Codice sorgente - presumibilmente VB.NET

  1. Private Sub cmdStart_Click()
  2. 'Apro la comunicazione seriale CON IL MODEM GSM
  3.         On Error Resume Next 'Abilito l'intercettazione di errori
  4.     If MSComm1.PortOpen = False Then
  5.     MSComm1.PortOpen = True
  6.     End If
  7.    
  8.  MSComm1.Output = "AT" + vbCrLf  
  9.  
  10. End Sub
  11.  
  12. Private Sub cmdInvio_Click()
  13. Dim numero As String
  14. Dim testo As String
  15.  
  16. numero = txtnumero.Text
  17. testo = txtmsg.Text
  18.  
  19. Call invia(numero, testo)
  20.  
  21. End Sub
  22.  
  23. Private Function invia(numero As String, testo As String)
  24.  
  25. MSComm1.Output = "AT+CMGF=1" & Chr$(13)
  26.  
  27. MSComm1.Output = "AT+CMGS=" & Chr$(34) & numero & Chr$(34) & Chr$(13)
  28.  
  29. MSComm1.Output = testo
  30.  
  31. MSComm1.Output = Chr$(26) & Chr$(13)
  32.  
  33. End Function
  34.  
  35. Private Sub MSComm1_OnComm()
  36. Dim Rx$
  37. Dim ix As Long
  38. Dim i As Integer
  39. Dim Ricevuto As Variant
  40. Dim num As Variant
  41. Dim y As Long
  42.    
  43.     Rx$ = MSComm1.Input 'Leggo il contenuto del buffer di ricezione §(e svuoto .Input)
  44.  
  45.  
  46.     If Len(Rx$) Then
  47.                
  48.                 'leggo il contenuto in esadecimale
  49.                 For ix = 1 To Len(Rx$)
  50.                     Ricevuto = Ricevuto & Right$("0" & Hex$(Asc(Mid$(Rx$, ix, 1))), 2)
  51.                 Next ix
  52.            
  53.                 'leggo il contenuto in ascii
  54.                 For y = 1 To Len(Ricevuto)
  55.                     num = Mid(Ricevuto, y, 2)
  56.                     Value = Value & Chr(Val("&h" & num))
  57.                     y = y + 1
  58.                 Next y
  59.                
  60.                 hex2ascii = Value
  61.                
  62.                
  63.     End If
  64.        
  65.      Text1.Text = Value


Ultima modifica effettuata da giusy_m86 il 13/10/2009 alle 10:39
PM Quote
Avatar
theprogrammer (Normal User)
Guru^2


Messaggi: 2509
Iscritto: 28/01/2009

Segnala al moderatore
Postato alle 10:46
Martedė, 13/10/2009
Perche' usi la OnComm per ricevere?

Non sono sicuro, dato che non posso provare con un modem adesso, ma penso che, dopo ogni comando tu debba attendere l' OK dal modem, prima di inviare il prossimo.

Quindi, orientativamente dovrebbe essere

MSComm1.Output = "AT+CMGF=1" & vbCrLf

( meglio vbCrLf che il solo Chr$(13) )

e poi attendi che venga ricevuto l'OK ...

Dopo invii il resto e attendi l' OK e cosi' via ...


PM Quote