Getting Infrared IrDA and IrSock to work on Windows
Abstract
Getting infrared communications and IrSock programs to work right the first time under Windows can be a painful task. And it is surprising how easy it becomes after you've wringed it out once or twice. The problem is essentially due to many "hidden" and "missing" steps as well as misconfigurations that you end up doing with the various devices you might have. This document is an attempt to assist the weary in getting it through, so that they may go on to hands-on programming with infrared IrDA and IrSock. The focus is primarily on Windows 98, and also Windows CE devices and their inter-operability via IR. Note that when we refer to CE devices, we are talking about hand-held devices, particularly the hand-held PC (H/PC) and the Palm-held PC (P/PC).
So here are some tips, hoping to avoid further confusion !
Verifying the Platforms
Check out the platforms you are trying to connect between. Windows NT 4.0 or earlier do not provide IR support. Windows NT 5.0 does (or will). Windows 95 needs you to install the IR3DDK (downloadable from the Microsoft site) and follow the instructions. Even then this can be problematic. Please refer to the Microsoft Knowledgebase Article Q149450 and others for Windows 95 setup. Mobile devices like hand-held PCs (H/PCs) or Palmheld PCs run Windows CE and will have native support but be aware that the header file af_irda.h used with IrSock on these platforms are slightly different.
The recommended platform to get a feel for IR is Windows 98. Windows 98 provides built in support for IR. It also provides the users with the latest WinSock DLLs that support IrDA. So the best possible setup to get IR working is between two vanilla Windows 98 PCs with IR dongles attached to the serial port. Getting this to work gives you enough information you can apply to getting the other configurations to work.
If you are specific about using a Windows CE hand held device, you can build the IR executable targeting your particular CE device under Windows NT 4.0 using VC++ toolkit for Windows CE, download it to the device and test it against your executable on Windows 98. Or even another CE device. But this is a bit tedious. Once you have a version tested and debugged between PCs, you can move it to the CE devices. Since the APIs are mostly portable, this should save some headaches for certain system configurations.
You can also use laptops running Windows 98. In some cases, these are more troublesome than regular PCs to get IR to work as we will see later.
Installing the software adapters
Make sure that the adapters are installed. This is not the physical adapter, but the "software" adapter as seen under Control Panel->Network->Adapters on vanilla Windows.
IR usually comes in two flavors. Slow IR (SIR) which gives upto 115 kbps as a dongle attached to the serial port, or as a built-in IR port. Fast IR (4Mbps) is supported usually through an add-on card due to heavy processing requirements. The built-in port will usually be detected under the Plug-and-Play of Windows 98.
Otherwise on Windows 98 you can go to Control Panel->Network->Add->Adapter->COM port or Dongle (or whichever adapter you have under some vendor name) and add the proper adapter. The Laptops would need to first enable the IrDA port from the BIOS setup before this can be done.
CE devices come with ports/adapter software pre-installed. No special setup would be required here. However, you'll have to select the communications port to be used as the "Infrared Port". This can be done from the Settings->Communications menu.
Under Windows 98, if by accident a port is installed multiple times, you can delete them from the Device manager. Make sure to use both "View devices by type" and then "View devices by connection" to identify ports to delete. Then reboot and try again.
Many laptop ports simply do not work (especially the older models). If your laptop comes off the shop with the IR adapter software installed and the Fast IR protocol also installed (check out Control Panel-> Network configuration list) it is a safe bet that the port is working. Otherwise you'll have to install the adapter software as mentioned earlier and proceed to the debugging section below.
Installing the protocol driver
In many cases, installing the adapter results in Windows automatically installing the Fast IR protocol driver. This driver is required for IrSock (Infrared sockets) support. Even though the name suggests a wrong protocol driver for a Slow IR port, this works.
It is always recommended to use the drivers provided by the manufacturer of the adapter. Sometimes it is bundled with Windows. For adapters like the Actisys dongles, you can use the Control Panel->Add new Hardware->Select from list->Infrared Devices->Vendor (or generic port) and install the adapter. The protocol driver will also get added.This is the correct way to install new (non built-in) adapters.
Sometimes the drivers supplied by vendors can cause problems if the Fast IR protocol is already installed. Removing the Fast IR protocol driver doesn't help. One way is to remove the driver files manually (right click on the ports/devices in Device manager->properties->Driver->Driver File Details on all associated devices). If this doesn't help it would be better to try a fresh installation of the OS.
Once this is done, the system (Windows 98) creates two virtual ports (e.g. COM4, LPT2) that simulate serial and parallel ports over the infrared physical port. These can be used by software that needs to see the IR port as a serial or a parallel port (e.g. active sync, direct cable connection, infrared printing).
You do have the option of choosing virtual ports. When selecting your ports in the installation process, you can also try to use virtual ports that are not COM3 or COM4 when the physical port selected is COM1 or COM2 respectively. Sometimes this makes things smoother. This could be because COM1 and COM3 share the same IRQ and the same is the case of COM2 and COM4. Also make sure that the virtual port you are selecting is not currently listed in the "View Devices by type" or "View devices by connection" options.
When communicating with a Windows CE device, in the Windows CE services ->Communications dialog box, add the above virtual port to the "Port" combo box by clicking "Install new port".
Windows CE hand-held devices have built-in Infrared ports which usually allow data exchange up to 115.2 kbps. No external driver needs to be installed for IR communications as the IRDA protocol stack is built into Windows CE.
Enabling the port
The port has to be enabled before it can be used.
On a Windows CE device the equivalent of the following needs to be done:
1) Go to Settings->Control Panel->Communications
2) Tap the PC connection
3) Select the "Infrared port" in the "Connect to Desktop computer " combo box.
When the communication is between a Windows machine running CE services and a CE hand held device, use the Programs->Communications->PC link option on the device (e.g. the H/PC). If the specified port settings are correct, communication is established. If the communication is taking place for the first time, The Partnership Wizard appears on the screen, which will guide in establishing a partnership between the DeskTop PC and the hand held. This partnership is important for IR communications. After this, an icon representing the hand held appears in the Mobile device Window. You can now move files to the H/PC from the DeskTop by simply dragging files from the Windows Explorer and dropping it in the Mobile Devices Window.
On Windows 98, port enabling can be done from the Control Panel->Infrared->Options. Note that this window doesn't pop-up to the top of other windows. After double clicking Infrared, you'll have to look for this window somewhere on your screen, perhaps hidden away under the control panel window. Also under "Preferences" select the option to display the IR icon on the task bar. Under "Identification" you can give the system a name and description. When you click OK, IR is enabled and an icon (a red LED) appears on the task bar, flashing green approximately every 3 seconds.
If you click on the icon the window again comes up, showing the current status (any devices detected around) Ideally, if you bring another IrDA enabled laptop/PC/hand held in the range with the adapters facing each other, it should be detected. The icon should change to show two LEDs facing one another (plus sound effects). But it is possible that this just doesn't happen! Or perhaps you get fluke detection: One device detects, another doesn't. Or detection happens briefly, then disconnects, then comes on again. repeatedly.
Debugging the IR port on Windows 98
Many things could be going wrong. Your port may not be functional, the driver not installed, installed driver not configured for the right port, the driver incompatible with earlier installation, or simply the driver doesn't work properly and needs some "help".
- Check out the physical status of the port. With the task bar icon enabled, expose the port to a diffused light source. You may hold up the lap top or PC IR adapter to the office tube light and wait for nearly a minute. If the icon under Windows 98 changes to show two LEDs with crosses indicating a "jam", then your port is working fine. Alternately, you can try using a flashlight or a laser-pointer light, but it will take more time and also not very reliable. The best method would be to use your TV remote control, or any infrared remote control and press down some button that send continuous signals (e.g. change channel). If the port is working, it will detect a "jam" and the icon will change. If your laptop has a dual port arrangement (front and back) be sure to jam both together. If it still doesn't show any activity, the chances are that you have a bad port, or the driver needs some "help".
- The next step would be to install the Direct Cable Connection software (if not already there). This can be from Control Panel->Add/Remove Programs->Windows setup->Communications->Details (on Windows 98). Do this on both machines. The software can be accessed from under Start->Programs->Accessories->Communications. Best make a desktop shortcut. Setup the machine being debugged as a 'host' that listens and the other as a 'guest' that connects. First use the virtual COM port for listening. Then click on 'listen'. This will startup the virtual port driver over the physical port. Check out the port diagnostics as in step 1.
- If diagnostic still fails, setup the 'host' to listen on the physical port itself. (e.g. COM2 instead of COM4). It might happen that now the detection kicks in properly. You'll have to wait for the message 'is the guest computer connected?', then iconize this window and proceed to using the IR connection. If you attempt to bring the other device in range before this message appears, there may be repeated attempts to "log-in" resulting in the connection breaking repeatedly.
If none of these works, you probably have a bad port or an incompatible driver. Do check that you are using the right ports (e.g. COM2). Many laptops need to enable this in the BIOS. It is also possible that you are using some other driver also on the same port.
As far as Windows CE hand held devices are concerned, the application "repllog.exe" is used to establish IR communication between a DeskTop and a Hand-held PC. This application is executed whenever "PC link" is tapped and the connection is established. This is available with almost all the Windows CE devices
Checking out IR
Before trying out any socket programs, first try out (if on Windows 98), and the Infrared Recipient program. (Right click on My Computer ->Open). Contrary to the name suggested, it can both send and receive files. Use this to make sure that you can indeed transfer a big file across. The other machine should also be running the "Infrared Recipient" program, which means that the other machine should also be a Windows 98 machine. .On a CE HandHeld, you have the "Contacts" program where you have the "Send" and "Receive" options. However, this way you can transfer a file only to another H/PC or PalmPC.
On Windows 98, you should see the icon change to show data transfer between the devices.
The next step would be to build your IrSock programs and let them run on the PCs/devices.
Checking out IrSock
The sample example in MSDN should work fine. However, it has no error checking. All the calls made there would need to be checked for this. If you are using a console mode application, then use the cerr stream instead of cout stream to display messages. This is because 'cout' is buffered and you will not see your message as and when it actually comes. This can cause real confusion in understanding what goes on.
To develop an IrSock application for Windows 95/98, you'll need the af_irda.h file in addition to the regular VC++ environment. If not this file, a few definitions from this file like SOCKADDR_IRDA etc. would be required. Note that these definitions are different for the CE platform. The definition of the constants vary. Also on CE, there is no IRLMP_DISCOVERY_MODE option in the af_irda.h header file that comes along with the VC ++ ToolKit for Windows CE. This means that we can't place the application running in a Windows CE device in discovery mode using the above said option. However, Windows 98 supports the discovery mode option. This file can be found in the IR3DDK from the Microsoft site, or if you have the CE development toolkit installed, underneath an include directory. You can also get it from the Calsoft Labs online article on IrSock programming mentioned later on.
You can build the applications on any vanilla Windows development machine with this header file and move it to the PC which has the IR interface. Windows CE would require the development tool kit for CE to be installed. To move the application to a Windows CE device, you should install Windows CE Services on the host PC.
Once you are able to get the sample server/client program working, the rest is easy. For information on IrSock programming details, refer (among others) to the online technical paper at the Calsoft Labs site: IrSock programming

