Click here to Skip to main content
15,867,704 members
Articles / Programming Languages / Visual Basic
Article

.NET Phone Communication Library Part I - Retrieve Phone Settings

Rate me:
Please Sign up or sign in to vote.
4.79/5 (30 votes)
4 Dec 2006CPOL2 min read 161.8K   5.4K   134   23
Communicate with GSM modem phones using AT commands

Sample Image - phoneat.jpg

Introduction

This article describes a way of communicating with your mobile phone using AT commands. Normally, a GSM compatible mobile phone will have a built-in modem, which we can communicate using AT commands. The AT command set should be common among all the handphone manufacturers including Nokia, Sony Ericsson, Siemen, and Motorola, although slight differences exist.

In this article, I will use an open source .NET phone communication library to show you the various ways of communicating with your mobile phone. The library is available here.

Getting started

Before we can communicate with the GSM phone, a connection must be established first. The connection can be either serial, bluetooth, or irDA. As long as we can connect to the phone, it is fine.

In this article, I established a bluetooth connection with my mobile phone. Firstly, I create a partnership between my laptop and my Nokia mobile phone, and then select the Bluetooth Serial Port service on my mobile phone. The configuration may wary depending on the Bluetooth software and the driver for your modem. If everything is okay, you should be able to see a Bluetooth modem configured in your device manager. Successful configuration will have the following:

Image 2

Take note that in my configuration, the COM port configured is COM9 and the baud rate is 115200. These settings will be used to connect to the mobile phone.

Test the configuration

After the Bluetooth connection is set up, we can use HyperTerminal to try to send AT commands to make sure the connection is okay.

Image 3

Image 4

As you can see, AT commands start with the word "AT". E.g., "ATE1" means echo the command typed locally, "AT+CGMM" displays the handphone model, and "AT+CSCA?" displays the SMSC configured in the mobile phone.

If everything is okay now, you can use the sample code attached in this article to retrieve various handphone settings. The results will be similiar to the screenshot displayed at the top of this article. Take note that different handsets may support different AT command sets. Certain AT commands may not be available in certain handsets.

The code in the solution is quite straightforward. It makes use of the open source library atSMS to retrieve various phone configurations by sending AT commands. You can read the list of the APIs available in the documentation and sample provided.

VB
If cboComPort.Text = String.Empty Then
          MsgBox("COM Port must be selected", MsgBoxStyle.Information)
          Return
      End If

      Dim oGsmModem As New GSMModem

      oGsmModem.Port = cboComPort.Text

      If cboBaudRate.Text <> String.Empty Then
          oGsmModem.BaudRate = Convert.ToInt32(cboBaudRate.Text)
      End If

      If cboDataBit.Text <> String.Empty Then
          oGsmModem.DataBits = Convert.ToInt32(cboDataBit.Text)
      End If

      If cboStopBit.Text <> String.Empty Then
          Select Case cboStopBit.Text
              Case "1"
                  oGsmModem.StopBits = Common.EnumStopBits.One
              Case "1.5"
                  oGsmModem.StopBits = Common.EnumStopBits.OnePointFive
              Case "2"
                  oGsmModem.StopBits = Common.EnumStopBits.Two
          End Select
      End If

      If cboFlowControl.Text <> String.Empty Then
          Select Case cboFlowControl.Text
              Case "None"
                  oGsmModem.FlowControl = Common.EnumFlowControl.None
              Case "Hardware"
                  oGsmModem.FlowControl = Common.EnumFlowControl.RTS_CTS
              Case "Xon/Xoff"
                  oGsmModem.FlowControl = Common.EnumFlowControl.Xon_Xoff
          End Select
      End If

      Try
          oGsmModem.Connect()
      Catch ex As Exception
          MsgBox(ex.Message, MsgBoxStyle.Critical)
          Return
      End Try

      Try
          txtRevision.Text = oGsmModem.Revision
      Catch ex As Exception
          txtRevision.Text = "Not supported"
      End Try

      Try
          txtIMSI.Text = oGsmModem.IMSI
      Catch ex As Exception
          txtIMSI.Text = "Not supported"
      End Try

      Try
          txtIMEI.Text = oGsmModem.IMEI
      Catch ex As Exception
          txtIMEI.Text = "Not supported"
      End Try

      Try
          txtModel.Text = oGsmModem.PhoneModel
      Catch ex As Exception
          txtModel.Text = "Not supported"
      End Try

      Try
          txtManufacturer.Text = oGsmModem.Manufacturer
      Catch ex As Exception
          txtManufacturer.Text = "Not supported"
      End Try



      Try
          txtSMSC.Text = oGsmModem.SMSC
      Catch ex As Exception
          txtSMSC.Text = "Not supported"
      End Try


      Try
          Dim rssi As Rssi = oGsmModem.GetRssi
          txtSignal.Text = rssi.Current & " of " & rssi.Maximum
      Catch ex As Exception
          txtSignal.Text = "Not supported"
      End Try

      Try
          Dim storages() As Storage = oGsmModem.GetStorageSetting
          Dim i As Integer
          txtSupportedStorage.Text = String.Empty
          For i = 0 To storages.Length - 1
              Dim storage As Storage = storages(i)
              txtSupportedStorage.Text += storage.Name & "(" &_
                  storage.Used & "/" & storage.Total & "), "
          Next
      Catch ex As Exception
          txtSupportedStorage.Text = "Not supported"
      End Try

      Try
          Dim loc As Location = oGsmModem.GetLocation
          txtLocation.Text = "Cell Id: " & loc.CellID & _
               ", MNC: " & loc.MNC & ", MCC: " & _
               loc.MCC & ", LAI: " & loc.LAI
      Catch ex As Exception
          txtLocation.Text = "Not supported"
      End Try

      Try
          txtPhoneNumber.Text = oGsmModem.MSISDN
      Catch ex As Exception
          txtPhoneNumber.Text = "Not supported"
      End Try

      Try
          Dim battery As Battery = oGsmModem.GetBatteryLevel
          txtBattery.Text = battery.BatteryLevel & "/" & _
                            battery.MaximumLevel & "(Charging: " &_
                            battery.BatteryCharged & ")"
      Catch ex As Exception
          txtBattery.Text = "Not supported"
      End Try

In future articles, I will show you how to send ASCII and Unicode SMS using AT commands and the open source library. So stay tuned...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Malaysia Malaysia
A programmer for a long time, and still learning everyday.

A supporter for open source solutions, and have written quite a few open source software both in .NET and Java.

https://mengwangk.github.io/

Comments and Discussions

 
QuestionCall receiving through GSM modem Pin
Member 1164025322-Feb-16 20:32
Member 1164025322-Feb-16 20:32 
AnswerRe: Call receiving through GSM modem Pin
mengwangk22-Feb-16 20:37
mengwangk22-Feb-16 20:37 
GeneralMy vote of 5 Pin
Global Analyser5-Nov-10 8:59
Global Analyser5-Nov-10 8:59 
GeneralCreate Call From USB Device Pin
Anubhava Dimri20-Nov-09 20:05
Anubhava Dimri20-Nov-09 20:05 
General[Message Deleted] Pin
it.ragester28-Mar-09 5:46
it.ragester28-Mar-09 5:46 
Generalatsms with postpaid not working Pin
jmjj11-Dec-08 6:32
jmjj11-Dec-08 6:32 
GeneralIVR system problem Pin
Akash Agarwal9-Jun-08 1:11
Akash Agarwal9-Jun-08 1:11 
Generalhelp in project Pin
mohammed qaid2-May-08 8:17
mohammed qaid2-May-08 8:17 
GeneralMultipart SMS Pin
Maximilian Seifert18-Apr-08 5:56
Maximilian Seifert18-Apr-08 5:56 
GeneralRetrieve more than one phone Pin
Member 404574914-Feb-08 20:32
Member 404574914-Feb-08 20:32 
QuestionBluetooth Dongle instead Bluetooth Modem Pin
Member 404574912-Feb-08 23:00
Member 404574912-Feb-08 23:00 
GeneralImports ATSMS Pin
gmzan28-Jan-08 16:38
gmzan28-Jan-08 16:38 
GeneralConnect via COM port Pin
phuong oanh27-Jan-08 18:54
phuong oanh27-Jan-08 18:54 
Question.NET Phone Communication part 2 and 3 missing Pin
mpradeepg23-Aug-07 4:56
mpradeepg23-Aug-07 4:56 
AnswerRe: .NET Phone Communication part 2 and 3 missing Pin
Prashant C18-Oct-07 20:32
Prashant C18-Oct-07 20:32 
QuestionPort Detection Pin
xriv11-May-07 13:26
xriv11-May-07 13:26 
GeneralLicensing question. Pin
dev00117-Apr-07 1:41
dev00117-Apr-07 1:41 
GeneralNokia Dev portal Pin
vmihalj29-Jan-07 22:27
vmihalj29-Jan-07 22:27 
www.forum.nokia.com

You can find a lot of documents there, including AT command list.

--
"If you think that knowledge/education is expensive, would you try ignorance?"

Vatroslav 'Ziggy' Mihalj, B.Sc.Computer Science
Member of HUPRO, ACM, IEEE, IEEE Computer Soc. and Communications Soc.

Questionphone number?? Pin
Muammar©5-Dec-06 22:26
Muammar©5-Dec-06 22:26 
AnswerRe: phone number?? Pin
Inanc Gumus12-Dec-06 11:09
Inanc Gumus12-Dec-06 11:09 
GeneralRe: phone number?? Pin
Shah Z. S12-Dec-06 22:43
Shah Z. S12-Dec-06 22:43 
AnswerRe: phone number?? Pin
mengwangk14-Dec-06 20:07
mengwangk14-Dec-06 20:07 
GeneralRe: phone number?? Pin
Muammar©15-Dec-06 18:28
Muammar©15-Dec-06 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.