Source code for fluidlab.objects.boards

"""Data Acquisition boards (:mod:`fluidlab.objects.boards`)

.. _lab.boards:
.. currentmodule:: fluidlab.objects.boards

Provides two small classes, :class:`ObjectUsingBoard` and the modules:

.. autosummary::


**Remark**: Can not import the module
:mod:`fluidlab.objects.boards.powerdaq` in Linux... So no doc!

The classes for data acquisition boards should be obtained from this
package. If the boards are not available, no error are raised and the
classes are replaced by the class

For example, with a computer without PowerDAQ board::

    from fluidlab.objects.boards import PowerDAQBoard
    board = PowerDAQBoard() # no error
    assert( == False) # no error
    assert(not board) # no error
    # AttributeError: You tried to use a false acquisition board.

.. autoclass:: ObjectUsingBoard

.. autoclass:: FalseBoard


from import _write_warning

[docs]class FalseBoard: """Represent a false acquisition board. This object tested as a boolean is False. It has an attribute `works` equal to False and an AttributeError on it returns an understandable message. """ works = False def __getattr__(self, key): raise AttributeError("You tried to use a false acquisition board.") def __bool__(self): """For python => 3.0""" return False def __nonzero__(self): """For python < 3""" return False
try: from .powerdaq import PowerDAQBoard except ImportError: _write_warning( "Warning:\n no fluidlab.objects.boards.powerdaq (use FalseBoard)." ) PowerDAQBoard = FalseBoard from . import nidaqnx if NIDAQBoard = nidaqnx.NIDAQBoard else: _write_warning( "Warning:\n " "no fluidlab.objects.boards.nidaqnx.NIDAQBoard (use FalseBoard)." ) NIDAQBoard = FalseBoard
[docs]class ObjectUsingBoard: """Useful to write classes for objects using a board.""" def __init__(self, board=None, VERBOSE=False): if board is None and VERBOSE: print( """Warning: none instance of the class PowerDAQBoard (or NIDAQBoard) has been given. Some functions need the board.""" ) self.board = board