RC102 IR remote controller

I picked up this USB device for not-so-very-much at a local supermarket, and set about trying to get it to work in Linux. I wanted to use it in my presentations: so I could click a button on the remote as I walk around the room rather than hovering over the computer. This is not something I do every day, and certainly not when I am using the laptop for anything else, so for my purposes a user-space program that may not be particularly cpu-efficient is fine. If you have different needs this code may not be so suitable.

My attempts are posted here in the hopes that they may be useful to someone. I don't claim that this is the only, or the best way, to do this. Only that it works for me. If any reader would like to contribute you are most welcome. If you do find anything here helpful, I would appreciate it if you could email me and tell me ( R dot W dot Kaye at bham dot ac dot uk ) but I'm sorry: I don't expect to have time to help you if you are stuck, your device doesn't work, or provide any other support.

Identification

The device consists of a IR receiver-dongle labelled IR-507 with USB interface, and a IR remote control labelled RC-102 rather like you'd get on TV sets, DVDs, etc, (except a bit smaller). The remote control is the exact size of a PCMCIA card, so can be stowed in the PCMCIA slot when not in use.

Mine was boxed as Tevion Computing Slim USB multi remote controller, though the same device may be available in other packaging.

When plugged in in Linux its firmware and USB identification is RC102-809 USB Remote, by Formosa Industrial Computing. USB identifier: Cls=03, Vendor=147a, ProdID=e019. Here is a more detailed description from /proc/bus/usb/devices. (I don't understand it all. If you do and can provide me with a description of what all this means I would be delighted to include it on this web page.)

T:  Bus=01 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#=  3 Spd=1.5 MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=147a ProdID=e019 Rev= 1.02
S:  Manufacturer=Formosa Industrial Computing
S:  Product=Formosa RC102-809 USB Remote
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=300mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=01 Prot=02 Driver=(none)
E:  Ad=81(I) Atr=03(Int.) MxPS=   4 Ivl=10ms

Getting it to work

I first installed the device-driver in windows. The driver provided is annoying as it nags when it cannot find the device on start-up, and this slows down start-up and log-in time, whereas I only want to use it on very special occasions, e.g. when I am giving presentations. Otherwise it works OK.

To see what it was doing, I tried USB snooping, etc., but didn't learn very much from that - perhaps because I know so little about USB etc. In fact more than 95% of what I saw I didn't understand at all. But a hint from a user on a use-net article trying to get a similar device going in BSD suggested that all that is needed is to read packets of four bytes from the device, and this together with libhid (http://libhid.alioth.debian.org/) turns out to be enough to get it to work, at least well enough for my purposes.

The device will receive from other IR controllers, such as the one you probably have for your TV set, though I haven't even begun to consider decoding all of these.

Usage

The software I wrote is a simple C program that polls the device and writes a line or lines to an output stream depending on the key that was pressed on the device. Much of the code is lifted from a test program supplied with libhid. (Thanks!) Lots of the code from my testing is still in the production version, so there are plenty of ways to tinker if you feel so inclined.

The device seems to operate by some sort of hand-shaking protocol. I didn't discover the exact details, but stopped when it was good enough for me. Events are usually key-presses or key-releases and have four-byte codes. The program outputs a (configurable) string to stdout so can be read by humans or programs. The normal usage is to put it in a pipe:

$ rc102remote | myinterpretor 

where rc102remote interprets events and sends commands to myinterpretor which acts on them. This pipe looks clunky (there's no daemon, system process, or system driver) but is just what I want: I can run it (via a script) exactly when it is needed, which is usually when I am giving a presentation. Polling (the only method I found to interface with the device) is comparitively CPU-intensive and I don't want it left on unnecessarily.

I use xte from http://hoopajoo.net/projects/xautomation.html (Debian xautomation package) as the interpretor that fakes keyboard and mouse events in X. Other filters and interpretors should be easy to write. rc102remote reads a table from a file (by default rc102.table in the current directory) which contains commands corresponding to the 14 possible key presses. See the example provided. The incantation

$ rc102remote | xte

with the standard datafile rc102.table is provided as a one-line shell script rc102.

Killing the rc102remote process using CTRL-C is programmed to shut things down nicely.

Building and installing

To compile rc102remote you will need gcc, libhid (Debian libhid0 and libhid-dev packages, see http://libhid.alioth.debian.org/), I used version 0.2.12-1 and then later 0.2.15. If you need to compile libhid or xte follow the instructions at the websites. There is a makefile which builds a single file, an executable called rc102remote and installs rc102remote and rc102 to /usr/local/bin. Please note that (unusually) both make and make install must be done as root to avoid problems of permissions on the hardware of your usb system.

If anyone reading this can help, please provide comprehensive instructions on setting the permissions for the device correctly in all the different versions of hotplug.

Running rc102

The easiest way is to do "rc102" which reads a table rc102.table in the current directory (or where rc102remote was installed otherwise) and passes commands to xte. You can edit the table to your heart's desire (there are comments in the sample table provided to tell you how) or for more control use the rc102remote command, e.g., to turn logging on with -l (or -a in append mode) and to specify the log file and command table with -n and -t respectively.

The only possible problems I can forsee is strange errors such as

WARNING: hid_find_usb_device(): no matching USB device found.
hid_force_open failed with return code 7

This (and other similar ones) means one or more of: (1) your device is not plugged in; (2) you do not have the right device for this program (check the USB system for the ID of your device); or (3) you did not build the program with super-user privileges.

Download

A tarball is available here: rc102remote.tar.gz.

Good luck! (And do let me know if this was useful...)

Alternatives

Just when I had finished writing and uploading all the code I did one last search at http://www.linux-usb.org/ and found that very recently David Braithwaite has written a driver, probably better than mine. You'll find it at http://braithwaite.dk/wikka/ZolidIrRemote.


Copyright Richard Kaye, R dot W dot Kaye at bham dot ac dot uk, http://web.mat.bham.ac.uk/R.W.Kaye/. Copying and usage of all information in this web page is permitted under the terms of the latest version of the GNU general public licence (see COPYING). EVERYTHING IS PROVIDED AS-IS WITH NO WARRANTY.