5.3.  Data types and structures

5.3.1. comedi_devinfo
5.3.2. comedi_t
5.3.3. sampl_t
5.3.4. lsampl_t
5.3.5. comedi_trig (deprecated)
5.3.6. comedi_sv_t (deprecated)
5.3.7. comedi_cmd
5.3.8. comedi_insn
5.3.9. comedi_range
5.3.10. comedi_krange
5.3.11. comedi_insnlist
5.3.12. comedi_polynomial_t
5.3.13. comedi_route_pair

This Section explains the data structures that users of the Comedi API are confronted with:

typedef struct comedi_devinfo_struct  comedi_devinfo;
typedef struct comedi_t_struct        comedi_t;
typedef struct sampl_t_struct         sampl_t;
typedef struct lsampl_t_struct        lsampl_t;
typedef struct comedi_sv_t_struct     comedi_sv_t;
typedef struct comedi_cmd_struct      comedi_cmd;
typedef struct comedi_insn_struct     comedi_insn;
typedef struct comedi_range_struct    comedi_range;
typedef struct comedi_krange_struct   comedi_krange;
typedef struct comedi_insnlist_struct comedi_insnlist;
typedef                               comedi_polynomial_t;
typedef                               comedi_route_pair;

The data structures used in the implementation of the Comedi drivers are described in Section 6.2.1.

5.3.1.  comedi_devinfo

The data type comedi_devinfo is used to store information about a device. This structure is usually filled in automatically when the driver is loaded (attached), so programmers need not access this data structure directly.

typedef struct comedi_devinfo_struct comedi_devinfo;

struct comedi_devinfo_struct{
  unsigned int version_code;    // version number of the Comedi code
  unsigned int n_subdevs;       // number of subdevices on this device
  char         driver_name[COMEDI_NAMELEN];
  char         board_name[COMEDI_NAMELEN];
  int          read_subdevice;  // index of subdevice whose buffer is read by read(), etc. on file descriptor from comedi_fileno() (negative means none)
  int          write_subdevice; // index of subdevice whose buffer is written by write(), etc. on file descriptor from comedi_fileno() (negatove means none).
  int          unused[30];

5.3.2.  comedi_t

The data type comedi_t is used to represent an open Comedi device:

typedef struct comedi_t_struct comedi_t;

A valid comedi_t pointer is returned by a successful call to comedi_open, and should be used for subsequent access to the device. It is an opaque type, and pointers to type comedi_t should not be dereferenced by the application.

5.3.3.  sampl_t

typedef unsigned short sampl_t;

The data type sampl_t is one of the generic types used to represent data values in Comedilib. It is used in a few places where a data type shorter than lsampl_t is useful. On most architectures it is a 16-bit, unsigned integer.

Most drivers represent data transferred by read and write functions using sampl_t. Applications should check the subdevice flag SDF_LSAMPL to determine if the subdevice uses sampl_t or lsampl_t.

5.3.4.  lsampl_t

typedef unsigned int lsampl_t;

The data type lsampl_t is the data type typically used to represent data values in Comedilib. On most architectures it is a 32-bit, unsigned integer.

5.3.5.  comedi_trig (deprecated)

typedef struct comedi_trig_struct comedi_trig;

struct comedi_trig_struct{
  unsigned int subdev;   /* subdevice */
  unsigned int mode;  /* mode */
  unsigned int flags;
  unsigned int n_chan;  /* number of channels */
  unsigned int *chanlist;   /* channel/range list */
  sampl_t *data;  /* data list, size depends on subd flags */
  unsigned int n;  /* number of scans */
  unsigned int trigsrc;
  unsigned int trigvar;
  unsigned int trigvar1;
  unsigned int data_len;
  unsigned int unused[3];

The comedi_trig structure is a control structure used by the COMEDI_TRIG ioctl, an older method of communicating instructions to the driver and hardware. Use of comedi_trig is deprecated, and is no longer implemented by the Comedi kernel layer.

5.3.6.  comedi_sv_t (deprecated)

typedef struct comedi_sv_struct comedi_sv_t;

struct comedi_sv_struct{
  comedi_t *dev;
  unsigned int subdevice;
  unsigned int chan;

  /* range policy */
  int range;
  int aref;

  /* number of measurements to average (for ai) */
  int n;

  lsampl_t maxdata;

The comedi_sv_t structure is used by the comedi_sv_… functions to provide a simple method of accurately measuring slowly varying inputs. This relies on the COMEDI_TRIG ioctl and is no longer by the Comedi kernel layer.

5.3.7.  comedi_cmd

typedef struct comedi_cmd_struct comedi_cmd;

struct comedi_cmd_struct{
  unsigned int subdev;
  unsigned int flags;

  unsigned int start_src;
  unsigned int start_arg;

  unsigned int scan_begin_src;
  unsigned int scan_begin_arg;

  unsigned int convert_src;
  unsigned int convert_arg;

  unsigned int scan_end_src;
  unsigned int scan_end_arg;

  unsigned int stop_src;
  unsigned int stop_arg;

  unsigned int *chanlist;
  unsigned int chanlist_len;

  sampl_t *data;
  unsigned int data_len;

More information on using commands can be found in the command section.

5.3.8.  comedi_insn

typedef struct comedi_insn_struct comedi_insn;

struct comedi_insn_struct{
  unsigned int insn;
  unsigned int n;
  unsigned int subdev;
  unsigned int chanspec;
  unsigned int unused[3];

Comedi instructions are described by the comedi_insn structure. Applications send instructions to the driver in order to perform control and measurement operations that are done immediately or synchronously, i.e., the operations complete before program control returns to the application. In particular, instructions cannot describe acquisition that involves timers or external events.

The field insn determines the type of instruction that is sent to the driver. Valid instruction types are:


read values from an input channel


write values to an output channel


read/write values on multiple digital I/O channels


configure a subdevice


read a timestamp, identical to gettimeofday except the seconds and microseconds values are unsigned values of type lsampl_t.


wait a specified number of nanoseconds

The number of samples to read or write, or the size of the configuration structure is specified by the field n, and the buffer for those samples by data. The field subdev is the subdevice index that the instruction is sent to. The field chanspec specifies the channel, range, and analog reference (if applicable).

Instructions can be sent to drivers using comedi_do_insn. Multiple instructions can be sent to drivers in the same system call using comedi_do_insnlist.

5.3.9.  comedi_range

typedef struct comedi_range_struct comedi_range;

struct comedi_range_struct{
  double min;
  double max;
  unsigned int unit;

The comedi_range structure conveys part of the information necessary to translate sample values to physical units, in particular, the endpoints of the range and the physical unit type. The physical unit type is specified by the field unit, which may take the values UNIT_volt for volts, UNIT_mA for milliamps, or UNIT_none for unitless. The endpoints are specified by the fields min and max.

5.3.10.  comedi_krange

typedef struct comedi_krange_struct comedi_krange;

struct comedi_krange_struct{
  int min;
  int max;
  unsigned int flags;

The comedi_krange structure is used to transfer range information between the driver and Comedilib, and should not normally be used by applications. The structure conveys the same information as the comedi_range structure, except the fields min and max are integers, multiplied by a factor of 1000000 compared to the counterparts in comedi_range.

In addition, kcomedilib uses the comedi_krange structure in place of the comedi_range structure.

5.3.11.  comedi_insnlist

typedef struct comedi_insnlist_struct comedi_insnlist;

struct comedi_insnlist_struct{
  unsigned int n_insns;
  comedi_insn *insns;

A comedi_insnlist structure is used to communicate a list of instructions to the driver using the comedi_do_insnlist function.

5.3.12.  comedi_polynomial_t

typedef struct {
  double expansion_origin;
  unsigned order;
} comedi_polynomial_t;

A comedi_polynomial_t holds calibration data for a channel of a subdevice. It is initialized by the comedi_get_hardcal_converter or comedi_get_softcal_converter calibration functions and is passed to the comedi_to_physical and comedi_from_physical raw/physical conversion functions.

5.3.13.  comedi_route_pair

typedef struct {
  unsigned int source;
  unsigned int destination;
} comedi_route_pair;

An array of comedi_route_pair objects is used to gain a list of routes that are valid for a particular device via comedi_get_routes. The values for source and destination are globally identifiable for the entire device as used by comedi_test_route, comedi_connect_route, and comedi_disconnect_route.