"Cython interface to comedilib.h"
-from _comedi_h cimport *
+from pycomedi._comedi_h cimport *
cdef extern from 'comedilib.h':
"Useful error checking wrappers around Comedilib function calls"
-# No relative imports in Cython yet, see
-# http://trac.cython.org/cython_trac/ticket/542
-from pycomedi import LOG as _LOG
-from pycomedi import PyComediError as _PyComediError
+from . import LOG as _LOG
+from . import PyComediError as _PyComediError
-cimport _comedilib_h
+from pycomedi cimport _comedilib_h
def raise_error(function_name=None, ret=None, error_msg=None):
"Expose `CalibratedConverter` internals at the C level for other Cython modules"
-cimport _comedilib_h
+from pycomedi cimport _comedilib_h
cdef class CalibratedConverter (object):
cimport numpy as _numpy
import numpy as _numpy
-cimport _comedi_h
-cimport _comedilib_h
-import _error
-import constant as _constant
-import utility as _utility
+from pycomedi cimport _comedi_h
+from pycomedi cimport _comedilib_h
+from . import _error
+from . import constant as _constant
+from . import utility as _utility
cdef void _python_to_charp(
cimport numpy as _numpy
import numpy as _numpy
-cimport _comedi_h
-cimport _comedilib_h
-from calibration cimport CalibratedConverter as _CalibratedConverter
-from calibration cimport Calibration as _Calibration
-from range cimport Range as _Range
-from subdevice_holder cimport SubdeviceHolder as _SubdeviceHolder
+from pycomedi cimport _comedi_h
+from pycomedi cimport _comedilib_h
+from pycomedi cimport calibration as _calibration
+from pycomedi cimport range as _range
+from pycomedi cimport subdevice_holder as _subdevice_holder
-from pycomedi import LOG as _LOG
-from chanspec import ChanSpec as _ChanSpec
-from pycomedi import PyComediError as _PyComediError
-import _error
-import constant as _constant
+from . import LOG as _LOG
+from . import PyComediError as _PyComediError
+from . import _error
+from . import chanspec as _chanspec
+from . import constant as _constant
cdef class Channel (object):
>>> d.close()
"""
- cdef public _SubdeviceHolder subdevice
+ cdef public _subdevice_holder.SubdeviceHolder subdevice
cdef public int index
def __cinit__(self):
cdef _get_range(self, index):
cdef _comedilib_h.comedi_range *rng
- cdef _Range ret
+ cdef _range.Range ret
# Memory pointed to by the return value is freed on Device.close().
rng = _comedilib_h.comedi_get_range(
self._device(), self.subdevice.index, self.index, index)
if rng is NULL:
_error.raise_error(function_name='comedi_get_range')
- ret = _Range(value=index)
+ ret = _range.Range(value=index)
ret.set_comedi_range(rng[0])
# rng[0] is a sneaky way to dereference rng, since Cython
# doesn't support *rng.
>>> c.range
<Range unit:volt min:-10.0 max:10.0>
"""
- cdef public _Range range
+ cdef public _range.Range range
cdef public object aref
def __init__(self, range=None, aref=None, **kwargs):
_error.raise_error(function_name='comedi_data_write', ret=ret)
def chanspec(self):
- return _ChanSpec(chan=self.index, range=self.range, aref=self.aref)
+ return _chanspec.ChanSpec(
+ chan=self.index, range=self.range, aref=self.aref)
cdef _comedilib_h.comedi_polynomial_t get_softcal_converter(
- self, direction, _Calibration calibration) except *:
+ self, direction, _calibration.Calibration calibration) except *:
"""Get a calibration polynomial for a software-calibrated channel
`direction` should be a value from `constant.CONVERSION_DIRECTION`.
ret=rc)
return poly
- cdef _get_converter(self, _Calibration calibration):
+ cdef _get_converter(self, _calibration.Calibration calibration):
cdef _comedilib_h.comedi_polynomial_t to_physical, from_physical
- cdef _CalibratedConverter ret
+ cdef _calibration.CalibratedConverter ret
flags = self.subdevice.get_flags()
from_physical_error = None
if flags.soft_calibrated:
_constant.CONVERSION_DIRECTION.to_physical)
from_physical = self.get_hardcal_converter(
_constant.CONVERSION_DIRECTION.from_physical)
- ret = _CalibratedConverter(from_physical_error=from_physical_error)
+ ret = _calibration.CalibratedConverter(
+ from_physical_error=from_physical_error)
ret._to_physical = to_physical
if from_physical_error is None:
ret._from_physical = from_physical
function_name='comedi_apply_calibration', ret=ret)
return ret
- cdef _apply_parsed_calibration(self, _Calibration calibration):
+ cdef _apply_parsed_calibration(self, _calibration.Calibration calibration):
ret = _comedilib_h.comedi_apply_parsed_calibration(
self._device(), self.subdevice.index, self.index,
_constant.bitwise_value(self.range),
function_name='comedi_apply_parsed_calibration', ret=ret)
return ret
- def apply_calibration(self, _Calibration calibration=None, path=None):
+ def apply_calibration(self, _calibration.Calibration calibration=None,
+ path=None):
"""Apply a calibration to this channel configuration
`calibration` may None or a `Calibration` instance. If it is
"Replace Comedi's CR_PACK and related macros with a Python class"
-cimport _comedi_h
-import constant as _constant
+from pycomedi cimport _comedi_h
+from . import constant as _constant
class ChanSpec (_constant.BitwiseOperator):
"Expose `Command` internals at the C level for other Cython modules"
-cimport _comedi_h
+from pycomedi cimport _comedi_h
cdef class Command (object):
cimport libc.stdlib as _stdlib
import numpy as _numpy
-cimport _comedi_h
-cimport _comedilib_h
-from pycomedi import PyComediError as _PyComediError
-from chanspec import ChanSpec as _ChanSpec
-import constant as _constant
+from pycomedi cimport _comedi_h
+from pycomedi cimport _comedilib_h
+from . import PyComediError as _PyComediError
+from . import chanspec as _chanspec
+from . import constant as _constant
cdef class Command (object):
def _chanlist_get(self):
ret = list()
for i in range(self._cmd.chanlist_len):
- c = _ChanSpec()
+ c = _chanspec.ChanSpec()
c.value = self._cmd.chanlist[i]
ret.append(c)
return ret
import numpy as _numpy
import comedi as _comedi
-from pycomedi import LOG as _LOG
+from . import LOG as _LOG
def bitwise_value(object):
"Expose `Device` internals at the C level for other Cython modules"
-cimport _comedilib_h
-from device_holder cimport DeviceHolder as _DeviceHolder
-from instruction cimport Insn as _Insn
+from pycomedi cimport _comedilib_h
+from pycomedi cimport device_holder as _device_holder
+from pycomedi cimport instruction as _instruction
-cdef class Device (_DeviceHolder):
+cdef class Device (_device_holder.DeviceHolder):
cdef public object file
cdef public object filename
cpdef do_insnlist(self, insnlist)
- cpdef do_insn(self, _Insn insn)
+ cpdef do_insn(self, _instruction.Insn insn)
import os as _os
cimport libc.stdlib as _stdlib
-from pycomedi import LOG as _LOG
-from pycomedi import PyComediError as _PyComediError
-cimport _comedi_h
-cimport _comedilib_h
-import _error
-from calibration import Calibration as _Calibration
-from device_holder cimport DeviceHolder as _DeviceHolder
-from device_holder import DeviceHolder as _DeviceHolder
-from instruction cimport Insn as _Insn
-from instruction import Insn as _Insn
-from subdevice import Subdevice as _Subdevice
-
-
-cdef class Device (_DeviceHolder):
+from . import LOG as _LOG
+from . import PyComediError as _PyComediError
+from pycomedi cimport _comedi_h
+from pycomedi cimport _comedilib_h
+from . import _error
+from . import calibration as _calibration
+from pycomedi cimport device_holder as _device_holder
+from . import device_holder as _device_holder
+from pycomedi cimport instruction as _instruction
+from . import instruction as _instruction
+from . import subdevice as _subdevice
+
+
+cdef class Device (_device_holder.DeviceHolder):
"""A Comedi device
>>> from . import constant
Returns the number of successfully completed instructions.
"""
cdef _comedi_h.comedi_insnlist il
- cdef _Insn i
+ cdef _instruction.Insn i
il.n_insns = len(insnlist)
if il.n_insns == 0:
return
_error.raise_error(function_name='comedi_do_insnlist', ret=ret)
return ret
- cpdef do_insn(self, _Insn insn):
+ cpdef do_insn(self, _instruction.Insn insn):
"""Preform a single instruction.
Returns an instruction-specific integer.
"""
if path is None:
path = self.get_default_calibration_path()
- c = _Calibration(device=self)
+ c = _calibration.Calibration(device=self)
c.from_file(path)
return c
# extensions to make a more idomatic Python interface
def insn(self):
- return _Insn()
+ return _instruction.Insn()
def subdevices(self, **kwargs):
"Iterate through all available subdevices."
ret.append(self.subdevice(i, **kwargs))
return ret
- def subdevice(self, index, factory=_Subdevice, **kwargs):
+ def subdevice(self, index, factory=_subdevice.Subdevice, **kwargs):
return factory(device=self, index=index, **kwargs)
# Copyright
-cimport _comedilib_h
+from pycomedi cimport _comedilib_h
cdef class DeviceHolder (object):
"Expose `Insn` internals at the C level for other Cython modules"
-cimport _comedi_h
+from pycomedi cimport _comedi_h
cdef class Insn (object):
cimport libc.stdlib as _stdlib
import numpy as _numpy
-cimport _comedi_h
-cimport _comedilib_h
-from pycomedi import PyComediError as _PyComediError
-from chanspec import ChanSpec as _ChanSpec
-import constant as _constant
+from pycomedi cimport _comedi_h
+from pycomedi cimport _comedilib_h
+from . import PyComediError as _PyComediError
+from . import chanspec as _chanspec
+from . import constant as _constant
cdef class Insn (object):
subdev = property(fget=_subdev_get, fset=_subdev_set)
def _chanspec_get(self):
- c = _ChanSpec()
+ c = _chanspec.ChanSpec()
c.value = self._insn.chanspec
return c
def _chanspec_set(self, value):
import os as _os
-cimport _comedilib_h
-import constant as _constant
+from pycomedi cimport _comedilib_h
+from . import constant as _constant
def set_loglevel(level):
"Expose `Range` internals at the C level for other Cython modules"
-cimport _comedilib_h
-from constant cimport BitwiseOperator as _BitwiseOperator
+from pycomedi cimport _comedilib_h
+from . import constant as _constant
-cdef class Range (_BitwiseOperator):
+cdef class Range (_constant.BitwiseOperator):
cdef _comedilib_h.comedi_range range
cdef set_comedi_range(self, _comedilib_h.comedi_range range)
"Wrap `comedi_range` in a Python class"
-from constant cimport BitwiseOperator as _BitwiseOperator
-import constant as _constant
+from pycomedi import constant as _constant
+from . import constant as _constant
-cdef class Range (_BitwiseOperator):
+cdef class Range (_constant.BitwiseOperator):
"""Stucture displaying a possible channel range
Warning: You probably want to use `channel.Channel.get_range()` or
"Expose `Subdevice` internals at the C level for other Cython modules"
-cimport _comedilib_h
-from command cimport Command as _Command
-from subdevice_holder cimport SubdeviceHolder as _SubdeviceHolder
+from pycomedi cimport _comedilib_h
+from pycomedi cimport command as _command
+from pycomedi cimport subdevice_holder as _subdevice_holder
-cdef class Subdevice (_SubdeviceHolder):
+cdef class Subdevice (_subdevice_holder.SubdeviceHolder):
cpdef dio_bitfield(self, unsigned int bits=*, write_mask=*, base_channel=*)
cdef class StreamingSubdevice (Subdevice):
- cdef public _Command cmd
+ cdef public _command.Command cmd
cdef public list _command_test_errors
"Wrap subdevice-wide Comedi functions in `Subdevice` and related classes"
-cimport _comedi_h
-cimport _comedilib_h
-cimport command as _command
-from pycomedi import LOG as _LOG
-import _error
-from channel import Channel as _Channel
-import chanspec as _chanspec
-import constant as _constant
-import command as _command
-from subdevice_holder cimport SubdeviceHolder as _SubdeviceHolder
-from subdevice_holder import SubdeviceHolder as _SubdeviceHolder
-from utility import _subdevice_dtype, _subdevice_typecode
-
-
-cdef class Subdevice (_SubdeviceHolder):
+from pycomedi cimport _comedi_h
+from pycomedi cimport _comedilib_h
+from pycomedi cimport command as _command
+from . import LOG as _LOG
+from . import _error as _error
+from . import channel as _channel
+from . import constant as _constant
+from . import command as _command
+from pycomedi cimport subdevice_holder as _subdevice_holder
+from . import subdevice_holder as _subdevice_holder
+from .utility import _subdevice_dtype, _subdevice_typecode
+
+
+cdef class Subdevice (_subdevice_holder.SubdeviceHolder):
"""Class bundling subdevice-related functions
>>> from .device import Device
ret.append(self.channel(i, **kwargs))
return ret
- def channel(self, index, factory=_Channel, **kwargs):
+ def channel(self, index, factory=_channel.Channel, **kwargs):
"`Channel` instance for the `index`\ed channel."
return factory(subdevice=self, index=index, **kwargs)
# Copyright
-cimport _comedilib_h
-from device_holder cimport DeviceHolder as _DeviceHolder
+from pycomedi cimport _comedilib_h
+from pycomedi cimport device_holder as _device_holder
cdef class SubdeviceHolder (object):
- cdef public _DeviceHolder device
+ cdef public _device_holder.DeviceHolder device
cdef public int index
cdef _comedilib_h.comedi_t * _device(self) except *
# Copyright
-cimport _comedilib_h
+from pycomedi cimport _comedilib_h
cdef class SubdeviceHolder (object):