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 CCS Technical Support

How receive <CR><LF>OK<CR><LF> on RS

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







How receive <CR><LF>OK<CR><LF> on RS
PostPosted: Mon May 02, 2005 3:03 pm     Reply with quote

Hi

I want receive from CELL Phone, the answer:

<CR><LF>OK<CR><LF>

But I dont know how to do it?

Getc(); o gets();


And, how echoing input char from hyperterminal and store this characters on internal buffer


Thank you so much..

Bye
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue May 03, 2005 12:23 pm     Reply with quote

You can read the six bytes into a buffer and verify their content. What have you tried that didn't work? I might read bytes until I get a "O", then check that the next byte is a "K", then consider it done. What do you want to do if you get an OK verses if you don't? You may need some sort of timeout so you don't wait forever for a faulty phone.
_________________
The search for better is endless. Instead simply find very good and get the job done.
r520m
Guest







PostPosted: Tue May 03, 2005 2:00 pm     Reply with quote

Ok..

what happen if getc() detect a 13??, it will stop reading from rs232??..

and the same question for gets()....that is my dude...how to solve it...

my cell phone is a ericsson r520m, i want sent "AT" and wait for "OK"...
Ttelmah
Guest







PostPosted: Tue May 03, 2005 2:28 pm     Reply with quote

Getc, just returns a character. It does not care what the character is, or 'stop' on any particular character. Gets conversely, gets characters, till a character that it deems to be an 'end of string' is seen. Look at the example program 'get_string', in the file 'input.c'. Notice that it is using 'getc', to get each character in turn, and testing for this being '13', to decide that the string has finished. This is exactly like the code for gets, except that it adds backspace handling. You can code an identical 'get and check', to look for any pattern you want, including multiple carriage returns. However remember to consider the need for a timeout, if the code is to be reliable...

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 03, 2005 2:42 pm     Reply with quote

get_string() also has a parameter for maximum string length.

This is much better than gets(), which will accept any number of
characters and continue putting them into RAM, way beyond the
limits of your input buffer and thus trashing all your other variables.
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