Click here to Skip to main content
15,867,686 members
Articles / Mobile Apps / Windows Mobile

Infrared Communication with your Mobile Phone

Rate me:
Please Sign up or sign in to vote.
4.89/5 (88 votes)
17 Dec 2003CPOL7 min read 1.2M   3.6K   218   274
Learn how to make your Pocket PC speak with your mobile phone.

Sample Image

Introduction

My English is not very well and so I hope everyone can understand this article. Still if questions should exist, I will gladly answer those. And if someone should find some errors, please send me the correct version of the wrong text - thanks for the help in improving my English knowledge ;-).

For data exchange, most of the new mobile phones and Pocket PCs possess an infrared (IRDA) port. So, why not use this infrared connection to communicate between these two devices?

This simple Pocket PC 2002 application shows how to communicate with your mobile phone, it will read the manufacturer, the model identification and the Phone Book of your mobile phone to your Pocket PC.

I have tried this Pocket PC application (running on my HP jornada 565) only with a Nokia 5210, my new Siemens S55 and a very old Siemens S25 mobile phone. So, I hope the application will also work with other mobile phones.

How can I speak with the mobile phone?

To speak with your mobile phone you have to use some special commands, called AT commands. You have to send these commands via the IRDA port of your Pocket PC to the mobile phone and the mobile phone will respond to you. If the mobile phone supports the received AT command, it will send you a valid response, otherwise it will send you an error response.

The AT commands have a general structure, for example take a look at the figure below:

AT command

<CR> ... Carriage return

This command is to request the manufacturer identification of the mobile phone. For example a Nokia 5210 will send you the following response:

AT response

<CR> ... Carriage return
<LF> ... Line feed

If the mobile phone doesn't support the received AT command, it will send you an error response:

AT error

<CR> ... Carriage return
<LF> ... Line feed

You can find some detailed documentation about the AT commands at the following sites:

The Code

The application is a simple dialog based MFC application including some simple API calls.

For the infrared communication, I have written a simple class called CIrdaPort. The class supports some functions to open and close the IRDA port and some functions for the read and write operations.

UML class diagram

To open the IRDA port use the following function:

C++
BOOL CIrdaPort::Open(UINT uiPort);

This function will open the IRDA port, the uiPort parameter defines the index of the IRDA port (1 for COM1, 2 for COM2, 3 for COM3). The return value TRUE indicates success, the value FALSE failure.

You can use the following function to take a look in the registry for the index of the IRDA port:

C++
UINT CIrdaPort::FindPortIndex();

If the function finds some index of the IRDA port in the registry this index will be returned, otherwise the return value is 0.

If you want to write some characters to the IRDA port you can use the following function:

C++
BOOL CIrdaPort::Send(const CString& strSend) const;

This function will send the string strSend to the mobile phone. The return value FALSE indicates failure, the value TRUE success.

To wait for a response you can use the following function:

C++
BOOL CIrdaPort::WaitForResponse(CString& strResponse, DWORD dwTimeout) const;

This function waits for a response strResponse of the mobile phone or returns with FALSE if the timeout dwTimeout occurred.

If you are finished with all read and write operations you have to close the port with the following function:

C++
void CIrdaPort::Close();

This function will close the IRDA port.

When you click on the "Read ..." button of the dialog, the application tries to connect to the mobile phone and read some information about the phone, like the manufacturer and the model identification (for example: Nokia Mobile Phones, Nokia 5210 or SIEMENS, S55). After that it tries to read all Phone Book entries of your mobile phone and display it in a list box on the dialog.

Don't forget to activate the infrared port of your mobile phone!

Before you can test the communication between your Pocket PC and your mobile phone, you have to activate the infrared (IRDA) port of your mobile phone. Most of the mobile phones have their own menu item to activate the infrared port. For example, for a Nokia mobile phone you have to choose Menu -> Infrared. After activating the infrared port, you will see the following symbol IR symbol at the top left corner on the display of your Nokia mobile phone and you will know that the infrared port is enabled.

Some mobile phones, like the Nokia phones, disable the infrared port after some minutes if there is no data exchange on the infrared connection. So, before you start a communication take a look on your mobile phone and reactivate the infrared port if necessary. Look also that there is a straight connection between the infrared sensor of your Pocket PC and your mobile phone and that there is nothing between the two devices which can block the communication.

Bluetooth connection between Pocket PC and mobile phone

After I published this article, I received many questions about how to connect your Pocket PC with your mobile phone via Bluetooth. I couldn't try it because I have no Bluetooth mobile phone or Bluetooth Pocket PC at the moment, but João Paulo Figueira tried it out and found the answer:

Change the name of the communications port from COMx: to BTC1: and comment out the following line:

VERIFY(SetupComm(m_hPort, 2048, 2048));

It's also possible to increase the port speed up to 115200.

João Paulo Figueira also found the registry key that holds the port's name, but he didn't know if this is standard. So, it would be great if you have some information about that and send it to me or João Paulo Figueira.

The registry key that he found that holds the port's name is HKEY_LOCAL_MACHINE\ExtModems\BtDialupModem.

Related links

If you have some problems with the sample application or you need some more information about RAW Infrared Communication on Pocket PC, take a look at Ruud en Frida Vermeij's homepage at http://vermeij.filternet.nl/programmer/rawir.html. In this site you can find many useful tips and tricks about the RAW Infrared Communication on Pocket PC.

If you are interested in Infrared Winsock Communication (IrSock) on Pocket PC and Desktop PC devices, take a look at my IRDA article at the Pocket PC Developer Network. This article is going to demonstrate, how simply you can implement the infrared support into your Windows applications. It provides a small Server/Client example, with the help of which you can send messages from your Pocket PC application to a desktop Windows application. You can use this example as a base for your own applications, which will provide ability to exchange data between different devices right from your application.

IrdaMobile under the normal Windows operating system (Windows 2000 or XP)

Since I have published this article in January this year, one of the most asked questions in the forum and the mails was, how the implement the sample application under the normal Windows operating system, like Windows 2000 or XP.

Sample Image

So, now I took the time to implement the sample application of this article under the normal Windows operating system, like Windows 2000 or XP.

Now, you can download a working executable of the IrdaMobile application for the normal Windows operating system and the hole source code at the top of this article.

The only thing you need to run the sample application under your normal Windows operating system (Windows 2000 or XP) is a virtual COM port driver like IrCOMM2k (Virtual Infrared COM Port for Windows 2000/XP). IrCOMM2k is a driver for Windows 2000 and XP, it emulates a serial port which can be used to exchange data via IrDA with mobile devices. For more information about this topic take a look at the "Technical Details" of this driver at http://www.ircomm2k.de/.

Bugs and comments

If you have any comments or find some bugs, I would love to hear about it and make the code better.

Release history

  • 18.12.2003

    Added the IrdaMobile sample for the normal Windows operating system (Windows 2000 or XP).

  • 31.10.2003

    Some changes in the CIrdaPort::FindPortIndex() function.

  • 14.09.2003

    Added the "Bluetooth Connection between Pocket PC and Mobile Phone" part to the article (thanks to João Paulo Figueira).

  • 09.09.2003

    Correction of the wrong implementation of the CIrdaPort::FindPortIndex() function (thanks to Ruud en Frida Vermeij).

  • 24.01.2003

    Removed the APS file from the source code archive (thanks to Johann Gerell).

  • 22.01.2003

    First release in CodeProject.

License

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


Written By
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Maybe irDA Socket is better than ComPort, WindowsXP doesn't support virtual irDA ComPort Pin
Daniel Strigl2-Oct-03 20:04
Daniel Strigl2-Oct-03 20:04 
GeneralReally Cool Pin
Mohamed Abdel-Monem25-Jan-03 1:03
Mohamed Abdel-Monem25-Jan-03 1:03 
GeneralRe: Really Cool Pin
Daniel Strigl25-Jan-03 5:50
Daniel Strigl25-Jan-03 5:50 
GeneralCool! Pin
Cathy23-Jan-03 15:02
Cathy23-Jan-03 15:02 
GeneralRe: Cool! Pin
John Liu28-Jan-03 17:56
John Liu28-Jan-03 17:56 
GeneralRe: Cool! Pin
Cathy29-Jan-03 21:57
Cathy29-Jan-03 21:57 
GeneralRe: Cool! Pin
TigerNinja_18-Feb-03 12:15
TigerNinja_18-Feb-03 12:15 
GeneralStupendous! Pin
Eric Anderton23-Jan-03 14:16
Eric Anderton23-Jan-03 14:16 
Although I don't own a cellphone, I've always wondered exactly how useful my IR port on my Palm really was. Now I know.

Good work! You have my 5. Wink | ;)

Any plans for any PDA/Phone software bundles in the near future?

- Eric

Calling a function is like tying your shoe. Remoting a function is like tying someone else's shoe... while they're running around... in China.
GeneralRe: Stupendous! Pin
Daniel Strigl23-Jan-03 20:28
Daniel Strigl23-Jan-03 20:28 
GeneralNice Pin
Johann Gerell23-Jan-03 11:01
Johann Gerell23-Jan-03 11:01 
GeneralRe: Nice Pin
Daniel Strigl23-Jan-03 20:35
Daniel Strigl23-Jan-03 20:35 
GeneralGreat class... Pin
Ardiani23-Jan-03 1:53
Ardiani23-Jan-03 1:53 
GeneralRe: Great class... Pin
Daniel Strigl23-Jan-03 2:08
Daniel Strigl23-Jan-03 2:08 
GeneralRe: Great class... Pin
Ardiani23-Jan-03 2:24
Ardiani23-Jan-03 2:24 
GeneralThis is cool Pin
Christian Graus23-Jan-03 0:39
protectorChristian Graus23-Jan-03 0:39 
GeneralRe: This is cool Pin
Daniel Strigl23-Jan-03 0:54
Daniel Strigl23-Jan-03 0:54 
GeneralThis article sounds interesting Pin
Anthony_Yio22-Jan-03 14:34
Anthony_Yio22-Jan-03 14:34 
GeneralRe: This article sounds interesting Pin
Daniel Strigl23-Jan-03 3:57
Daniel Strigl23-Jan-03 3:57 

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.