2004-01-17 16:33:09 +00:00
|
|
|
######################################################################
|
|
|
|
#
|
|
|
|
# $Source$
|
|
|
|
#
|
|
|
|
# $Revision$
|
|
|
|
# $Date$
|
|
|
|
#
|
|
|
|
# $Author$
|
|
|
|
#
|
|
|
|
# Copyright (C) 2003,2004 James Steven Jenkins
|
|
|
|
#
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
# This file is syntactic sugar for accessing the Ruby comedilib
|
|
|
|
# extension library generated by SWIG. The syntactic sugar is in
|
2004-03-29 01:39:36 +00:00
|
|
|
# several forms:
|
2004-01-17 16:33:09 +00:00
|
|
|
#
|
|
|
|
# (1) Method names without the 'comedi_' prefix. The Comedi module
|
|
|
|
# disambiguates the namespace.
|
|
|
|
#
|
|
|
|
# (2) Instance methods that take an explicit receiver instead of
|
|
|
|
# passing the target object as an initial pointer. For example:
|
|
|
|
# comedi_close(dev) can be written as dev.close.
|
|
|
|
#
|
|
|
|
# (3) A pre-defined IO object and an accessor method to simplify
|
|
|
|
# reading from the file descriptor associated with the comedi device.
|
|
|
|
# Data from comedi device dev can be accessed with dev.ios.read.
|
2004-03-06 22:13:37 +00:00
|
|
|
#
|
|
|
|
# (4) A ComediError exception class. If the underlying comedi
|
|
|
|
# function returns an error indication, the ruby method will raise
|
2004-03-29 01:39:36 +00:00
|
|
|
# ComediError. If the comedi function returns both a status and a
|
|
|
|
# value (e.g., comedi_data_read), the status is not returned by the
|
|
|
|
# ruby method unless it carries information in addition to indication
|
|
|
|
# of failure (e.g., comedi_command_test).
|
|
|
|
#
|
|
|
|
# (5) Ruby booleans. Comedi functions that return C integer boolean values
|
|
|
|
# (comedi_range_is_chan_specific, comedi_maxdata_is_chan_specific) have
|
|
|
|
# corresponding boolean ruby methods with '?' appended to the method name.
|
2004-01-17 16:33:09 +00:00
|
|
|
|
|
|
|
require 'comedi.so'
|
|
|
|
|
|
|
|
include Comedi
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct is returned by Comedi::open
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
class SWIG::TYPE_p_comedi_t_struct
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# create an IO object to access the comedi_t_struct fileno
|
2004-01-17 16:33:09 +00:00
|
|
|
|
|
|
|
def ios
|
2004-03-06 22:13:37 +00:00
|
|
|
def self.ios
|
|
|
|
@ios
|
|
|
|
end
|
|
|
|
@ios = IO.new(fileno, 'r')
|
2004-01-17 16:33:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-03-06 22:13:37 +00:00
|
|
|
# ComediError is raised by methods whose underlying comedi functions return
|
|
|
|
# indication of an error.
|
|
|
|
|
|
|
|
class ComediError < SystemCallError
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@comedi_errno = Comedi::errno
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :comedi_errno
|
2004-01-17 16:33:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module Comedi
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2004-03-06 22:13:37 +00:00
|
|
|
# wrap_method is the basis for wrap_module_method and
|
|
|
|
# wrap_instance_method.
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
def wrap_method(mod, name, err, multi, arglist)
|
|
|
|
|
|
|
|
cname = name
|
|
|
|
ret = 'value'
|
|
|
|
status = 'value'
|
|
|
|
value = 'value'
|
|
|
|
|
|
|
|
# If name ends in '?', make ruby wrapper a boolean.
|
|
|
|
|
|
|
|
if bool = (name =~ /\?$/)
|
|
|
|
value = 'ret == 1'
|
|
|
|
cname = name.sub(/\?$/, '')
|
|
|
|
elsif multi == :simple
|
|
|
|
ret = 'status, value'
|
|
|
|
status = 'status'
|
|
|
|
value = 'value'
|
|
|
|
elsif multi == :compound
|
|
|
|
ret = 'status, value'
|
|
|
|
status = 'status'
|
|
|
|
value = 'status, value'
|
|
|
|
end
|
|
|
|
|
|
|
|
wrap_def = %Q{# Module: #{mod}\n\n}
|
|
|
|
wrap_def << %Q{def #{name}(*args)\n}
|
|
|
|
wrap_def << %Q{ #{ret} = comedi_#{cname}(#{arglist})\n}
|
|
|
|
|
|
|
|
# Raise exceptions if required.
|
|
|
|
|
2004-03-06 22:13:37 +00:00
|
|
|
unless err == :none
|
2004-03-29 01:39:36 +00:00
|
|
|
wrap_def << %Q{ raise ComediError.new if }
|
2004-03-06 22:13:37 +00:00
|
|
|
case err
|
|
|
|
when :neg
|
2004-03-29 01:39:36 +00:00
|
|
|
wrap_def << %Q{#{status} < 0\n}
|
2004-03-06 22:13:37 +00:00
|
|
|
when nil
|
2004-03-29 01:39:36 +00:00
|
|
|
wrap_def << %Q{#{status}.nil?\n}
|
2004-03-06 22:13:37 +00:00
|
|
|
else
|
2004-03-29 01:39:36 +00:00
|
|
|
wrap_def << %Q{#{status} == #{err}\n}
|
2004-03-06 22:13:37 +00:00
|
|
|
end
|
|
|
|
end
|
2004-03-29 01:39:36 +00:00
|
|
|
|
|
|
|
# Return value.
|
|
|
|
|
|
|
|
wrap_def << %Q{ return #{value}\n}
|
|
|
|
wrap_def << %Q{end\n\n}
|
|
|
|
|
|
|
|
# Execute definition.
|
|
|
|
|
|
|
|
puts wrap_def if __FILE__ == 'comedi.rb'
|
2004-03-06 22:13:37 +00:00
|
|
|
mod.module_eval wrap_def
|
|
|
|
end
|
|
|
|
|
|
|
|
# wrap_module_method defines Comedi module methods without the
|
|
|
|
# unnecessary comedi_ prefix. The wrapped method raises
|
|
|
|
# ComediError if the return value equals a specified value.
|
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
def wrap_module_method(mod, name, err, multi)
|
|
|
|
wrap_method(mod, name, err, multi, '*args')
|
2004-01-17 16:33:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# wrap_instance_method defines instance methods for any of several
|
|
|
|
# classes. It removes the comedi_ prefix and allows use of an
|
2004-03-06 22:13:37 +00:00
|
|
|
# explicit receiver. The wrapped method raises ComediError
|
|
|
|
# if the return value equals a specified value.
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
def wrap_instance_method(mod, name, err, multi)
|
|
|
|
wrap_method(mod, name, err, multi, 'self, *args')
|
2004-01-17 16:33:09 +00:00
|
|
|
end
|
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
# This struct holds information for methods with return class,
|
|
|
|
# error, and multi-return indication.
|
|
|
|
|
|
|
|
Method_group = Struct.new(:class, :err, :multi, :names)
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
# Define method groups.
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
module_methods = [
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-06 22:13:37 +00:00
|
|
|
# Comedi module methods that return nil on error.
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
Method_group.new(Comedi, nil, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
open
|
|
|
|
parse_calibration_file
|
|
|
|
}),
|
2004-01-17 16:33:09 +00:00
|
|
|
|
2004-03-06 22:13:37 +00:00
|
|
|
# Comedi module methods that do not indicate errors.
|
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
Method_group.new(Comedi, :none, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
loglevel
|
|
|
|
perror
|
|
|
|
strerrno
|
|
|
|
errno
|
|
|
|
to_phys
|
|
|
|
from_phys
|
|
|
|
set_global_oor_behavior
|
2016-05-12 19:35:40 +01:00
|
|
|
to_physical
|
|
|
|
from_physical
|
2004-03-06 22:13:37 +00:00
|
|
|
}),
|
2004-03-29 01:39:36 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
instance_methods = [
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that return -1 on error.
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, -1, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
close
|
|
|
|
fileno
|
|
|
|
get_subdevice_type
|
|
|
|
find_subdevice_by_type
|
|
|
|
get_read_subdevice
|
|
|
|
get_write_device
|
|
|
|
get_subdevice_flags
|
|
|
|
get_n_channels
|
2004-03-29 01:39:36 +00:00
|
|
|
range_is_chan_specific?
|
|
|
|
maxdata_is_chan_specific?
|
2004-03-06 22:13:37 +00:00
|
|
|
get_n_ranges
|
|
|
|
find_range
|
|
|
|
get_buffer_size
|
|
|
|
get_max_buffer_size
|
|
|
|
set_buffer_size
|
|
|
|
trigger
|
|
|
|
do_insnlist
|
|
|
|
do_insn
|
|
|
|
lock
|
|
|
|
unlock
|
2004-03-29 01:39:36 +00:00
|
|
|
data_read_hint
|
2004-03-06 22:13:37 +00:00
|
|
|
data_write
|
2007-10-15 00:02:49 +00:00
|
|
|
dio_get_config
|
2004-03-06 22:13:37 +00:00
|
|
|
dio_config
|
|
|
|
dio_write
|
|
|
|
cancel
|
|
|
|
command
|
|
|
|
poll
|
|
|
|
set_max_buffer_size
|
|
|
|
get_buffer_contents
|
|
|
|
mark_buffer_read
|
2016-05-12 19:35:40 +01:00
|
|
|
mark_buffer_written
|
2004-03-06 22:13:37 +00:00
|
|
|
get_buffer_offset
|
2016-05-13 15:14:47 +01:00
|
|
|
get_buffer_read_offset
|
|
|
|
get_buffer_write_offset
|
2007-10-15 00:02:49 +00:00
|
|
|
get_softcal_converter
|
|
|
|
get_hardcal_converter
|
2016-05-12 19:35:40 +01:00
|
|
|
internal_trigger
|
|
|
|
arm
|
|
|
|
arm_channel
|
|
|
|
disarm
|
|
|
|
disarm_channel
|
|
|
|
reset
|
|
|
|
reset_channel
|
|
|
|
set_counter_mode
|
|
|
|
set_clock_source
|
|
|
|
set_filter
|
|
|
|
set_gate_source
|
|
|
|
set_other_source
|
|
|
|
set_routing
|
|
|
|
get_hardware_buffer_size
|
|
|
|
digital_trigger_disable
|
|
|
|
digital_trigger_enable_edges
|
|
|
|
digital_trigger_enable_levels
|
|
|
|
set_read_subdevice
|
|
|
|
set_write_subdevice
|
2004-03-06 22:13:37 +00:00
|
|
|
}),
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that return status and a
|
2004-03-29 01:39:36 +00:00
|
|
|
# value. Status is -1 on error. Status is discarded.
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, -1, :simple, %w{
|
2004-03-29 01:39:36 +00:00
|
|
|
data_read
|
|
|
|
data_read_delayed
|
|
|
|
dio_read
|
2016-05-12 19:35:40 +01:00
|
|
|
dio_bitfield
|
2007-10-15 00:02:49 +00:00
|
|
|
dio_bitfield2
|
2004-03-29 01:39:36 +00:00
|
|
|
get_cmd_src_mask
|
|
|
|
get_cmd_generic_timed
|
2016-05-12 19:35:40 +01:00
|
|
|
get_gate_source
|
|
|
|
get_routing
|
2016-05-13 15:14:47 +01:00
|
|
|
get_buffer_read_count
|
|
|
|
get_buffer_write_count
|
2004-03-29 01:39:36 +00:00
|
|
|
}),
|
2016-05-12 19:35:40 +01:00
|
|
|
# TODO: add get_clock_source, but it returns status and two values.
|
2004-03-29 01:39:36 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that return status and a
|
2004-03-29 01:39:36 +00:00
|
|
|
# value. Status is -1 on error. Status and value are both
|
|
|
|
# returned.
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, -1, :compound, %w{
|
2004-03-29 01:39:36 +00:00
|
|
|
command_test
|
|
|
|
}),
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that return 0 on error.
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, 0, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
get_maxdata
|
|
|
|
}),
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that return <0 on error.
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, :neg, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
apply_calibration
|
|
|
|
apply_parsed_calibration
|
|
|
|
}),
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that return nil on error.
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, nil, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
get_driver_name
|
|
|
|
get_board_name
|
|
|
|
get_range
|
|
|
|
get_default_calibration_path
|
|
|
|
}),
|
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
# SWIG::TYPE_p_comedi_t_struct methods that do not indicate errors.
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2007-10-15 00:02:49 +00:00
|
|
|
Method_group.new(SWIG::TYPE_p_comedi_t_struct, :none, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
get_n_subdevices
|
|
|
|
get_version_code
|
|
|
|
}),
|
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
# Comedi_sv_t methods that return -1 on error.
|
2004-03-06 22:13:37 +00:00
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
Method_group.new(Comedi_sv_t, -1, nil, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
sv_init
|
|
|
|
sv_update
|
2004-03-29 01:39:36 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
# Comedi_sv_t methods that return status and a value. Status
|
|
|
|
# is -1 on error.
|
|
|
|
|
|
|
|
Method_group.new(Comedi_sv_t, -1, :simple, %w{
|
2004-03-06 22:13:37 +00:00
|
|
|
sv_measure
|
|
|
|
}),
|
|
|
|
|
|
|
|
# Comedi_calibration_t methods that do not indicate errors.
|
|
|
|
|
2004-03-29 01:39:36 +00:00
|
|
|
Method_group.new(Comedi_calibration_t, :none, nil, %w{
|
2016-05-12 19:35:40 +01:00
|
|
|
cleanup_calibration
|
2004-03-06 22:13:37 +00:00
|
|
|
})
|
2004-03-29 01:39:36 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# Wrap Comedi module methods.
|
|
|
|
|
|
|
|
module_methods.each do |d|
|
|
|
|
d.names.each do |n|
|
|
|
|
wrap_module_method(d.class, n, d.err, d.multi)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Wrap instance methods.
|
|
|
|
|
|
|
|
instance_methods.each do |d|
|
2004-03-06 22:13:37 +00:00
|
|
|
d.names.each do |n|
|
2004-03-29 01:39:36 +00:00
|
|
|
wrap_instance_method(d.class, n, d.err, d.multi)
|
2004-03-06 22:13:37 +00:00
|
|
|
end
|
2004-01-17 16:33:09 +00:00
|
|
|
end
|
|
|
|
end
|