-# Copyright (C) 2011-2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
#
# This file is part of pycomedi.
#
>>> TRIG_SRC.now <= 2
True
>>> TRIG_SRC.now < 3
-False
+True
>>> TRIG_SRC.now > None
True
+The ``UNIT`` constant treats ``RF_EXTERNAL`` as a full-fledged unit:
+
+>>> UNIT.index_by_name('external')
+<_NamedInt external>
+>>> UNIT.index_by_value(_comedi.RF_EXTERNAL)
+<_NamedInt external>
+
.. [#ops] See `emulating numeric types`_ and `NotImplementedError` in
`the standard type hierarchy`_.
import numpy as _numpy
import comedi as _comedi
-from pycomedi import LOG as _LOG
+from . import LOG as _LOG
def bitwise_value(object):
else:
raise ValueError(op)
+ def __reduce__(self):
+ return (BitwiseOperator, (self.value,))
+
class _NamedInt (BitwiseOperator):
"A flag or enum item."
def __repr__(self):
return '<%s %s>' % (self.__class__.__name__, self.name)
+ def __reduce__(self):
+ return (_NamedInt, (self.name, self.value, self.doc))
+
class _Enum (list):
"An enumerated list"
translation = {}
self._name_keys = {}
self._value_keys = {}
- for attr in dir(_comedi):
+ mod = _comedi
+ if hasattr(mod, 'wrapped'):
+ mod = mod.wrapped
+ if prefix.startswith('COMEDI_'):
+ prefix = prefix[len('COMEDI_'):]
+ for attr in dir(mod):
if attr.startswith(prefix):
item_name = self._item_name(attr, prefix, translation)
if self._is_ignored(item_name, blacklist, whitelist):
def _add_item(self, attr, item_name):
item_value = getattr(_comedi, attr)
+ if not isinstance(item_value, int):
+ return # item_name collided with another object, skip this non-int
if item_value < 0:
_LOG.debug('big value for {0:s}: {1:d} ({1:b}) converted to {2:d} ({2:b})'.format(
attr, item_value, (1<<32) + item_value))
self._value_keys[item.value] = item
setattr(self, item.name, item)
-
def index_by_name(self, name):
return self._name_keys[name]
UNIT = _Enum('unit', 'UNIT_', translation={'mA':'mA'})
# The mA translation avoids lowercasing to 'ma'.
+UNIT.append(_NamedInt(
+ name='external',
+ value=_comedi.RF_EXTERNAL,
+ doc=('RF_EXTERNAL (value unit is defined by an external reference '
+ 'channel)')))
CALLBACK = _Enum('callback_flags', 'COMEDI_CB_', blacklist=['block', 'eobuf'])
CALLBACK.eos.doc += ' (end of scan)'