CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

operator/operand error when comparing AT command

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
vjn86



Joined: 12 Oct 2009
Posts: 11

View user's profile Send private message

operator/operand error when comparing AT command
PostPosted: Mon Oct 12, 2009 10:43 am     Reply with quote

Hi there. I have tried to do a simple coding to read message from gsm modem and send another message as an acknowledgment to pre determined number. The error that I get in ccs compiler says that + and " " symbol cannot be use as it is a operand but the problem is the data transmitted to pic is contains both + and "" sign... [ +CMTI: "SM",1 ]

This is my coding. I hope someone could guide me on this.
Code:
#include <16f876a.h>
#device adc=10
#use delay(clock=20000000)
#fuses hs,nowdt,nolvp,noprotect
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7, parity=n)


byte mystat=0;
char mydata;
char +CMTI: "SM",1

void main()
{set_tris_c(0x80);

do
{
      if (kbhit())
      {  mydata=getch();
         mystat=1;
      }

      if (mystat==1)
      {
      // compare data
   
         if(mydata=='+CMTI: "SM",1')
         { printf("at+cmgf=1\r\n");
            delay_ms(500);     
            printf("at+csmp=17,168,0,0\r\n");
            delay_ms(500);
            printf("at+cmgs=\"+60136240915\"\r\n");
            delay_ms(3000);
            printf("hey ");
            putc(0x1A);
            delay_ms(10000);
         }

         else
         break;
      }
   }while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 10:57 am     Reply with quote

Read articles on "printf escape sequences":
http://www.daemon-systems.org/man/printf.1.html
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Oct 15, 2009 2:12 am     Reply with quote

You also need to read up on C char arrays and strings.

This :-
char +CMTI: "SM",1
is not possible.

This :-
if(mydata=='+CMTI: "SM",1')
Will also fail.

The single quote is used to represent a single char as in
char a = 'a';

The double quote is used to create a string BUT the string must be assigned to a char array and the array MUST have enough space for the hidden null terminating character '\0'
char str[17] = "This is a string";

To create a string that contains double quotes as in your case you use the escape char \ This tells the compiler to ignore the next char and just use it as is. A little vague there but what I mean is if you start a string with " then the next time the compiler sees a " it will think it is the end of the string. You need the compiler to ignore that " and in your case the next one so that they are part of the string. If you see what I mean ?

char myStr[] = "+CMTI: \"SM\",1";
This will create a var called myStr which will contain the string
+CMTI: "SM",1

Hope this helps.
vjn86



Joined: 12 Oct 2009
Posts: 11

View user's profile Send private message

PostPosted: Sat Dec 05, 2009 8:26 am     Reply with quote

thanks guys.. this really helps ...
Wayne : when i was exploring ur tips i found that :

char myStr[] = "+CMTI: \"SM\",1"; will produce (+CMTI: "SM",) only... but with an addition of /n in the coding : "+CMTI: \"SM\",1/n"
I was able to get output as expected. I wonder how /n changes the output... anyway thanks man...
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Dec 07, 2009 3:12 am     Reply with quote

"/n" places a newline char[10] charater at that point. The device you are talking to will use the nl newline char as the end of the command.

Some devices need "/r/n" char[13] char[10] (cr carridge return, nl newline) to indicate the end of the command.

I am not sure how you debuged the string to determine that it only contained (+CMTI: "SM",) but I expect that it was the way you did this that made it look like it didn't contain the rest!
Either that or there is a bug in CCS!
vjn86



Joined: 12 Oct 2009
Posts: 11

View user's profile Send private message

PostPosted: Thu Dec 10, 2009 12:53 pm     Reply with quote

Ayte.. thanks man...
vjn86



Joined: 12 Oct 2009
Posts: 11

View user's profile Send private message

PostPosted: Sun Mar 21, 2010 12:50 pm     Reply with quote

Wayne: I think there is an error with my pic circuit. Whenever I print a string using c6 and c7, it will omit the last two characters. But somehow I am still able to send send at command and get its response. However I am able to get the string without being trimmed if I defined other than c6 and c7 for rs232...hmm...weird...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group