View previous topic :: View next topic |
Author |
Message |
r520m Guest
|
How receive <CR><LF>OK<CR><LF> on RS |
Posted: Mon May 02, 2005 3:03 pm |
|
|
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
|
|
Posted: Tue May 03, 2005 12:23 pm |
|
|
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
|
|
Posted: Tue May 03, 2005 2:00 pm |
|
|
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
|
|
Posted: Tue May 03, 2005 2:28 pm |
|
|
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
|
|
Posted: Tue May 03, 2005 2:42 pm |
|
|
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. |
|
|
|