View previous topic :: View next topic |
Author |
Message |
ILLIAS28
Joined: 11 Jan 2011 Posts: 42
|
READING AN SMS |
Posted: Thu Jan 16, 2020 5:52 am |
|
|
Could you please help me,
i saw in a discussion an instruction for reading sms that is : fgets(GSM)
my question is: what is GSM? is that a library or what? _________________ i am newbe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Jan 16, 2020 6:08 am |
|
|
Quick comment...
GSM = Global System for Mobile...
The code says 'get a string of data from a serial device previously defined as GSM'.
Somewhere before that line a '#USE RS232(...stream=GSM...)' was coded to configure 2 I/O pins to connect to a GSM module.
Check the CCS manual for proper syntax and options !
Be aware that as it's code for 'string' operation , the GSM module MUST return a /0 in order for the PIC to proceed to the next line of code ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Jan 16, 2020 6:49 am |
|
|
No.
Gets, automatically appends a '\0', when a line feed is seen. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Thu Jan 16, 2020 7:21 am |
|
|
hmm, I always thought it looked for the 'end of string' delimiter not 'make a string' by adding the /0.
That gets me wondering what happens when there is no linefeed in the incoming data ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Jan 16, 2020 8:03 am |
|
|
Gets, terminates when a line feed or null is seen.
It is really best thought of as a 'get line' function.
From K&R:
Quote: |
It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
|
|
|
|
ILLIAS28
Joined: 11 Jan 2011 Posts: 42
|
READING AN SMS |
Posted: Thu Jan 16, 2020 8:25 am |
|
|
Thank you very much for your help guys;
but what is the difference between this command and the AT command for reading SMS: printf("AT+CMGR=%d\r",indx); _________________ i am newbe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Thu Jan 16, 2020 8:31 am |
|
|
Whoa.
Very different things completely.
Gets, is a C command to 'read' the reply from the modem.
The AT command is a string sent _to_ the modem, to get a reply.
You send an AT command (using printf), and then the reply from the
modem can be read with gets. |
|
|
|