Solved

How can I write SMS coming from GSM modem in the text file using the com port ?

Posted on 2004-09-17
3
330 Views
Last Modified: 2013-12-26
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,09: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,10: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,10:00:58-00"
Hello
+CMT: "+2236799488",,"04/09/16,09:40:47-00"
Hello

Thanks for your help
0
Comment
Question by:toupe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:imarshad
ID: 12091075
One other option is to use AT+CMGL command.....Depending upon the type of application you are developing AT+CMGL might be a better option..... Currently you have set your modem to Output the SMS as it arrives.......But what if at that time your Program is not running ? In that case you will not be able to read that SMS.......

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
0
 

Author Comment

by:toupe
ID: 12178046
Thanks for your help Imran, my program works properly now with Sleep Sub.
0
 
LVL 13

Accepted Solution

by:
imarshad earned 50 total points
ID: 12236674
If your problem is solved then you should close the question by accepting my suggestion......

Imran
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question