Skip to main content

With the new Python integration for the Qmix SDK you can develop small applications in the shortest time, automate certain dosing processes or realize your own analyses. The main advantage of Python is its ease of programming, which significantly reduces the time required to develop, debug and maintain the code. In the following example we show you how easy and fast you can implement an application with Python and the Qmix SDK.

Installation

To install, simply use the Qmix SDK installation package for Windows. The SDK will be installed in a folder of your choice.

Integration

To include the Qmix SDK in your Python script you have to add the path containing the Qmix SDK modules to the module search path. In order for Python to load the shared libraries (DLLs) of the SDK, you must then add the path containing the DLLs to the Windows search path. All details are also available in the online documentation.

import sys
import os
QMIXSDK_DIR = "C:/temp/QmixSDK-64bit_20180626"
sys.path.append(QMIXSDK_DIR + "/lib/python")
os.environ['PATH'] += os.pathsep + QMIXSDK_DIR

 

Now you can import the modules of the Qmix SDK Python integration.

from qmixsdk import qmixbus
from qmixsdk import qmixpump

 

The first Python application

Now you can start developing your first application. The following program shows a small example. First a bus object is created, initialized with the path to a device configuration and then the communication is started. Then we create a pump object and connect it to the first pump in the SDK – device index 0. As a test we print the name of the pump with the print function.

def main():
"""
A small example that shows how to use the Qmix SDK for Python
"""
bus = qmixbus.Bus()
bus.open("testconfig_qmixsdk", "")
bus.start()
pump = qmixpump.Pump()
pump.lookup_by_device_index(0)
print(pump.get_device_name())

 

In the next step we perform a reference run with the calibrate function to determine the zero position of the pump. Before the reference run, we clear any remaining errors (clear_fault) and enable the pump (enable). With the help of a timeout timer we wait until the calibration is finished.

pump.clear_fault()
pump.enable(True)
pump.calibrate()
timeout_timer = qmixbus.PollingTimer(10000)
result = timeout_timer.wait_until(pump.is_calibration_finished, True)
print(result)

 

The pump is now initialized and we can start dosing. For this we set the units for volume and flow rate to milliliter and milliliter per second. As a test we will output the unit for the flow with the print function. Then we configure the syringe to be used. We use a syringe with 1 mm inner diameter and 60 mm plunger stroke. In line 41 we start the aspiration (aspirate) of 0.02 ml with a flow rate of 0.004 ml/s. With a timeout timer we wait again until the dosage is finished.

pump.set_volume_unit(UnitPrefix.milli, VolumeUnit.litres)
pump.set_flow_unit(UnitPrefix.milli, VolumeUnit.litres, TimeUnit.per_second)
print(pump.get_flow_unit()
pump.set_syringe_param(1, 60)
print(pump.get_syringe_param())
print(pump.get_volume_max())
print(pump.get_flow_rate_max())
pump.aspirate(0.02, 0.004)
timeout_timer.set_period(10000)
result = timeout_timer.wait_until(pump.is_pumping, False)
print(result)

 

At the end of the program we stop the communication and call the close function of the bus object to release all resources again.

bus.stop()
bus.close()

 

We hope you got a small impression of how powerful and simple the Qmix SDK for Python is. You can download the Python example from this blog post here.