Tuesday, June 14, 2011

AT Commands

By Jugal Panchal

What is an AT command?

AT commands allow giving instructions to both mobile devices and ordinary landline telephones. The commands are sent to the phone's modem, which can be a GSM modem or PC modem. Different phones support different sets of AT commands. This means that a specific phone might not support all AT commands listed at end of this article. Currently there is no authoritative list available of supported AT commands by all phones.

Overview

This article focuses on AT commands on Nokia's GSM and CDMA products only. Different manufacturers may have different sets of AT commands. Fortunately, many AT commands are the same. Mobile device manufacturers may also give attention to operators to allow or not to allow some commands on phones.

AT commands can be used for operations that are usually done from the keypad, for instance calling a number, sending, reading, or deleting an SMS, setting the SMSC number, looking for a GPRS access point, reading and deleting phonebook data, reading the battery status, reading the signal strength, and so on. When you want to make a PC-based application to interface a mobile phone using USB or Bluetooth, these commands are needed to communicate with mobile phones. Nokia provides an AT command set guide, where you can see the basic command syntax and the response of the command in various situations. See the Related Links section at the end of this article.

Using AT Commands with .Net

Before going for developing application we have to do some basic step with OS:

1. For AT commands to work, we have to connect our device to our PC either by Bluetooth or USB cable (just Google if you don’t know how to connect mobile with PC using either Bluetooth or USB cable).

2. After making connection you need to check its port which is very easy. Just go to control panel and open Phone and Model option and you will see something as below.


There is a Modem with its port. You have to remember that port in this case that is COM6.

3. Now comes the coding part

a. Design the form as below


Note: At the time of design drag a serial port components from toolbox in Components Tab.

b. Load all Com Port from your PC to combobox.

private void frmATCommandTest_Load(object sender, EventArgs e)
{
/*
* Name of all ports are copied to Combobox
*/
this.cmbComPorts.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
}

c. There are various baud rates as per speed.

i. 110
ii. 300
iii. 1200
iv. 2400
v. 4800
vi. 9600
vii. 19200
viii. 38400
ix. 57600
x. 115200
xi. 230400
xii. 460800
xiii. 921600

So add as items to second combobox.

d. To connect with device

private void btnConnect_Click(object sender, EventArgs e)
{
try
{
if (!this.serialPort1.IsOpen)
{
this.serialPort1.PortName = cmbComPorts.Text;
this.serialPort1.Open();
this.serialPort1.BaudRate = cmbBaudRate.Text;
this.serialPort1.DataBits = 8;
this.serialPort1.StopBits = System.IO.Ports.StopBits.One;
this.serialPort1.Parity = System.IO.Ports.Parity.None;
this.serialPort1.Handshake = System.IO.Ports.Handshake.None;

MessageBox.Show(
"\nCONNECTED SUCESSFULLY\n", "Information");
}
else
{
MessageBox.Show(
"\nALLREADY CONNECTED\n", "Information");
}
}
catch
{
MessageBox.Show(
"\nCOMMPORT IS NOT CONNECTED", "Information");
}
}

For closing connection just call close method of Serial Port.

e. It's time to code for sending a message now

public void btnSend_Click(object sender, EventArgs e)
{
if (this.serialPort1.IsOpen)
{
serialPort1.BaseStream.Flush();
string cb = char.ConvertFromUtf32(26);
System.Threading.Thread.Sleep(
2000);

this.serialPort1.Write("AT+CMGF=1\r");
//Ufone Service Center
this.serialPort1.Write("AT+CSCA=servicecenter\r\n");
this.serialPort1.Write("AT+CMGS=\"" + txtPhoneNumber.Text + "\"\r\n");
this.serialPort1.Write(txtMessage.Text + cb);

MessageBox.Show(
"\nMessage Sent\n", "Information");
}
else
{
MessageBox.Show(
"\nSerial Port Is Not Open\n", " ERROR ");
}
}

Now it is a time to run this application. It should run successfully in your Visual Studio. If you face any error the Google it or simply ask me.

To operate the code you have to select the communication port with which your mobile has been connected (in our case it is COM6) and choose Baud Rate after click on connect button. This should show you a message for successful connection. Now type the number and message and click ‘send’ button.

There are lots of many things (such as call, miss call (you can set time for fun), end call, bulk message, send multiple copy of message, check IMEI number, battery status, manufacture name and date, date and time etc.) we can do with AT Commands but for now we will stop here. For more details I have mentioned links at end of article. I have also mentioned at set of AT Commands that might come handy for you if you would like to test it.

AT Commands set for Nokia GSM and CDMA products: (These can work on other mobile set too)

Call control:
Command - Description
ATA - Answer command
ATD - Dial command
ATH - Hang up call
ATL - Monitor speaker loudness
ATM - Monitor speaker mode
ATO - Go on-line
ATP - Set pulse dial as default
ATT - Set tone dial as default
AT+CSTA - Select type of address
AT+CRC - Cellular result codes

Data card control commands:
Command - Description
ATI - Identification
ATS - Select an S-register
ATZ - Recall stored profile
AT&F - Restore factory settings
AT&V - View active configuration
AT&W - Store parameters in given profile
AT&Y - Select Set as power up option
AT+CLCK - Facility lock command
AT+COLP - Connected line identification presentation
AT+GCAP - Request complete capabilities list
AT+GMI - Request manufacturer identification
AT+GMM - Request model identification
AT+GMR - Request revision identification
AT+GSN - Request product serial number identification (IMEI)

Phone control commands:
Command - Description
AT+CBC - Battery charge
AT+CGMI - Request manufacturer identification
AT+CGMM - Request model identification
AT+CGMR - Request revision identification
AT+CGSN - Request product serial number identification
AT+CMEE - Report mobile equipment error
AT+CPAS - Phone activity status
AT+CPBF - Find phone book entries
AT+CPBR - Read phone book entry
AT+CPBS - Select phone book memory storage
AT+CPBW - Write phone book entry
AT+CSCS - Select TE character set
AT+CSQ - Signal quality

Computer data card interface commands:
Command - Description
ATE - Command Echo
ATQ - Result code suppression
ATV - Define response format
ATX - Response range selection
AT&C - Define DCD usage
AT&D - Define DTR usage
AT&K - Select flow control
AT&Q - Define communications mode option
AT&S - Define DSR option
AT+ICF - DTE-DCE character framing
AT+IFC - DTE-DCE Local flow control
AT+IPR - Fixed DTE rate

Service:
Command - Description
AT+CLIP - Calling line identification presentation
AT+CR - Service reporting control
AT+DR - Data compression reporting
AT+ILRR - DTE-DCE local rate reporting

Network communication parameter commands:
Command - Description
ATB - Communications standard option
AT+CBST - Select bearer service type
AT+CEER - Extended error report
AT+CRLP - Radio link protocol
AT+DS - Data compression

Miscellaneous commands:
Command - Description
A/ - Re-execute command line
AT? - Command help
AT*C - Start SMS interpreter
AT*T - Enter SMS block mode protocol
AT*V - Activate V.25bis mode
AT*NOKIATEST - Test command
AT+CESP - Enter SMS block mode protocol

SMS commands

SMS text mode:
Command - Description
AT+CSMS - Select message service
AT+CPMS - Preferred message storage
AT+CMGF - Message format
AT+CSCA - Service centre address
AT+CSMP - Set text mode parameters
AT+CSDH - Show text mode parameters
AT+CSCB - Select cell broadcast message types
AT+CSAS - Save settings
AT+CRES - Restore settings
AT+CNMI - New message indications to TE
AT+CMGL - List messages
AT+CMGR - Read message
AT+CMGS - Send message
AT+CMSS - Send message from storage
AT+CMGW - Write message to memory
AT+CMGD - Delete message

SMS PDU:
Command - Description
AT+CMGL - List Messages
AT+CMGR - Read message
AT+CMGS - Send message
AT+CMGW - Write message to memory

Related links