Comedi Relacs Plugins


Interfaces to the comedi data acquisition library for normal analog input and output as well as for dynamic clamp.Comedi (linux control and measurement device interface) provides hardware drivers to many data acquisition boards with a common library interface. The RELACS comedi plugins access data acquisition boards by means of the comedi library.

For general information about comedi and a list of supported devices see


Install comedi

You should install the comedi drivers and library prior to configuring RELACS, so that ./configure can detect the presence of the comedi library. This requires to compile a kernel first.

Linux kernel

In order to be able to install the comedi drivers you need to have a kernel source tree that matches your running kernel image. Either compile your own kernel from scratch (section Compile your own kernel , takes some time), or make sure that you get a matching source tree for your kernel image (section Install sources for an existing kernel).

Install sources for an existing kernel

  1. Get the soure that matches your kernel. On Ubuntu/Debian you get the kernel source matching your running kernel image by executing
    $ cd /usr/src
    $ apt-get source linux-image-`uname -r`
    as root and cd into the kernel source directory
    $ cd `uname -r`
  2. Copy the kernel configuration file of your kernel image to the source:
    $ cp /boot/config-`uname -r` .config
  3. Make sure the file Module.symvers is also in your source. On Ubuntu/Debian you find it in the corresponding linux-headers directory:
    cp ../linux-headers-`uname -r`/Module.symvers .
  4. Run
    $ make oldconfig
    $ make prepare
    $ make scripts

Compile your own kernel

  1. Either get a vanilla kernel from, e.g., place the tar file in /usr/src and unpack it with
    $ cd /usr/src
    $ tar xjvf linux-
    (replace linux- by the directory name of your new kernel source). Create a softlink to your kernel source
    $ cd /usr/src
    $ ln -s linux- linux
    $ cd linux
  2. Reuse your current configuration (replace XXX by the name of your running kernel):
    $ cp /boot/config-XXX .config
    $ make oldconfig
    Hit enter to all the (probably many) questions.
  3. Steps 3. to 6. describe the normal way to compile a linux kernel. On Debian systems there is an elegant alternative that is described in step 9. below. First, you configure your kernel by calling
    $ make menuconfig
    Possible settings you might want to change are: Leave the configuration dialog by pressing "Exit" until you are asked "Save kernel config?". Select "Yes".
  4. Then compile and install the kernel
    $ make && make modules && make modules_install && make install
    This takes quite a while.
  5. Finally you might need to create a RAM disk image file, if make install did not create a /boot/initrd- file already:
    $ cd /boot
    $ update-initramfs -c -k
  6. Check the grub menu whether your new kernel was added.. With grub v1 (default up-to Debian Lenny) there should be an entry like this in /boot/grub/menu.lst:
    title           Debian GNU/Linux, kernel
    root            (hd0,0)
    kernel          /boot/vmlinuz- root=/dev/sda1 ro quiet
    initrd          /boot/initrd.img-
    With grub v2 (default since Debian Lenny) there should be an entry like this in /boot/grub/grub.cfg:
    menuentry "Ubuntu, Linux" {
            if [ -n ${have_grubenv} ]; then save_env recordfail; fi
            set quiet=1
            insmod ext2
            set root=(hd0,1)
            search --no-floppy --fs-uuid --set cc028ecc-e801-4f23-a86d-ae2d10a71294
            linux   /boot/vmlinuz- root=UUID=cc028ecc-e801-4f23-a86d-ae2d10a71294 ro   quiet splash
            initrd  /boot/initrd.img-
    You can configure grub v2 by editing the file /etc/default/grub and running update-grub afterwards.
  7. Reboot the computer into the new kernel.
    $ reboot
  8. Install third party kernel modules as well, like for example the ones for your graphics board. For your nvidia graphics board, download the driver from Install it by calling
    $ sh
    If you want to install the nvidia driver for a second kernel, then call
    $ sh -k -K
    (replace by the name of the kernel where you want to install the nvidia driver, i.e. the string 'uname -r' would return if that kernel is running).
  9. On a Debian system there is an alternative to steps 3. - 6. for compiling a linux kernel:
    1. Get the kernel-package
      $ apt-get install kernel-package
    2. Configure and build the kernel:
      $ make-kpkg --initrd --revision r1 --config menuconfig kernel-image
      See step 3. for hints on the configuration options.
    3. Install the kernel
      $ cd ..
      $ dpkg -i linux-image-
    4. continue with step 6.


  1. Download the current comedi sources from the CVS repository to /usr/local/src . When prompted for a password, hit enter.
    $ cd /usr/local/src
    $ cvs -d login
    $ cvs -d co comedi
    $ cvs -d co comedilib
    $ cvs -d co comedi_calibrate
    Or download the current CVS snapshots from to /usr/local/src and unpack them
    $ cd /usr/local/src
    $ tar xzvf comedi.tar.gz
    $ tar xzvf comedilib.tar.gz
    $ tar xzvf comedi_calibrate.tar.gz
  2. You may need to install the packages: autoconf, libtool, libgsl0-dev, libboost-dev.
  3. Make sure that you are really running the kernel for which you want to install comedi! You can check with
    $ uname -r
  4. Change to the comedi directory:
    $ cd /usr/local/src/comedi
  5. Generate the configuration script by calling
    $ ./
    You may ignore warnings and reminders.
  6. Configure simply by calling
    in case you want to install comedi into your currently running kernel. If -c /usr/src/linux is not your running kernel, then call
    $ ./configure --with-linuxdir=/usr/src/linux
  7. Compile and install (as root)
    $ make && make install
    $ depmod -a
  8. For some strange reason, the include files for kcomedilib linux/comedilib.h and linux/comedi.h are not installed by comedi to [prefix]/include/linux . These files are needed for compiling the kernel modules that use comedi. Also, RTAI expects comedi include files in [prefix]/include/linux. Therefore you need to copy the comedi include files to [prefix]/include/linux yourself:
    $ cp include/linux/comedi.h /usr/include/linux/
    $ cp include/linux/comedilib.h /usr/include/linux/
  9. Check loading the comedi module:
    $ modprobe comedi
    If you do not get any error message, then the comedi kernel modules were successfully compiled and can be loaded into the kernel.
  10. Check autodetection of your data acquisition board:
    $ udevadm trigger
    $ ls /dev/comedi*
    In case the ls command shows something like
    /dev/comedi0        /dev/comedi0_subd1   /dev/comedi0_subd12
    /dev/comedi0_subd0  /dev/comedi0_subd11  /dev/comedi0_subd2
    i.e. some comedi* character device files, your board probably was detected. Run
    $ comedi_test -t info -f /dev/comedi0
    to see more details about your data acquisition board (note: comedi_test is part of comedilib, see below). In case no /dev/comedi* device file shows up or comedi_test reported an error (E: comedi_open("/dev/comedi0"): No such device), your data acquisition board needs to be configured manually, using something like
    $ comedi_config /dev/comedi0 ni_mio_cs
    that can be put into the /etc/init.d/boot.local file, so that the board is configured during startup of the system. Read the man page of comedi_config first!
    $ man comedi_config


  1. Change to the comedilib directory:
    $ cd /usr/local/src/comedilib
  2. Generate the configuration script by calling
    $ ./
    You may ignore warnings and reminders.
  3. Configure comedilib to be installed in /usr/lib and /usr/include
    $ ./configure --prefix=/usr --sysconfdir=/etc
    If you want to have Comedlib to be installed somewhere else, specify another prefix. You may want to read ./configure --help as well. Pay attention to warnings and errors! You might need to install additional software first.
  4. Compile and install (as root)
    $ make && make install


  1. Change to the comedi_calibrate directory:
    $ cd /usr/local/src/comedi_calibrate
  2. Generate the configuration script by calling
    $ autoreconf -v -i
    You may ignore warnings and reminders.
  3. Configure
    $ ./configure --prefix=/usr --sysconfdir=/etc
  4. Compile and install (as root)
    $ make && make install

Install RTAI and comedi

For dynamic clamp you need an RTAI patched linux kernel and comedi.

Linux kernel and RTAI patch

  1. Download the latest RTAI version (version 3.7.1) from and put into /usr/local/src .
  2. Unpack RTAI in /usr/local/src:
    $ cd /usr/local/src
    $ tar xjvf rtai-3.7.1.tar.bz2
    $ ln -s rtai-3.7.1 rtai
  3. Check for available patches. Get a list of all patches for all architectures:
    $ find rtai/base/arch/ -name '*.patch' | sort
    The most recent patches for intel and amd 32 and 64-bit systems are in the x86 directory. Decide for a patch, and remember its version number: hal-linux-<kernel-version>-*.patch
    1. Currently, the works, the patch for the 2.6.29 kernel is broken.
    2. Download a 'vanilla' kernel, e.g. linux-<kernel-version>.tar.gz from to /usr/src
    3. Unpack the kernel
      $ tar xzvf linux-
      $ mv /usr/src/linux- /usr/src/linux-
      $ ln -s /usr/src/linux- linux
      Currently, for compiling the DynClamp plugin RELACS assumes that /usr/src/linux points to your rtai patched kernel.
  4. Patch the kernel
    $ cd /usr/src/linux
    $ patch -p1 < /usr/local/src/rtai/base/arch/x86/patches/hal-linux-
  5. Configure, compile, and install the kernel. Follow the intructions given in Linux kernel, starting at step 2. In the kernel configuration dialog you should do the following settings: On Debian, the make-kpkg command should be
    make-kpkg --initrd --append-to-version -rtai --revision r1 --config menuconfig kernel-image
  6. Reboot into your new RTAI real time kernel.

RTAI modules

  1. Make sure that you are really running your RTAI kernel! You can check with
    $ uname -r
  2. Change to the RTAI directory
    $ cd /usr/local/src/rtai
  3. Configure RTAI by calling
    $ make menuconfig
    Check the following settings: Then exit and save configuration. Watch the output while RTAI is configured for possible warnings and errors. In case this fails, you should check and/or edit the file .rtai_config and run .configure manually.
  4. Compile and install (as root)
    $ make && make install
    In case you get an error like "../../../base/include/asm/rtai_leds.h:24:20: error: asm/io.h: No such file or directory" then delete the "#include <asm/io.h>" line in the specified file and call make again.
  5. Make the RTAI kernel modules known to modprobe:
    $ ln -s /usr/realtime/modules /lib/modules/`uname -r`/rtai
    $ depmod -a
  6. Test RTAI by loading the rtai_sched module:
    $ modprobe rtai_sched
    If this fails: XXX add lapic to the kernel parameter in the kernel line of the grub menu in /boot/grub/menu.lst .


  1. Follow the instructions above for installing Comedi . For configuring Comedi you should use
    $ ./configure --with-linuxdir=/usr/src/linux --with-rtaidir=/usr/realtime
  2. Check loading the comedi module:
    $ modprobe comedi
    On failure, call
    $ dmesg
    to get more details. If it says "unknown symbol", then you might have forgotten to deselect the "Module versioning support" in the "loadable module support" section of the kernel configuration. Either recompile your kernel with the "Module versioning support" deselected, or
    $ cp /lib/modules/`uname -r`/rtai/Module.symvers /usr/local/src/comedi/comedi
    $ make clean
    $ make && make install
    $ depmod -a
    $ cp /usr/local/src/comedi/comedi/Module.symvers /lib/modules/`uname -r`/comedi
  3. Then follow the instructions above for installing (if not already done, this is independent of the kernel used)


  1. If you haven't compiled RELACS yet, then follow the instructions in the top-level INSTALL file (the final make install is not necessary for testing). Otherwise, cd into the RELACS top-level directory and do
    $ ./configure --with-rtai=/usr/realtime/include
    $ cd plugins/linuxdevices/comedi
    $ make clean
    $ make
  2. Load the dynamic clamp kernel module (as root):
    $ cd plugins/linuxdevices/comedi/module
    $ ./
  3. Run RELACS
    $ cd - # cd back into the top-level directory of RELACS
    $ cd plugins/patchclamp
    $ cp relacs.cfg.dynclamp relacs.cfg
    $ ./relacslocal
  4. Possible problems are:

Set up udev permissions for comedi device files

  1. Login as root.
  2. Create a new group "iocard":
    $ addgroup --system iocard
  3. Add udev rules to the /etc/udev/rules.d directory:
    $ echo 'KERNEL=="comedi*", MODE="0660", GROUP="iocard"' > /etc/udev/rules.d/comedi.rules
  4. Run
    $ udevadm trigger
    to apply your new udev rules
  5. Add users to the "iocard" group:
    $ adduser <username> iocard
    After the next login, <username> is a member of the iocard group and and has sufficient permissions to access the data acquisition boards through comedi.

Resize comedi buffer

To set the comedi internal buffers to 640kB do as root:
$ comedi_config -r /dev/comedi0
$ comedi_config --read-buffer 640 --write-buffer 640 /dev/comedi0 ni_pcimio
Maybe this should go in /etc/rc.local or to some udev postprocessing rule.

Calibrating analog input and output

For software calibrated boards (like NI M-Series boards) do (as root?)
$ comedi_soft_calibrate -f /dev/comedi0
This calibrates all channels for all ranges. A file is written to /usr/var/lib/comedi/calibrations that contains the calibration parameter. The ComediAnalogInput and ComediAnalogOutput plugins read this file.

For calibrating all ranges, references, and channels of hardware calibrated boards (e.g. NI E-Series) do

$ for C in 0 $(seq 16); do
    for A in 0 1 2; do
      for R in 0 $(seq 20); do
        comedi_calibrate -reset -calibrate -f /dev/comedi0 -s 0 -r $R -a $A -c $C;
$ for C in 0 1; do
    for A in 0 1 2; do
      for R in 0 1; do
        comedi_calibrate -reset -calibrate -f /dev/comedi0 -s 1 -r $R -a $A -c $C;


Generated on Tue Mar 22 23:15:45 2011 for Comedi Relacs Plugins by  doxygen 1.5.3