Result Codes of AT Commands (Tutorial 16)

Result codes are messages sent from the GSM/GPRS modem or mobile phone to provide you information about the execution of an AT command and the occurrence of an event. Two types of result codes are useful to you when dealing with AT commands for SMS messaging:

  • Final result codes

  • Unsolicited result codes


Final Result Codes of AT Commands


A final result code marks the end of an AT command response. It is an indication that the GSM/GPRS modem or mobile phone has finished the execution of a command line. Two frequently used final result codes are OK and ERROR. Only one final result code will be returned for each command line. Thus, you will not see both OK and ERROR in the response of a command line.


1. The OK Final Result Code

The OK final result code indicates that a command line has been executed successfully by the GSM/GPRS modem or mobile phone. It always starts and ends with a carriage return character and a linefeed character.

Here is an example for illustration. Let's say you send the command line "AT+CMGL;+CGMI" to your GSM/GPRS modem. The AT command "+CMGL" is used to list SMS messages stored in the message storage area and the AT command "+CGMI" is used to get the manufacturer name of the GSM/GPRS modem. If everything works properly without any errors, the command line, together with the response returned, should be something similar to this:


AT+CMGL;+CGMI
+CMGL: 1,"REC UNREAD","+85291234567",,"06/11/11,00:30:29+32"
Welcome to our SMS tutorial.
Nokia
OK


As mentioned earlier, when a terminal program such as HyperTerminal of Microsoft Windows sees a carriage return character, it moves the cursor to the beginning of the current line. When it sees a linefeed character, it moves the cursor to the same position on the next line. Hence, the command line you entered, together with the response returned, will be displayed like this in a terminal program such as HyperTerminal of Microsoft Windows:


AT+CMGL;+CGMI
+CMGL: 1,"REC UNREAD","+85291234567",,"06/11/11,00:30:29+32"
Welcome to our SMS tutorial.

Nokia

OK


2. The ERROR Final Result Code

The ERROR final result code indicates that an error occurs when the GSM/GPRS modem or mobile phone tries to execute a command line. After the occurrence of an error, the GSM/GPRS modem or mobile phone will not process the remaining AT commands in the command-line string.

Below are some common causes of error:

  • The syntax of the command line is incorrect.

  • The value specified to a certain parameter is invalid.

  • The name of the AT command is spelt incorrectly.

  • The GSM/GPRS modem or mobile phone does not support one or more of the AT commands, command parameters or parameter values in the command-line string.

Like the OK final result code, the ERROR final result code always starts and ends with a carriage return character and a linefeed character.

Here is an example for illustration. Suppose you want to instruct your GSM/GPRS modem to list SMS messages from the message storage area and get the manufacturer name of the GSM/GPRS modem. You intend to type the command line "AT+CMGL;+CGMI" but make a careless mistake by typing "+CMFL" instead of "+CMGL". The GSM/GPRS modem will return the ERROR final result code, as shown below:


AT+CMFL;+CGMI
ERROR


As an error occurs when the GSM/GPRS modem processes "+CMFL", the GSM/GPRS modem stops the execution of the command line and so the second AT command "+CGMI" is not processed.

If you type the second AT command "+CGMI" incorrectly instead of the first AT command "+CMGL", the GSM/GPRS modem will output the result of the execution of the AT command "+CMGL" before outputting the ERROR final result code, like this:


AT+CMGL;+CGMU
+CMGL: 1,"REC UNREAD","+85291234567",,"06/11/11,00:30:29+32"
Welcome to our SMS tutorial.
ERROR


As mentioned earlier, when a terminal program such as HyperTerminal of Microsoft Windows sees a carriage return character, it moves the cursor to the beginning of the current line. When it sees a linefeed character, it moves the cursor to the same position on the next line. Hence, the command line you entered, together with the response returned, will be displayed like this in a terminal program such as HyperTerminal of Microsoft Windows:


AT+CMGL;+CGMU
+CMGL: 1,"REC UNREAD","+85291234567",,"06/11/11,00:30:29+32"
Welcome to our SMS tutorial.

ERROR

from developershome .com