Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #83 from psyfood/fill-empty
Browse files Browse the repository at this point in the history
ENH: Add `switch_valve_when_done` kwarg to multiple methods
  • Loading branch information
hoechenberger committed Nov 23, 2018
2 parents df730ae + 60d4052 commit 973e493
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
@@ -1,7 +1,11 @@
Version 2018.xx.xx
------------------
* Update installation instructions
* Automated testing using Travis now also runs on Python 2.7 (only tested Python 3 before)
* Automated testing using Travis now also runs on Python 2.7 (only tested
Python 3 before)
* `switch_valve_when_done` keyword argument is now available for all pumping
operations
* Depend on `pypiwin32` instead of `pywin32`

Version 2018.11.07
------------------
Expand Down
57 changes: 51 additions & 6 deletions pyqmix/pump.py
Expand Up @@ -586,6 +586,7 @@ def aspirate(self, volume, flow_rate, wait_until_done=False,

self.valve.switch_position(self.valve.aspirate_pos)
self._call('LCP_Aspirate', self._handle[0], volume, flow_rate)

if wait_until_done:
# Wait until pumping has actually started.
while not self.is_pumping:
Expand Down Expand Up @@ -647,6 +648,7 @@ def dispense(self, volume, flow_rate, wait_until_done=False,

self.valve.switch_position(self.valve.dispense_pos)
self._call('LCP_Dispense', self._handle[0], volume, flow_rate)

if wait_until_done:
# Wait until pumping has actually started.
while not self.is_pumping:
Expand All @@ -659,7 +661,8 @@ def dispense(self, volume, flow_rate, wait_until_done=False,
if switch_valve_when_done:
self.valve.switch_position(self.valve.aspirate_pos)

def set_fill_level(self, level, flow_rate, wait_until_done=False):
def set_fill_level(self, level, flow_rate, wait_until_done=False,
switch_valve_when_done=False):
"""
Pumps fluid with the given flow rate until the requested fill level is
reached.
Expand All @@ -680,6 +683,10 @@ def set_fill_level(self, level, flow_rate, wait_until_done=False):
wait_until_done : bool
Whether to halt program execution until done.
switch_valve_when_done : bool
If set to ``True``, it switches valve to dispense position after
the aspiration is finished. Implies `wait_until_done=True`.
Raises
------
ValueError
Expand All @@ -692,12 +699,16 @@ def set_fill_level(self, level, flow_rate, wait_until_done=False):
if flow_rate <= 0:
raise ValueError('Flow rate must be positive.')

if switch_valve_when_done:
wait_until_done = True

# Switch the valves to inlet or outlet position, depending on
# whether we are going to aspirate or to dispense.
if level < self.get_fill_level():
self.valve.switch_position(self.valve.dispense_pos)
else:
self.valve.switch_position(self.valve.aspirate_pos)

self._call('LCP_SetFillLevel', self._handle[0], level, flow_rate)

if wait_until_done:
Expand All @@ -709,7 +720,11 @@ def set_fill_level(self, level, flow_rate, wait_until_done=False):
while self.is_pumping:
time.sleep(0.0005)

def generate_flow(self, flow_rate, wait_until_done=False):
if switch_valve_when_done:
self.valve.switch_position(self.valve.aspirate_pos)

def generate_flow(self, flow_rate, wait_until_done=False,
switch_valve_when_done=False):
"""
Generate a continuous flow.
Expand All @@ -724,6 +739,10 @@ def generate_flow(self, flow_rate, wait_until_done=False):
wait_until_done : bool
Whether to halt program execution until done.
switch_valve_when_done : bool
If set to ``True``, it switches valve to dispense position after
the aspiration is finished. Implies `wait_until_done=True`.
Raises
------
ValueError
Expand All @@ -733,11 +752,16 @@ def generate_flow(self, flow_rate, wait_until_done=False):
if flow_rate == 0:
raise ValueError('Flow rate must be non-zero.')

if switch_valve_when_done:
wait_until_done = True

if flow_rate > 0:
self.valve.switch_position(self.valve.dispense_pos)
else:
self.valve.switch_position(self.valve.aspirate_pos)

self._call('LCP_GenerateFlow', self._handle[0], flow_rate)

if wait_until_done:
# Wait until pumping has actually started.
while not self.is_pumping:
Expand All @@ -747,7 +771,11 @@ def generate_flow(self, flow_rate, wait_until_done=False):
while self.is_pumping:
time.sleep(0.0005)

def fill(self, flow_rate, wait_until_done=False):
if switch_valve_when_done:
self.valve.switch_position(self.valve.aspirate_pos)

def fill(self, flow_rate, wait_until_done=False,
switch_valve_when_done=False):
"""
Fill the syringe.
Expand All @@ -759,6 +787,10 @@ def fill(self, flow_rate, wait_until_done=False):
wait_until_done : bool
Whether to halt program execution until done.
switch_valve_when_done : bool
If set to ``True``, it switches valve to dispense position after
the aspiration is finished. Implies `wait_until_done=True`.
Raises
------
ValueError
Expand All @@ -775,9 +807,14 @@ def fill(self, flow_rate, wait_until_done=False):
if flow_rate <= 0:
raise ValueError('Flow rate must be positive.')

self.generate_flow(-flow_rate, wait_until_done=wait_until_done)
if switch_valve_when_done:
wait_until_done = True

self.generate_flow(-flow_rate, wait_until_done=wait_until_done,
switch_valve_when_done=switch_valve_when_done)

def empty(self, flow_rate, wait_until_done=False):
def empty(self, flow_rate, wait_until_done=False,
switch_valve_when_done=False):
"""
Empty the syringe.
Expand All @@ -789,6 +826,10 @@ def empty(self, flow_rate, wait_until_done=False):
wait_until_done : bool
Whether to halt program execution until done.
switch_valve_when_done : bool
If set to ``True``, it switches valve to dispense position after
the aspiration is finished. Implies `wait_until_done=True`.
Raises
------
ValueError
Expand All @@ -803,7 +844,11 @@ def empty(self, flow_rate, wait_until_done=False):
if flow_rate <= 0:
raise ValueError('Flow rate must be positive.')

self.generate_flow(flow_rate, wait_until_done=wait_until_done)
if switch_valve_when_done:
wait_until_done = True

self.generate_flow(flow_rate, wait_until_done=wait_until_done,
switch_valve_when_done=switch_valve_when_done)

def stop(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,5 +1,5 @@
cffi
ruamel.yaml
appdirs
pywin32
pypiwin32
-e .
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -28,7 +28,7 @@ install_requires =
cffi
ruamel.yaml
appdirs
pywin32; platform_system == "Windows"
pypiwin32; platform_system == "Windows"
future; python_version < '3'

[bdist_wheel]
Expand Down

0 comments on commit 973e493

Please sign in to comment.