13/10/09 8:02
theprogrammer
Forse dovrebbe essere
MSComm1.Output = Chr$(26) & Chr$(13)
Ultima modifica effettuata da theprogrammer 13/10/09 8:02
aaa
13/10/09 8:12
giusy_m86
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"
aaa
13/10/09 8:21
theprogrammer
Strano ... Prova a mostrare TUTTO il codice ... magari c'e' qualcosa nel resto ...
aaa
13/10/09 8:36
giusy_m86
Ecco l'intero codice:
Private Sub cmdStart_Click()
'Apro la comunicazione seriale CON IL MODEM GSM
On Error Resume Next 'Abilito l'intercettazione di errori
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
MSComm1.Output = "AT" + vbCrLf
End Sub
Private Sub cmdInvio_Click()
Dim numero As String
Dim testo As String
numero = txtnumero.Text
testo = txtmsg.Text
Call invia(numero, testo)
End Sub
Private Function invia(numero As String, testo As String)
MSComm1.Output = "AT+CMGF=1" & Chr$(13)
MSComm1.Output = "AT+CMGS=" & Chr$(34) & numero & Chr$(34) & Chr$(13)
MSComm1.Output = testo
MSComm1.Output = Chr$(26) & Chr$(13)
End Function
Private Sub MSComm1_OnComm()
Dim Rx$
Dim ix As Long
Dim i As Integer
Dim Ricevuto As Variant
Dim num As Variant
Dim y As Long
Rx$ = MSComm1.Input 'Leggo il contenuto del buffer di ricezione §(e svuoto .Input)
If Len(Rx$) Then
'leggo il contenuto in esadecimale
For ix = 1 To Len(Rx$)
Ricevuto = Ricevuto & Right$("0" & Hex$(Asc(Mid$(Rx$, ix, 1))), 2)
Next ix
'leggo il contenuto in ascii
For y = 1 To Len(Ricevuto)
num = Mid(Ricevuto, y, 2)
Value = Value & Chr(Val("&h" & num))
y = y + 1
Next y
hex2ascii = Value
End If
Text1.Text = Value
Ultima modifica effettuata da giusy_m86 13/10/09 8:39
aaa
13/10/09 8:46
theprogrammer
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 ...
aaa