Source code for fluidlab.objects.pinchvalve

Pinching valve (:mod:`fluidlab.objects.pinchvalve`)

.. currentmodule:: fluidlab.objects.pinchvalve


.. autoclass:: PinchValve

.. autoclass:: ContextManagerOpenedValve

.. autoclass:: FalseContextManager

.. autofunction:: tube_as_opened_as_possible


from __future__ import division, print_function

from fluidlab.objects.boards import ObjectUsingBoard

[docs]class PinchValve(ObjectUsingBoard): """A class handling the pinch valve.""" def __init__(self, board=None, channel=0): super().__init__(board=board) = channel self.close() def open(self): self.board.dout.write(2 ** def close(self): self.board.dout.write(0) def opened(self): return ContextManagerOpenedValve(self)
[docs]class ContextManagerOpenedValve: def __init__(self, valve): self.valve = valve def __enter__(self): return self.valve def __exit__(self, type, value, traceback): self.valve.close()
[docs]class FalseContextManager: def __enter__(self): return self def __exit__(self, type, value, traceback): pass
[docs]def tube_as_opened_as_possible(valve): if valve is not None: return ContextManagerOpenedValve(valve) else: return FalseContextManager()
if __name__ == "__main__": import time from fluidlab.objects.boards import PowerDAQBoard from fluiddyn.util.timer import Timer period = 4 # (s) board = PowerDAQBoard() valve = PinchValve(board) # valve = None timer = Timer(period) for i in xrange(10): time.sleep(1) # with valve.opened(): with tube_as_opened_as_possible(valve): print("valve opened.") timer.wait_tick() print("valve closed.")