Package: python-syringe-pump
Python controller for Legato family of syringe pumpsControl a syringe pumpt (e.g. Legato 100 / 101) using a computer.
This package uses a COM port to communicate with the pump via an USB cable.
It enables you to write python programs that control the pump, e.g. turn it on and off, set the flow rate, etc.Installationpipinstallpython-syringe-pumporpoetryaddpython-syringe-pumpUsageWorking exampleCopy-paste this to get going!importasyncioimportaioserialfromsyringe_pumpimportPump,Quantityasyncdefmain():serial=aioserial.AioSerial(port="COM4",baudrate=115200,timeout=2)asyncwithPump(serial=serial)aspump:awaitpump.infusion_rate.set(Quantity("1 ml/min"))awaitpump.run()awaitasyncio.sleep(10)# pump will stop when exiting the context managerasyncio.run(main())Curious about the pieces of code above? Read on!Serial port connectionThesyringe_pumpusesaioserialto communicate with the pump via the COM port.
To use the controller, create a serial connection and pass it into the Pump class.importaioserialserial=aioserial.AioSerial(port="COM4",baudrate=115200,timeout=2)Async communicationThis package usesasyncioto communicate with the pump.
As a result, you need to add a fewawaitstatements to your code, which may seem like a pain.
However, the benefits will be worth it, especially when working with multiple pumps or sending experiment results via a network.fromsyringe_pumpimportPump,Quantitypump=awaitPump.from_serial(serial=serial)awaitpump.infusion_rate.set(Quantity("1 ml/min"))awaitpump.run()Note: Thefrom_serialclass method will configure the pump to
use the correct communication protocol and disable NVRAM, following manufacturer's recommendations.Async context managerIn python, it's common to usecontext managersto handle external resources such as files, network connections, etc.Instead of the above examle, you can use thePumpas such context manager, which will
automatically stop the pump in case of an error or at the end of the program.fromsyringe_pumpimportPump,QuantityasyncwithPump(serial=serial)aspump:awaitpump.infusion_rate.set(Quantity("1 ml/min"))awaitpump.run()Running async codeTo run the async code in a normal python file,
you need to use theasyncio.runfunction or similar:importasyncio# in regular python file:asyncdefmain():asyncio.sleep(1)asyncio.run(main())Note: To benefit from non-blocking asyncio code, useasyncio.sleepinstead oftime.sleep.Note: in a jupyter notebook, you can useawaitdirectly in the cell:# in jupyter notebook only:awaitmain()APIUnitsThe pump controller uses thequantiphypackage to handle flow rates, volumes etc.Example usage:fromsyringe_pumpimportQuantityQuantity("1 ml/min")Quantity("13.54 ml")Pump classThe controller implements most of the functionality specified inLegato user Commands.The methods and their parameters are easy to discover using autocomplete in your IDE.Here's a quick overview of the popular methods:run&stop: control the pump operationset_brightness: control the onboard display. Set to 0 to turn off.set_force&get_force: control the force applied to the syringeNext, the pump controller has some properties that allow you to manage other parameters:Pump.infusion_rate and Pump.withdrawal_rateThe pump flow rates can be controlled here, including ramping.
Common methods available are:setandgetset_ramp(start, end, duration)Example:rate=awaitpump.infusion_rate.get_rate()awaitpump.infusion_rate.set_rate(2*rate)awaitpump.infusion_rate.set_ramp(2*rate,0,10)Pump.syringeThe syringe parameters can be controlled here.
The pump uses them to convert between flow rates and volumes.Important methods:get_diameterandset_diameterget_volumeandset_volumeset_manufacturer- to use pre-defined settings for common syringesExample:fromsyringe_pumpimportManufacturerawaitpump.syringe.set_manufacturer(Manufacturer.HOSHI,Quantity("1 ml"))ExamplesSee theexamplesfolder for more examples.Pump.infusion_volume and Pump.withdrawal_volumeAllows you to inspect and reset the volume dispensed by the pump.
The pump keeps track of the volume since last reset by itself.Methods:getclearPump.target_volumeAllows you to set a volume after which the pump will stop by itself.
This is useful to prevent the pump from over-dispensing and damaging the syringe.Methods:setclearget- returns the target volume orNoneif not setNote that there is only one target volume across infusion and withdrawal.
Negative values are not allowed.Pump.target_timeAllows you to set a time after which the pump will stop by itself.
The time is represented as adatetime.timedeltaobject.Methods:setclearget- returns the target time orNoneif not setExample:fromdatetimeimporttimedeltaawaitpump.target_time.set(timedelta(hours=2,minutes=10))Note: it seems the pumpt can only handle target time or target volume, but not both.DevelopmentHave a look atCONTRIBUTING.mdfor more information on the scope of the project and how to contribute.CreditsProject logo:Freepik @ Flaticon.com