From d721a0c05450c793a5e0e562d286a689565cf81b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 19 Mar 2012 10:48:36 -0400 Subject: [PATCH] Mask range.unit with 0xff when determining the unit. 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. --- pycomedi/range.pyx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pycomedi/range.pyx b/pycomedi/range.pyx index c3e196a..6c05cde 100644 --- a/pycomedi/range.pyx +++ b/pycomedi/range.pyx @@ -46,6 +46,10 @@ cdef class Range (_BitwiseOperator): >>> 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 @@ -67,9 +71,10 @@ cdef class Range (_BitwiseOperator): 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): -- 2.26.2