Skip to content

Commit 8298dcb

Browse files
committed
Add pumps
1 parent 6b2728a commit 8298dcb

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

docs/pylabrobot.pumps.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. currentmodule:: pylabrobot.pumps
2+
3+
pylabrobot.pumps package
4+
========================
5+
6+
This package contains APIs for working with pumps.
7+
8+
.. autosummary::
9+
:toctree: _autosummary
10+
:nosignatures:
11+
:recursive:
12+
13+
pylabrobot.pumps.pump.Pump
14+
15+
16+
Backends
17+
--------
18+
19+
.. autosummary::
20+
:toctree: _autosummary
21+
:nosignatures:
22+
:recursive:
23+
24+
pylabrobot.pumps.cole_parmer.masterflex.Masterflex

docs/pylabrobot.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ Subpackages
1010
:maxdepth: 1
1111

1212
pylabrobot.liquid_handling
13+
pylabrobot.pumps
1314
pylabrobot.resources
1415
pylabrobot.utils

pylabrobot/pumps/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .pump import Pump
2+
from .cole_parmer import Masterflex

pylabrobot/pumps/backend.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from abc import ABCMeta
2+
3+
from pylabrobot.machine import MachineBackend
4+
5+
6+
class PumpBackend(MachineBackend, metaclass=ABCMeta):
7+
""" Abstract base class for pump backends. """
8+
9+
def run_revolutions(self, num_revolutions: float):
10+
""" Run for a given number of revolutions.
11+
12+
Args:
13+
num_revolutions: number of revolutions to run.
14+
"""
15+
16+
def run_continuously(self, speed: float):
17+
""" Run continuously at a given speed.
18+
19+
If speed is 0, the pump will be halted.
20+
21+
Args:
22+
speed: speed in rpm.
23+
"""
24+
25+
def halt(self):
26+
""" Halt the pump. """
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .masterflex import Masterflex
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import Optional
2+
3+
import serial # type: ignore
4+
5+
from pylabrobot.pumps.backend import PumpBackend
6+
7+
8+
class Masterflex(PumpBackend):
9+
""" Backend for the Cole Parmer Masterflex L/S 07551-20 pump
10+
11+
Documentation available at:
12+
- https://pim-resources.coleparmer.com/instruction-manual/a-1299-1127b-en.pdf
13+
- https://web.archive.org/web/20210924061132/https://pim-resources.coleparmer.com/
14+
instruction-manual/a-1299-1127b-en.pdf
15+
"""
16+
17+
def __init__(self, com_port: str):
18+
self.com_port = com_port
19+
self.ser: Optional[serial.Serial] = None
20+
21+
async def setup(self):
22+
self.ser = serial.Serial(
23+
port=self.com_port,
24+
baudrate=4800,
25+
timeout=1,
26+
parity=serial.PARITY_ODD,
27+
stopbits=serial.STOPBITS_ONE,
28+
bytesize=serial.SEVENBITS
29+
)
30+
31+
self.ser.write(b"\x05") # Enquiry; ready to send.
32+
self.send_command("P21")
33+
34+
def send_command(self, command: str):
35+
assert self.ser is not None
36+
command = "\x02" + command + "\x0d"
37+
self.ser.write(command.encode())
38+
return self.ser.read()
39+
40+
def run_revolutions(self, num_revolutions: float):
41+
num_revolutions = round(num_revolutions, 2)
42+
cmd = f"P21V{num_revolutions}G"
43+
self.send_command(cmd)
44+
45+
def run_continuously(self, speed: float):
46+
if speed == 0:
47+
self.halt()
48+
return
49+
50+
direction = "+" if speed > 0 else "-"
51+
speed = int(abs(speed))
52+
cmd = f"P21S{direction}{speed}G0"
53+
self.send_command(cmd)
54+
55+
def halt(self):
56+
self.send_command("P21H")

pylabrobot/pumps/pump.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pylabrobot.machine import MachineFrontend
2+
3+
from .backend import PumpBackend
4+
5+
6+
class Pump(MachineFrontend):
7+
""" Frontend for a (peristaltic) pump. """
8+
9+
def __init__(self, backend: PumpBackend):
10+
self.backend: PumpBackend = backend
11+
12+
def run_revolutions(self, num_revolutions: float):
13+
self.backend.run_revolutions(num_revolutions=num_revolutions)
14+
15+
def run_continuously(self, speed: float):
16+
""" Run continuously at a given speed.
17+
18+
If speed is 0, the pump will be halted.
19+
20+
Args:
21+
speed: speed in rpm
22+
"""
23+
24+
self.backend.run_continuously(speed=speed)
25+
26+
def halt(self):
27+
self.backend.halt()

0 commit comments

Comments
 (0)