26.3.5. Syntax of the +CMGL AT Command in SMS PDU Mode

The syntax of the +CMGL AT command in SMS PDU mode is: (Optional parameter is enclosed in square brackets.)


+CMGL[=message_status]


The message_status parameter takes an integer that specifies the message status to be used to find messages to return. The SMS specification has defined five message status values, which are shown below. You can perform a test operation to find the actual values supported by your GSM/GPRS modem or mobile phone. See the "Finding the Message Status Values Supported by the +CMGL AT Command in SMS PDU Mode" section for the details. Usually all five status values are supported.

For example, if 1 is specified to the message_status parameter, the +CMGL AT command will list all messages that have the "received read" status from the message storage area.

Note that message_status is an optional parameter. If it is omitted, the +CMGL AT command will use the default value 0.


26.3.6. Format of the Information Response of the +CMGL AT Command in SMS PDU Mode

If the GSM/GPRS modem or mobile phone reads the SMS message from message storage successfully, it will return an information response to the computer / PC. In SMS PDU mode, the information response of the +CMGL AT command has the following format: (Optional fields are enclosed in square brackets.)


+CMGL: index,message_status,[address_text],TPDU_length<CR><LF>SMSC_number_and_TPDU[<CR><LF>+CMGL: ...]


Before we discuss each of the fields that appear in the +CMGL information response, let's see an example that gives you some idea of how an actual +CMGL information response should look like:


+CMGL: 1,0,,62
07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E


The index Field

The first field of the information response of the +CMGL AT command, index, is an integer that specifies the location of the SMS message in the message storage area.


The message_status Field

The second field of the information response of the +CMGL AT command, message_status, is an integer that indicates the status of the SMS message. It can be one of the following four values:


The address_text Field

The third field of the information response of the +CMGL AT command, address_text, is a string that contains the text associated to address in the phonebook, where address is the phone number encoded in the TPDU of the SMSC_number_and_TPDU field. For example, if the phone number encoded in the TPDU is "91234567" and the text "Alice" is associated to the phone number "91234567" in the phonebook, address_text will be "Alice". The AT command +CSCS (command name in text: Select TE Character Set) can be used to specify the character set for displaying address_text.

Note that address_text is an optional field. Some GSM/GPRS modems and mobile phones leave this field empty. (Examples: Philips 598 supports this field, while most Nokia products, including my Nokia 6021, and Sony Ericsson T68i does not.)


The TPDU_length Field

The fourth field of the information response of the +CMGL AT command, TPDU_length, is an integer that indicates the length (in octets. 1 octet = 8 bits) of the TPDU contained in the SMSC_number_and_TPDU field. In the earlier example command line, the value of the SMSC_number_and_TPDU field is:


07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E


It can be divided into two parts. The following part is the TPDU:


040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E


The TPDU is coded in hexadecimal format. Each character represents 4 bits, i.e. 1/2 octet. The TPDU has 124 characters and so there are totally 62 octets. That's why the value of the TPDU_length field is 62.


The SMSC_number_and_TPDU Field

The fifth field of the information response of the +CMGL AT command, SMSC_number_and_TPDU, specifies the SMSC number and the TPDU (Transfer Protocol Data Unit) in hexadecimal format.

If the SMS message to be read is an incoming SMS message, the value of the SMSC_number_and_TPDU field will be something like this:


07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E


The TPDU embedded in the above hexadecimal sequence is of the type SMS-DELIVER. Here is some of the information encoded in the hexadecimal sequence:

For the details about how the hexadecimal sequence of an incoming SMS message is coded, please refer to the section titled "Some Explanation about the Decoding of the SMSC_number_and_TPDU Field Value of the +CMGR AT Command" of this SMS tutorial.

If the SMS message to be read is an outgoing SMS message, the value of the SMSC_number_and_TPDU field will be something like this:


07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E


The TPDU embedded in the above hexadecimal sequence is of the type SMS-SUBMIT. Its format is different from that of an SMS-DELIVER TPDU. Below shows some of the information encoded in the hexadecimal sequence above:

For the details about how the hexadecimal sequence of an outgoing SMS message is coded, please refer to the section titled "Some Explanation about the Coding of the SMSC_number_and_TPDU Parameter Value of the +CMGS AT Command" of this SMS tutorial.


Multiple SMS Messages in the Information Response

If there are multiple SMS messages to be returned, the information response of the +CMGL AT command will contain more than one "+CMGL: ...". Two characters, <CR><LF>, are used to delimit two "+CMGL: ...". Here is an example for illustration. Suppose the command line "AT+CMGL=4" (this command line tells the GSM/GPRS modem or mobile phone to retrieve all messages from message storage) is executed and three SMS messages are listed. If all characters are shown, the command line and the response returned will be displayed like this:


AT+CMGL=4<CR>
<CR><LF>+CMGL: ...<CR><LF>+CMGL: ...<CR><LF>+CMGL: ...<CR><LF>
<CR><LF>OK<CR><LF>


In a terminal program such as HyperTerminal of Microsoft Windows, a carriage return character causes the cursor to be moved to the beginning of the current line, and a linefeed character causes the cursor to be moved to the same position on the next line. Hence, the above result will be displayed like this in a terminal program such as HyperTerminal of Microsoft Windows:


AT+CMGL=4
+CMGL: ...
+CMGL: ...
+CMGL: ...

OK


Previous Page Page 63 of 65 Next Page

Contents at a Glance (Click Here for Full Table of Contents)

Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page