Comedi Relacs Plugins 0.9.8
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 http://www.comedi.org

Content

Introduction

If you only need normal ("streaming", asynchronous) data acquisition as it is implemented by the ComediAnalogInput and ComediAnalogOutput plugins, then follow the instructions in Install comedi.

If you want to use dynamic clamp, i.e. some realtime computation, as it is implemented by the DynClampAnalogInput and DynClampAnalogOutput plugins, then you need to install a real-time linux kernel first, as described in Install RTAI and Comedi.

Install comedi

On recent linux distributions comedi modules are already in the Linux kernel. You only need to install the comedilib library

sudo apt-get install libcomedi-dev 

and to set the permissions as described in Setting up udev permissions for Comedi device files. If your data acquisition board needs to be calibrated, you also need to install comedi_calibrate. This seems not to be available as a package, so you have to compile it yourself. See Comedi_calibrate for details.

If this does not work (some older versions did not provide some functions needed by the RELACS comedi plugins), or if you require the most recent version of comedi, you should reinstall the comedi drivers and the comedi library from scratch as described in the following sections.

You should install the comedi drivers and library prior to configuring RELACS, so that ./configure can detect the presence of the comedi library. If you install comedi later, simply run ./configure and make again to detect comedi and compile the corresponding plugins for RELACS.

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 and header files matching your running kernel image by executing as root
    $ cd /usr/src
    $ apt-get install dpkg-dev
    $ apt-get source linux-image-`uname -r`
    $ apt-get install linux-headers-`uname -r`
    
    If apt-get source tells you "E: You must put some 'source' URIs in your sources.list" then you need to enable the source repositories for the package manager. For this open with your favorite editor /etc/apt/sources.list and the *.list files in /etc/apt/sources.list.d/. Remove the comments in front of the lines that start with "deb-src". Then run
    $ apt-get update 
    
    to resynchronize the package index files with the new repositories. Now apt-get source should be able to download the kernel sources. After downloading the kernel source create a link to the kernel source:
    ln -s linux <kernel-source> 
    
    where <kernel-source> is the kernel source installed by apt-get. Note that often the kernel source directory that you installed with apt-get has a different name than the name of the currently running kernel that uname -r returns. Use ls -rtl to list the directories in the /usr/src folder. The last one is the one that was added by apt-get source. Now you can cd into the kernel source directory
    $ cd linux
    
  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. Get a vanilla kernel from http://www.kernel.org, e.g. http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.8.tar.bz2, place the tar file in /usr/src and unpack it as root with
    $ cd /usr/src
    $ tar xjvf linux-2.6.38.8.tar.bz2
    
    (replace linux-2.6.38.8 by the directory name of your new kernel source). Create a softlink to your kernel source
    $ ln -s linux-2.6.38.8 linux
    $ cd linux
    
    and make sure the make, gcc, libncurses-dev, and zlib1g-dev packages are installed:
    $ apt-get install make gcc libncurses-dev zlib1g-dev
    
  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:
    • Processor type and features:
      • Select your Subarchitecture Type (PC-Compatible) - this option does not exist for newer kernels
      • Select the right Processor family (you find the name of your processor by looking at /proc/cpuinfo, check "help" to find out, which Processor family you have to select)
      • Select "Preemption Model (Preemptible kernel (Low-Latency Desktop))"
    Leave the configuration dialog by pressing "Exit" until you are asked "Save kernel config?". Select "Yes".
  4. Then compile and install (as root) 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-2.6.38.8 file already:
    $ cd /boot
    $ update-initramfs -c -k 2.6.38.8
    
  6. Check the grub menu whether your new kernel was added.
    • With grub v2 (default since Debian Lenny) simply run
      $ update-grub
      
      the output of update-grub should mention your new kernel image. You can configure grub v2 by editing the file /etc/default/grub . To get the boot menu that you need to select the kernel you want to boot you should for example unset the GRUB_HIDDEN_TIMEOUT and set the GRUB_TIMEOUT appropriately in that file. For example:
      #GRUB_HIDDEN_TIMEOUT=0
      #GRUB_HIDDEN_TIMEOUT_QUIET=true
      GRUB_TIMEOUT=10
      
      Also, if ou do not like that grub puts your rtai kernel into a subsection called 'Previous linux versions', then comment out the following lines in /etc/grub.d/10_linux
      #  if [ "$list" ] && ! $in_submenu; then
      #    echo "submenu \"Previous Linux versions\" {"
      #    in_submenu=:
      #  fi
      
      After editing run update-grub to apply the changes.
    • 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 2.6.28.9
      root            (hd0,0)
      kernel          /boot/vmlinuz-2.6.28.9 root=/dev/sda1 ro quiet
      initrd          /boot/initrd.img-2.6.28.9
      
  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 http://www.nvidia.com/Download/index.aspx?lang=en-us. Install it by calling
    $ sh NVIDIA-Linux-x86_64-190.42-pkg2.run
    
    If you want to install the nvidia driver for a second kernel, then call
    $ sh NVIDIA-Linux-x86_64-190.42-pkg2.run -k 2.6.28.9-rtai -K
    
    (replace 2.6.28.9-rtai 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. See http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Debian_Lenny_Compile_RTAI for more details. Do as root:
    1. Get the kernel-package
      $ apt-get install kernel-package libncurses-dev
      
    2. Configure and build the kernel:
      $ export CONCURRENCY_LEVEL=2  # set here the number of CPUs you have to speed things up!
      $ make-kpkg clean
      $ make-kpkg --initrd --revision 1.0 --config menuconfig kernel-image kernel-headers kernel-source
      
      You can also supply a -j option to tell make how many processes can be run in parallel. See step 3. for hints on the configuration options.
    3. Install the kernel
      $ cd ..
      $ dpkg -i linux-image-2.6.38.8_1.0_amd64.deb linux-headers-2.6.38.8_1.0_amd64.deb
      
    4. continue with step 6.

Comedi

Kernel versions 2.6.30 onwards have an experimental in-tree Comedi implementation in the driver "staging" area. You can check whether it works for you by following the instructions of point 11 below. However, we recommend installing a current version of the comedi drivers.

Here are all commands that you can throw into a shell to completely install comedi:

# install all required packages:
apt-get -y install gcc g++ git autoconf automake libtool bison flex libgsl0-dev libboost-program-options-dev

# download comedi sources:
cd /usr/local/src
git clone git://comedi.org/git/comedi/comedi.git
git clone git://comedi.org/git/comedi/comedilib.git
git clone git://comedi.org/git/comedi/comedi_calibrate.git
rm -r /lib/modules/`uname -r`/kernel/drivers/staging/comedi

# comedi:
cd /usr/local/src/comedi
./autogen.sh
./configure
make && make install
depmod -a
cp include/linux/comedi.h /usr/include/linux/
cp include/linux/comedilib.h /usr/include/linux/

# comedilib:
cd /usr/local/src/comedilib
./autogen.sh
./configure --prefix=/usr --sysconfdir=/etc
make && make install

# comedi_calibrate:
cd /usr/local/src/comedi_calibrate
autoreconf -v -i
./configure --prefix=/usr --sysconfdir=/etc
make && make install

# setup udev permissions:
addgroup --system iocard
echo 'KERNEL=="comedi*", MODE="0660", GROUP="iocard"' > /etc/udev/rules.d/95-comedi.rules
udevadm trigger
adduser $USER iocard

In the following the necessary steps are described in detail:

  1. Download the current Comedi sources from the Git repository to /usr/local/src as root.
    $ apt-get install git
    $ cd /usr/local/src
    $ git clone git://comedi.org/git/comedi/comedi.git
    $ git clone git://comedi.org/git/comedi/comedilib.git
    $ git clone git://comedi.org/git/comedi/comedi_calibrate.git
    
    Or download the current Git snapshots from http://www.comedi.org/download.html to /usr/local/src and unpack them
    $ cd /usr/local/src
    $ tar xzvf comedi-HEAD-*.tar.gz
    $ tar xzvf comedilib-HEAD-*.tar.gz
    $ tar xzvf comedi_calibrate-HEAD-*.tar.gz
    
  2. You may need to install the packages: autoconf, libtool.
    $ apt-get install autoconf automake libtool
    
  3. Make sure that you are really running the kernel for which you want to install Comedi! You can check with
    $ uname -r
    
  4. Remove the Comedi staging modules to avoid conflicts:
    $ rm -r /lib/modules/`uname -r`/kernel/drivers/staging/comedi
    
  5. Change to the comedi directory:
    $ cd /usr/local/src/comedi
    
  6. Generate the configuration script by calling
    $ ./autogen.sh
    
    You may ignore warnings and reminders.
  7. Configure simply by calling
    ./configure
    
    in case you want to install Comedi into your currently running kernel. If /usr/src/linux is not your running kernel, then call
    $ ./configure --with-linuxsrcdir=/usr/src/linux
    
    with /usr/src/linux replaced by the path to the sources of the kernel for which you want to install Comedi.
  8. Compile
    $ make
    
    and install (as root)
    $ make install
    $ depmod -a
    
  9. 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/
    
  10. 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.
  11. 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_board_info /dev/comedi0
    
    (or comedi_test -t info -f /dev/comedi0) to see more details about your data acquisition board (note: both comedi_board_info and comedi_test are 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. For this you also need to tell comedi to create a /dev/comedi0 device file for you. Add the following line to /etc/modprobe.conf or /etc/modprobe.d/comedi.conf (the latter you have to create if the directory /etc/modprobe.d exists):
    options comedi comedi_num_legacy_minors=4
    
    See also http://www.comedi.org/doc/install.html#cardconfiguration .

Comedilib

  1. You may need to install the packages: autoconf, libtool, bison, flex.
    $ apt-get install bison flex
    
  2. Change to the comedilib directory as root:
    $ cd /usr/local/src/comedilib
    
  3. Generate the configuration script by calling
    $ ./autogen.sh
    
    You may ignore warnings and reminders.
  4. 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.
  5. Compile and install (as root)
    $ make && make install
    
  6. In case make fails with this error message:
    libtool: link: gcc -std=gnu99 -I../include -I../include -Wall -g -O2 -o .libs/comedi_test comedi_test-bufconfig.o comedi_test-cmd_1.o comedi_test-cmd_2.o comedi_test-cmd_3.o comedi_test-info.o comedi_test-insn_read.o comedi_test-insn_read_time.o comedi_test-inttrig.o comedi_test-lib.o comedi_test-main.o comedi_test-mmap.o comedi_test-mode0_read.o comedi_test-select.o  ../lib/.libs/libcomedi.so -lm
    ../lib/.libs/libcomedi.so: undefined reference to `nearbyint'
    ../lib/.libs/libcomedi.so: undefined reference to `floor'
    collect2: error: ld returned 1 exit status
    make[2]: *** [comedi_test] Error 1
    make[2]: Leaving directory `/usr/local/src/comedilib/testing'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/usr/local/src/comedilib'
    make: *** [all] Error 2
    
    then add the following line
    libcomedi_la_LIBADD = -lm
    
    to lib/Makefile.am after the line libcomedi_la_LDFLAGS. Then run
    $ make clean
    $ ./autogen.sh
    $ ./configure --prefix=/usr --sysconfdir=/etc
    $ make && make install
    

Comedi_calibrate

  1. You may need to install the packages: autoconf, libtool, libgsl0-dev, libboost-program-options-dev.
    $ apt-get install libgsl0-dev libboost-program-options-dev
    
  2. Change to the comedi_calibrate directory as root:
    $ cd /usr/local/src/comedi_calibrate
    
  3. Generate the configuration script by calling
    $ autoreconf -v -i
    
    You may ignore warnings and reminders.
  4. Configure
    $ ./configure --prefix=/usr --sysconfdir=/etc
    
  5. Compile and install (as root)
    $ make && make install
    

Install RTAI and Comedi

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

Note:
(June 2013) There is a problem regarding newer versions of clib (version >= 2.15, version 2.13 works, check version with ldd --version). The rtai_math module does not compile correctly with the newer libc version. I have not figured out a nice solution to this bug other than to use a not so new linux distro.... Working is linux Mint upto version 12 (Lisa), Ubuntu Oneiric, Debian Linux 7.0. Find out your distro with cat /etc/issue or lsb_release -a.

Linux kernel and RTAI patch

  1. Download the latest RTAI (http://www.rtai.org) version (the following instructions where tested successfully with version 3.9) from the RTAI repository at http://www.rtai.org/RTAI and put it into /usr/local/src as root. Alternatively you could try to clone the source from https://github.com/ShabbyX/RTAI. This version fixed quite some autotools issues and is working hard on getting the rtai_math module back. Unfortunately, this also failed so far (February 2014, Linux Mint 16 Petra, kernel 3.8.13)
  2. Unpack RTAI in /usr/local/src:
    $ cd /usr/local/src
    $ tar xjvf rtai-3.9.tar.bz2
    $ ln -s rtai-3.9 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. I got the 2.6.38.8 to work.
    2. Too old (usually not so old) kernels do not compile with the curent version of the gcc compiler.
    3. Download a 'vanilla' kernel, e.g. linux-<kernel-version>.tar.gz from http://www.kernel.org (e.g. http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.38.8.tar.bz2) to /usr/src
    4. Unpack the kernel
      $ cd /usr/src
      $ tar xjvf linux-2.6.38.8.tar.bz2
      $ mv linux-2.6.38.8 linux-2.6.38.8-rtai
      $ ln -s linux-2.6.38.8-rtai linux
      
      Currently, for compiling the DynClamp plugin RELACS assumes that /usr/src/linux points to your rtai patched kernel.
  4. Patch the kernel (use the patch file that matches the downloaded kernel)
    $ cd /usr/src/linux
    $ patch -p1 < /usr/local/src/rtai/base/arch/x86/patches/hal-linux-2.6.38.8-x86-2.11-02.patch
    
  5. Configure, compile, and install the kernel.
    Note:
    In newer gcc and kernels there is a problem with some compiler flag when compiling the RTAI math module. Disable (comment them out using '#') in /usr/src/linux/arch/x86/Makefile all lines with -mpreferred-stack-boundary=3 before configuring and compiling the kernel.
    Follow the intructions given in Compile your own kernel, starting at step 2. On Debian, the make-kpkg command should be
    $ make-kpkg --initrd --append-to-version -rtai --revision 1.0 --config menuconfig kernel-image kernel-headers kernel-source
    
    In the kernel configuration dialog you should do the following settings:
    • General setup: set "Local version" to -rtai (not needed if you are using make-kpkg)
    • Enable loadable module support:
      • Select "Enable module support"
      • Deselect "Module versioning support"
    • Processor type and features:
      • Disable "Tickless System"
      • Select your "Subarchitecture Type" (PC-Compatible) - this option does not exist for newer kernels
      • Select the right Processor family (you find the name of your processor by looking at /proc/cpuinfo, check "help" to find out, which Processor family you have to select)
      • Select "Preemption Model (Preemptible kernel (Low-Latency Desktop))"
      • Disable “Use register arguments” - this option does not exist for newer kernels (version <= 2.6.19)
      • Select "Interrupt pipeline"
      • Set "Timer frequency" to 1000 Hz
    • Power management and ACPI options:
      • Disable "CPU Frequency scaling"
  6. Reboot into your new RTAI real time kernel. If this fails: Try adding one or several of the advanced configuration and power interface (ACPI) or advanced programmable interrupt controller (APIC) options, acpi=off pci=noacpi noapic nolapic lapic , to the kernel parameter in the kernel line of the grub menu in /boot/grub/menu.lst (grub v1) or to the GRUB_CMDLINE_LINUX variable in /etc/defaults/grub . After restart, check for the number of CPUs in /proc/cpuinfo - they might be reduced by these parameters!

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. In case you downloaded RTAI from https://github.com/ShabbyX/RTAI, you need to generate configure script and makefiles first:
    $ ./autogen.sh
    
    (do not call ./autogen.sh when using the original RTAI sources since it might fail).
  4. Configure RTAI by calling as root
    $ make menuconfig
    
    Check the following settings:
    • General
      • Installation directory: should be set to /usr/realtime
      • Linux source tree: must be set to /usr/src/linux
      • RTAI Documentation: deselect all documentation (if you don't you might get an error)
      • Build RTAI testsuite: select
    • Machine
      • Number of CPUs: set to the right value. The default is not always right. If in doubt, look into the file /proc/cpuinfo .
      • Enable FPU support: select
    • Base system
      • Other features
        • Mathfuns support in kernel: select
        • C99 standard support: select
    • Add-ons
      • Real Time COMEDI support in user space: leave unselected
    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.
  5. Compile and install (as root)
    $ make && make install
    
    Known issues:
    • In case you get an error like "/usr/include/features.h:323:26: fatal error: bits/predefs.h: No such file or directory" install the gcc-multilib package
      $ apt-get install gcc-multilib
      
    • 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.
    • If you get error messages like "../../../base/sched/liblxrt/.libs/liblxrt.so: undefined reference to `pthread_create'", i.e. undefined references to various pthread functions, then open base/sched/liblxrt/GNUmakefile in you favourite editor, find the line containing 'liblxrt_la_LIBADD' and add "-lpthread" to it so that this line looks like
      liblxrt_la_LIBADD = -lpthread
      
      Then
      $ cd base/sched/liblxrt
      $ make clean
      $ cd -
      $ make
      
  6. Make the RTAI kernel modules known to modprobe:
    $ ln -s /usr/realtime/modules /lib/modules/`uname -r`/rtai
    $ depmod -a
    
  7. Test RTAI by loading the rtai_sched module:
    $ modprobe rtai_sched
    
    If this fails: Try adding one or several of the advanced configuration and power interface (ACPI) or advanced programmable interrupt controller (APIC) options, acpi=off pci=noacpi noapic nolapic lapic , to the kernel parameter in the kernel line of the grub menu in /boot/grub/menu.lst (grub v1) or to the GRUB_CMDLINE_LINUX variable in /etc/defaults/grub . Recompile and install RTAI (make clean && make && make install && depmod -a). After restart, check for the number of CPUs in /proc/cpuinfo - they might be reduced by these parameters!
  8. If you have a multi-core system you should reserve at least one CPU for RTAI. You can isolate CPUs by using the kernel parameter
    isolcpus=0,1,2
    
    (for isolating the cores no. 0, 1, and 2) and by loading the rtai_hal kernel module the following way:
    insmod rtai_hal.ko IsolCpusMask=0x07
    
    See the file /usr/local/src/rtai/README.ISOLCPUS for more details.
  9. Run the RTAI latency test
    $ cd /usr/realtime/testsuite/kern/latency
    $ run
    

Comedi

For an RTAI kernel you definitely have to install the Comedi drivers yourself according to the following instructions:

  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)

Test RELACS

  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 (you do not have to be root for this, except for loading the kernel modules in point 2)
    $ ./configure
    $ cd plugins/linuxdevices/comedi
    $ make clean
    $ make
    
  2. Load the dynamic clamp kernel module (as root):
    $ cd plugins/linuxdevices/comedi/module
    $ ./loadmodules.sh
    
  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:
    • Data acquisition does not start:
      • You might not have sufficient permissions for reading and writing to the /dev/comedi* devices. For a quick fix do as root
        $ chmod a+rw /dev/comedi*
        
        See Setting up udev permissions for Comedi device files below for a better solution.
      • The comedi and rtai modules are not properly loaded.
      • The comedi device is not configured yet.
    • Performance is bad / RELACS regularly hangs for a few seconds / RELACS seems to be slowed down dramatically.
      • Disable APM and ACPI by adding "apm=off" and acpi=off to the kernel parameter in the kernel line of the grub menu in /boot/grub/menu.lst .

Setting up udev permissions for Comedi device files

Once comedi is installed you also need to make sure that you (the user) have appropriate permissions for accessing the comedi device files. That is you need to be able to have read and write access to the /dev/comedi* files. One elegant way to achieve this to create a new group and tell udev to add the comedi device files to this group.

  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/95-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 calibrating analog input and output you should run comedi_calibrate once in a while. comedi_calibrate writes a file to /usr/var/lib/comedi/calibrations that contains the calibration parameter. The ComediAnalogInput and ComediAnalogOutput plugins read this file and apply the calibration.

For hardware calibrated boards (like NI E-Series boards) do

$ comedi_calibrate --reset --calibrate -f /dev/comedi0

For software calibrated boards (like NI M-Series boards) do

$ comedi_soft_calibrate -f /dev/comedi0

You may want to read the man page of comedi_calibrate.

Setting up dynamic clamp for RELACS

  1. cd into the RELACS top-level directory and run
    $ ./configure
    
    This should detect RTAI (see message towards the end of the output of configure).
  2. Then compile the dynamic clamp plugins and the kernel module:
    $ cd plugins/linuxdevices/comedi
    $ make clean
    $ make
    
  3. Load the dynamic-clamp kernel module (as root):
    $ cd plugins/linuxdevices/comedi/module
    $ ./loadmodules.sh
    
  4. If you want to load the dynamic-clamp kernel module automatically during the boot process, then call the loadmodules.sh script from the script /etc/rc.local . Simply add a line like this
    /where/ever/the/script/is/located/loadmodules.sh
    
    to /etc/rc.local.

Kernel messages

When fiddling around with kernel modules you might want to have a look at the kernel messages in /var/log/messages:

$ tail -f /var/log/messages

alternatively use

$ less /var/log/messages

and hit 'F'. Both commands will then show what was added to the messages immediately. Interrupt this by hitting ctrl-c.

In case you do not have a /var/log/messages file (unfortunately the default in modern ubuntu based systems), you have to enable it. As root open the file /etc/rsyslog.d/50-default.conf in an editor. Remove the hash marks in front of the following lines:

*.=info;*.=notice;*.=warn;\
        auth,authpriv.none;\
        cron,daemon.none;\
        mail,news.none          -/var/log/messages

The tell the system that you changed this file (still as root):

$ restart rsyslog 

Links