Comedi

The Control and Measurement Device Interface handbook for Comedilib 0.11.0

David Schleef

Ian Abbott

Éric Piel

This document is part of Comedilib. In the context of this document, the term "source code" as defined by the license is interpreted as the XML source.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 of the License.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

Abstract

Comedi is a free software project to interface digital acquisition (DAQ) cards. It is the combination of three complementary software items: (i) a generic, device-independent API, (ii) a collection of Linux kernel modules that implement this API for a wide range of cards, and (iii) a Linux user space library with a developer-oriented programming interface to configure and use the cards.


Table of Contents

1. Overview
1.1. What is a device driver?
1.2. Policy vs. mechanism
1.3. A general DAQ device driver package
1.4. DAQ signals
1.5. Device hierarchy
1.6. Acquisition terminology
1.7. DAQ functions
1.8. Supporting functionality
2. Configuration
2.1. Configuration
2.2. Getting information about a card
3. Writing Comedi programs
3.1. Your first Comedi program
3.2. Converting between integer data and physical units
3.3. Your second Comedi program
3.4. Asynchronous acquisition
3.5. Further examples
4. Acquisition and configuration functions
4.1. Functions for single acquisition
4.2. Instructions for multiple acquisitions
4.3. Instructions for configuration
4.4. Instruction for internal triggering
4.5. Commands for streaming acquisition
4.6. Slowly-varying inputs
4.7. Experimental functionality
5. Comedi reference
5.1. Headerfiles: comedi.h and comedilib.h
5.2. Constants and macros
5.3. Data types and structures
5.4. Functions
5.5. Language bindings
5.6. Kernel drivers
6. Writing a Comedi driver
6.1. Communication user-space — kernel-space
6.2. Generic functionality
6.3. Board-specific functionality
6.4. Callbacks, events and interrupts
6.5. Device driver caveats
6.6. Integrating the driver in the Comedi library
Glossary

1. Overview

Comedi is a free software project that develops drivers, tools, and libraries for various forms of data acquisition: reading and writing of analog signals; reading and writing of digital inputs/outputs; pulse and frequency counting; pulse generation; reading encoders; etc. The source code is distributed in two main packages, comedi and comedilib:

  • Comedi is a collection of drivers for a variety of common data acquisition plug-in boards (which are called devices in Comedi terminology). The drivers are implemented as the combination of (i) one single core Linux kernel module (called comedi) providing common functionality, and (ii) individual low-level driver modules for each device.

  • Comedilib is a separately distributed package containing a user-space library that provides a developer-friendly interface to the Comedi devices. Included in the Comedilib package are documentation, configuration and calibration utilities, and demonstration programs.

  • Kcomedilib is a Linux kernel module (distributed with the comedi package) that provides the same interface as comedilib in kernel space, and suitable for use by real-time kernel modules. It is effectively a kernel library for using Comedi from real-time tasks.

Comedi works with standard Linux kernels, but also with its real-time extensions RTAI and RTLinux/GPL.

This section gives a high-level introduction to which functionality you can expect from the software. More technical details and programming examples are given in the following sections of this document.

1.1.  What is a device driver?

A device driver is a piece of software that interfaces a particular piece of hardware: a printer, a sound card, a motor drive, etc. It translates the primitive, device-dependent commands with which the hardware manufacturer allows you to configure, read and write the electronics of the hardware interface into more abstract and generic function calls and data structures for the application programmer.

David Schleef started the Comedi project to put a generic interface on top of lots of different cards for measurement and control purposes. This type of cards are often called data acquisition (or DAQ) cards.

Analog input and output cards were the first goal of the project, but now Comedi also provides a device independent interface to digital input and output cards, and counter and timer cards (including encoders, pulse generators, frequency and pulse timers, etc.).

Schleef designed a structure which is a balance between modularity and complexity: it's fairly easy to integrate a new card because most of the infrastructure part of other, similar drivers can be reused, and learning the generic and hence somewhat heavier