1 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
3 # This file is part of pycomedi.
5 # pycomedi is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 2 of the License, or (at your option) any later
10 # pycomedi is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # pycomedi. If not, see <http://www.gnu.org/licenses/>.
17 "Wrap `comedi_range` in a Python class"
19 from pycomedi.constant cimport BitwiseOperator as _BitwiseOperator
20 from . import constant as _constant
23 cdef class Range (_BitwiseOperator):
24 """Stucture displaying a possible channel range
26 Warning: You probably want to use `channel.Channel.get_range()` or
27 `channel.Channel.find_range()` rather than initializing this
28 stucture by hand. If you do initialize it by hand (or set any
29 values by hand), remember that it may no longer correspond to your
30 devices built-in range with that index.
32 For consistency with other integer wrappers, the range index is
33 stored in the `.value` attribute.
35 >>> from constant import UNIT
38 <Range unit:volt min:0.0 max:0.0>
45 <Range unit:mA min:-2.71828 max:3.14159>
52 def __init__(self, value):
58 cdef set_comedi_range(self, _comedilib_h.comedi_range range):
62 fields = ['%s:%s' % (f, getattr(self, f))
63 for f in ['unit', 'min', 'max']]
64 return '<%s %s>' % (self.__class__.__name__, ' '.join(fields))
70 return _constant.UNIT.index_by_value(self.range.unit)
71 def _unit_set(self, value):
72 self.range.unit = _constant.bitwise_value(value)
73 unit = property(fget=_unit_get, fset=_unit_set)
77 def _min_set(self, value):
78 self.range.min = value
79 min = property(fget=_min_get, fset=_min_set)
83 def _max_set(self, value):
84 self.range.max = value
85 max = property(fget=_max_get, fset=_max_set)