Author Topic: How to receive sms and delete  (Read 25918 times)

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
How to receive sms and delete
« on: August 11, 2012, 11:37:46 AM »
Hi, my intention is to check incoming sms with interval of 2 minutes with FMD88-10 and receiving sms through wavecom gsm modem.

After 2 minutes  interval execute AT commands = "AT+CMGL=ALL"
stored in DM then delete "AT+CMGD=1,3"

Please do advise how to start,  

Print #1 "AT+CMGD=1,2"+CHR$(13)

Thanks

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to receive sms and delete
« Reply #1 on: August 12, 2012, 06:52:37 AM »
You can assign the string that you wish to print to a variable.

E.g.

IF ..........   ' some test conditions
    A$ = "AT+CMGL=ALL"
ELSE
    A$ = "AT+CMGD=1,3"
ENDIF

PRINT #1 A$ + CHR$(13)
.....
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #2 on: August 12, 2012, 08:58:39 AM »
Hi,

I am going to check my incoming message after interval 2 minutes.
1) After 2 minutes i am going to send command "AT+CPMS?"
    which will help me to indicate the number of SMS received.
The reply will be after send this command is:-
+CPMS:"SM",2,40.... where 2 indicates no of SMS received. I did assign string variable A$ to command receive and take out the no of SMS receive and assign to integer variable A.

A$ = Print#1 "AT+CPMS?"
i = 1
While 1
      B$ = MID$( A$,i,1)
     i=i+1
     If(B$ = ",")  goto @10 : ENDIF
ENDWHILE

@10 A = MID$(A$,i,1)

Please do advice me up to this stage first.
How i can debug this to make sure what i get in A, B$ and A$. Do i need to do convert data type in TBASIC.

Then i can catch up the remaining. Thanks
« Last Edit: August 12, 2012, 09:45:35 AM by Tito »

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #3 on: August 13, 2012, 10:03:59 AM »
Hi,

SETBAUD 1,9
Print#1 "AT+CPMS?"
A$ =INCOMM(1)       ' where A$ = +CPMS:"SM",2,40.... (from GSM)
B$ = ","

While 1
   C$ = MID$(A$,i,1)
   delay 50
   if STRCMP(B$,C$) = 0 then
      j = i
      While 1
           i = i +1
           D$ = MID$(A$,i,1)
           if STRCMP( B$,D$)=0 exit : endif
      endwhile
   exit
   endif
   i =i +1
endwhile

E$ = MID$(A$,j+1,i-j+1)

I get 2 indicates no of sms received. Is there i can simplify this.

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to receive sms and delete
« Reply #4 on: August 13, 2012, 11:57:20 AM »
The GSM modem should return an ASCII string that is CR terminated?

If so then you can use the INPUT$(1) command to read the entire string. INCOMM(1) is for reading individual byte until there is no more data. A$ = INCOMM(1) will not compile due to different variable type.

You can use ASC(A$,n) command to check the ASCII of each character inside the string:

E.g. You can simulate the following program fragment inside a custom function. Once executed it will show you the position of the first and second comma inside A$. You can see the A$ from the view variable screen as well:


A$ = "+CPMS:"+CHR$(34)+"SM"+CHR$(34)+",2,40"

I = 1
FOR I = 1 to 70    
   IF ASC(A$,I) = 44    ' ASCII value for comma character
     EXIT
   ENDIF
   I = I+1
NEXT

SETLCD 1,1, "1st comma at "+STR$(I)


I = I+1

FOR I = I to 70    
   IF ASC(A$,I) = 44    ' ASCII value for comma character
     EXIT
   ENDIF
   I = I+1
NEXT

SETLCD 2,1, "2nd comma at "+STR$(I)


Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #5 on: August 13, 2012, 09:29:41 PM »
Hi, I get the information but

Example in hyperterminal

AT+CPMS?
example i get this
+CPMS: "SM",2,40,"SM",2,40,"SM",2,40
'empty row then
OK

then when i try out
SETBAUD 1,9
Print #1 "AT+CPMS?"
delay 50
A$=INPUT$(1)
delay 50
 i=1
for i = 1 to 70
      delay 50
      if ASC(A$,i)=44
         exit
     endif
next
j=i
j=j+1
for j = j to 70
     delay 50
     if ASC(A$,j)=44
         exit
     endif
next
B$ = mid$(A$,i+1,j-i-1)

Print #1 "AT+CMGS="+CHR$(34)+"+6XXXXXXX"+CHR$(34)
Print #1 B$ +CHR$(26)

I do receive "blank" SMS.After continuously on / off input 1 (i do use on/off switch to input 1 to trigger the function) switch give me all kind of incorrect data expect once "2".
I just want to make sure that i receive correct data before processing.

Even i did try to get Len(A$), reply sms subsequently shows :
1) 1
2) 22
3) 3
4) 2
5) 1
6) 3 etc...

just for info in C# i do receive in this format:-
"AT+CPMS?\r\r\n+CPMS:\"SM\",2,40,\"SM\",2,40\r\n\r\nOK\r\n"
 ???
« Last Edit: August 14, 2012, 06:56:29 AM by Tito »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to receive sms and delete
« Reply #6 on: August 14, 2012, 10:39:10 AM »
Note that every time you run the INPUT$(1) command, it will only return something when there is a complete string that is terminated by a single CR. Otherwise it will return an empty string.

INPUT$(1) will only return one string at a time. It will not include the CR character itself inside the return string. So the situation is quite different from that of C# where a return string includes all the \r characters.  For INPUT$(1) each time it is called it will return only one string.

There is also no need to put a delay 50 inside the for loop where you locate the position of the "," character. The complete string is already in A$ so you can run the program as fast as possible.

You may want to use the simulator to help you test your program. Anytime you need the program to stop so that you can examine the data you can put "PAUSE" statement in the custom function and the program will stop there and you can continue by clicking on the "PAUSE" button on the simulator. This way it will be much easier to debug your program.
 



Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #7 on: August 14, 2012, 12:37:44 PM »
Hi thanks you for given points on debug method. I am new for d board and TBASIC . On C# I did completed for SMS on server app.

I have to monitor online to determine incoming string. ?Comm 1 has to hook up with PC for on line monitoring and Comm 2 connect to GSM modem by using RS 485 converter. I don't have RS 485 with me currently. Have to order online and might take couple of days. Will post the outcome later

Thanks.

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #8 on: August 17, 2012, 09:31:30 AM »
 ;D hi, I am back. i did manage get RS232 to RS485 converter. Before step further to previous question, i couldn't send sms out. My setting are:-
1) jumper in Auto-turnaround
2) supply 12VDC
3) RS485(+) goes to RS485(+) in FMD 88-10
4) RS485(-) goes to RS485(-) in FMD 88-10
5) Cable I do use my fabricated cable
6) GSM modem connected with RS232 to RS485 converter.

code:-

SetBaud 2,9

Print #2 "AT+CMFG=1"
Print #2 "AT+CMGS="+CHR$(34)+"+6XXXXXXX"+ CHR$(34)
Print #2 "thank God Hello" + CHR$(26)
SETLCD 1,1,"Thank God"
« Last Edit: August 17, 2012, 09:43:49 AM by Tito »

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #9 on: August 17, 2012, 01:13:43 PM »
Hi, Currently i did swap my ports and its works, where RS 485 to PC and COMM 1 to GSM modem. But i would like to know the configuration for as mention above.

While trying out using "PAUSE" command and read out the INPUT$(1) for few times, i did get various results as follows:-
\OA
\OA0K
\OA0K
\0AAT+CPMS?
PMS?
\0A+CPMS: "SM",7,40,"SM",7,40,"SM,7,40
203

From bottom, number 2 is correct results. May i know why i am getting this. Do i have to flush the com buffer every time before send command?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to receive sms and delete
« Reply #10 on: August 18, 2012, 09:40:22 AM »
Yes any incoming characters from the serial port are stored into a 256 bytes circular buffer. If the previous communication resulted in unread characters then they will show up the next time you call the INPUT$(n) command.

You can flush the input buffer quite easily:

FOR I = 1 to 256
   IF INCOMM(1) < 0 EXIT: ENDIF
NEXT

Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #11 on: August 19, 2012, 09:26:31 AM »
Hi, Its seems something missing, doesn't work. Please do advice.

FOR I = 1 to 256
 
  IF INCOMM(1) < 0 EXIT: ENDIF
NEXT

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to receive sms and delete
« Reply #12 on: August 20, 2012, 11:23:47 AM »
What do you mean by "doesn't work"? Is it compilation error? If so then your i-TRiLOGI version may not support the EXIT function. In that case just replace it with a GOTO to get out of the loop.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Tito

  • Newbie
  • Posts: 48
  • Think
    • View Profile
Re:How to receive sms and delete
« Reply #13 on: August 21, 2012, 11:38:06 AM »
Hi, after long search on reading sms, i do manage to read receive sms by using incomm instead of input$.

I do notice in VB.net and C# while send "AT" the return is
"AT\r\r\nOK\r\n" it will be equivalent with "AT"+CHR$(13)+CHR$(13)+CHR$(10)+"OK"+CHR$(13)+CHR$(10).

by using incomm with :-
 
SETBAUD 1,9
Print #1 "AT"

for i = 1 to 100
    DM = incomm(1)
    A$ = A$ + CHR$(DM)
    if DM<0 then
           exit
    endif
next

By doing this i could obtain the entire string. Please do correct if i am wrong.

Thanks
« Last Edit: August 21, 2012, 11:40:38 AM by Tito »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:How to receive sms and delete
« Reply #14 on: August 21, 2012, 10:48:45 PM »
Yes you could assemble all the binary data into a single string using your method. Note that INCOMM(1) return -1 as soon as the buffer is empty. So you may want to wait for a while after sending the command to give the modem time to send back the entire response before you start reading them.
Email: support@triplc.com
Tel: 1-877-TRI-PLCS