-# Copyright (C) 2011-2012 W. Trevor King <wking@drexel.edu>
+# -*- coding: utf-8 -*-
+# Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
+# Éric Piel <piel@delmic.com>
#
# This file is part of pycomedi.
#
-# pycomedi is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation, either version 2 of the License, or (at your
-# option) any later version.
+# pycomedi is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 2 of the License, or (at your option) any later
+# version.
#
-# pycomedi is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
+# pycomedi is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License
-# along with pycomedi. If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU General Public License along with
+# pycomedi. If not, see <http://www.gnu.org/licenses/>.
"Wrap device-wide Comedi functions in a `Device` class"
cimport _comedi_h
cimport _comedilib_h
import _error
+from calibration import Calibration as _Calibration
from instruction cimport Insn as _Insn
from instruction import Insn as _Insn
from subdevice import Subdevice as _Subdevice
3
>>> d.get_n_subdevices()
14
- >>> d.get_version_code()
- (0, 0, 76)
+ >>> d.get_version()
+ (0, 7, 76)
>>> d.get_driver_name()
'ni_pcimio'
>>> s = d.get_read_subdevice()
return ret
def get_version_code(self):
- """Comedi version code.
+ """Comedi version code as a single integer.
This is a kernel-module level property, but a valid device is
necessary to communicate with the kernel module.
-
- Returns a tuple of version numbers, e.g. `(0, 7, 61)`.
"""
version = _comedilib_h.comedi_get_version_code(self.device)
if version < 0:
_error.raise_error(function_name='comedi_get_version_code',
ret=version)
+ return version
+
+ def get_version(self):
+ """Comedi version as a tuple of version numbers.
+
+ Returns the result of `.get_version_code()`, but rephrased as
+ a tuple of version numbers, e.g. `(0, 7, 61)`.
+ """
+ version = self.get_version_code()
ret = []
for i in range(3):
- ret.insert(0, version & (2**8-1))
- version >>= 2**8 # shift over 8 bits
+ ret.insert(0, version & 0xff) # grab lowest 8 bits
+ version >>= 8 # shift over 8 bits
return tuple(ret)
def get_driver_name(self):
ret = _comedilib_h.comedi_do_insnlist(self.device, &il)
finally:
_stdlib.free(il.insns)
- if ret < 0:
+ if ret < len(insnlist):
_error.raise_error(function_name='comedi_do_insnlist', ret=ret)
return ret
function_name='comedi_get_default_calibration_path')
return ret
+ def parse_calibration(self, path=None):
+ """The soft calibration from a file for this device.
+
+ If path is None, the default calibration file is used.
+ """
+ if path is None:
+ path = self.get_default_calibration_path()
+ c = _Calibration(device=self)
+ c.from_file(path)
+ return c
+
# extensions to make a more idomatic Python interface
def insn(self):