toupe
asked on
How can I write SMS coming from GSM modem in the text file using the com port ?
Hi experts,
I'm a VB programer, I have some problem to write the data coming from GSM modem "Fastrack" in the text file using the com port.
This my code source
Private Sub Form_Load()
'Paramètres du 1er modem
MSComm1.RTSEnable = True
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = "AT+CNMI=0,2,0,0,0" & vbCr
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Open "C:\Receiv1_sms.txt" For Append As #1
Print #1, MSComm1.Input
Close #1
End Select
End Sub
With this I write the sms in the text file but when I read it I have the format problem....
+CMT: "+2236799488",,"04/09/16,0 9:40:47-00 "
Hello
+CMT: "+2236722223",,"04/09/16
Hello
+CMT: "+2236715596",,"04/09/16
9-00"
F1
+CMT: "+2236761466",,"
,09:55:44-00"
Hello
+CMT: "+2236784793",,"04/09/16,1 0:00:58-00 "
Hello
How can I do to receive all SMS in the same format in the text file like this
+CMT: "+2236784793",,"04/09/16,1 0:00:58-00 "
Hello
+CMT: "+2236799488",,"04/09/16,0 9:40:47-00 "
Hello
Thanks for your help
I'm a VB programer, I have some problem to write the data coming from GSM modem "Fastrack" in the text file using the com port.
This my code source
Private Sub Form_Load()
'Paramètres du 1er modem
MSComm1.RTSEnable = True
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = "AT+CNMI=0,2,0,0,0" & vbCr
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
Open "C:\Receiv1_sms.txt" For Append As #1
Print #1, MSComm1.Input
Close #1
End Select
End Sub
With this I write the sms in the text file but when I read it I have the format problem....
+CMT: "+2236799488",,"04/09/16,0
Hello
+CMT: "+2236722223",,"04/09/16
Hello
+CMT: "+2236715596",,"04/09/16
9-00"
F1
+CMT: "+2236761466",,"
,09:55:44-00"
Hello
+CMT: "+2236784793",,"04/09/16,1
Hello
How can I do to receive all SMS in the same format in the text file like this
+CMT: "+2236784793",,"04/09/16,1
Hello
+CMT: "+2236799488",,"04/09/16,0
Hello
Thanks for your help
ASKER
Thanks for your help Imran, my program works properly now with Sleep Sub.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
AT+CMGL=4 (PDU Mode)
AT+CMGL="ALL" (Text Mode)
These commands will output all the SMS received serially.....and you manually have to delete each SMS you receive with AT+CMGD command......
as far as your current code is concerned you might insert a delay after comEvReceive event is fired.......
Case comEvReceive
Open "C:\Receiv1_sms.txt" For Append As #1
sleep 500
Print #1, MSComm1.Input
Close #1
and declare sleep as
private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'If declaring in form code
Hope this helps.....
Imran Arshad