This avoids crashes like:
Traceback (most recent call last):
...
File "range.pyx", line 62, in pycomedi.range.Range.__str__
File "range.pyx", line 70, in pycomedi.range.Range._unit_get
File "constant.pyx", line 269, in pycomedi.constant._Enum.index_by_value
KeyError: 256L
when RF_EXTERNAL is set.
>>> r.unit
<_NamedInt mA>
"""
+ # other data gets packed into the unit unsigned int (e.g RF_EXTERNAL)
+ _uint_all = 0xffffffffL
+ _unit_all = 0xff
+
def __cinit__(self):
self.value = -1
return self.__str__()
def _unit_get(self):
- return _constant.UNIT.index_by_value(self.range.unit)
+ return _constant.UNIT.index_by_value(self.range.unit & self._unit_all)
def _unit_set(self, value):
- self.range.unit = _constant.bitwise_value(value)
+ self.range.unit &= self._uint_all - self._unit_all
+ self.range.unit |= _constant.bitwise_value(value) & self._unit_all
unit = property(fget=_unit_get, fset=_unit_set)
def _min_get(self):