#-------------------------------------------------------------------------------
# Name:          Manual Purge for the reactor system
# Purpose:       Allows for purging the system manually with buffer
# Authors:       Eric N
#
# Last Version:  22.09.2022
# Copyright:     (c) Institute of Technical Biocatalysis TUHH
# Licence:       GNU GPL-v3 
#-------------------------------------------------------------------------------
from pumps_new_era import pumps_new_era
import time

class PurgeSystem():

    def __init__(self,pump,nPumps,duration=300,rate=0.250):

        # Purges the system using nPumps. Works only, if the continous adresses starting from 1 are used.
        # Duration in seconds. Rate in ml/min.
        for i in range(1,nPumps+1):
            if i < 10:
                adr = '0'+str(i)
            else:
                adr = str(i)
            pump.setRate(adr,rate)
            pump.run(adr)
        time.sleep(duration)
        for j in range(4,nPumps+1):
            if j < 10:
                adr = '0'+str(j)
            else:
                adr = str(j)
            pump.stop(adr)

if __name__ =='__main__':
    pump = pumps_new_era()
    # Pumpenanzahl
    nPumps = 4

    # mit Standardeinstellungen
    #PurgeSystem(pump,nPumps)

    # mit spezifischen Einstellungen
    duration = 6000
    rate = 0.075
    PurgeSystem(pump,nPumps,duration,rate)