|
| 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") |
0 commit comments