![]() |
Platforms, Frameworks & Libraries »
Mobile Development »
General
Intermediate
Infrared Communication with your Mobile PhoneBy Daniel StriglLearn how to make your Pocket PC speak with your mobile phone. |
VC6, VC7.1, eVC 3.0, Windows, PocketPC 2002, MFC, ATL, VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

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.
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.
<CR> ... Carriage return
<CR> ... Carriage return
<LF> ... Line feed
<CR> ... Carriage return
<LF> ... Line feed
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.

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/.
If you have any comments or find some bugs, I would love to hear about it and make the code better.
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.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Dec 2003 Editor: Nishant Sivakumar |
Copyright 2003 by Daniel Strigl Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |