Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Infrared Communication with your Mobile Phone

0.00/5 (No votes)
17 Dec 2003 3  
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:

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:

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:

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:

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:

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here