def startDose(doseLength, waitTime): if(shouldDose == True): doseLock = True t0 = Utility.currentTimeMillis() #set dig output pin to start dosing try: ik.interfaceKit.setOutputState(0, 1) except PhidgetException as e: doseLock = False ik.interfaceKit.setOutputState(0, 0) print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) print("setting dig output to 1") # dose until the dose time is met or something else releases the lock while((Utility.currentTimeMillis() - t0) < timeToDose * 1000 or doseLock != True): Time.sleep(0.1) try: ik.interfaceKit.setOutputState(0, 0) doseLock = False print("dosed for %i second out put changed to 0" % (timeToDose)) except PhidgetException as e: doseLock = False print("Phidget Exception %i: %s" % (e.code, e.details)) print("Exiting....") exit(1) doseLock = False
def updateVars(self, g): self.time = Utility.currentTimeMillis() self.currentPh = g.currentPh self.currentTemp = g.currentTemp self.doseTime = g.doseTime self.concentration = g.concentration self.flowRate = g.flowRate self.waitTime = g.waitTime
def interfaceKitSensorChanged(self, e): source = e.device index = e.index self.currentTime = Utility.currentTimeMillis() if(self.firstAttach == False): self.firstAttach = True return True elif(self.calibrationMode == True): print("calibration mode") elif(self.calibrationMode == False): if(index == 1): self.currentTemp = Utility.calculateTemp(e.value) print("Temp Sensor %i: Sensor %i: %i" % (source.getSerialNum(), e.index, e.value)) print("Temp = %i " + str(self.currentTemp)) if(index == 0 and self.currentTemp != None): self.currentPh = Utility.calculatePh(e.value) print("pH level is " + str(self.currentPh)) # logValues(self, time, phLevel, temp, doseTime, concentration, waitTime): self.control.updateGlobalVars(self.currentPh, self.currentTemp) else: print("No mode was set so I'm gonna do nothing") return False
def __init__(self): # Vars self.minPh = 5.8 self.maxPh = 6.2 self.doseTime = 20 self.currentPh = None self.currentTemp = None self.currentTime = Utility.currentTimeMillis() self.flowRate = 30 # doseLock is to prevent from running two dosing threads at once and can kill the dosing period if ph level is reached # shouldDose is to initiate dosing self.doseLock = False self.shouldDose = False # calibration mode or logging mode self.calibrationMode = False # sampling length in milliseconds self.phSamplingLength = 10000 self.concentration = 2.5 # dose length in seconds self.doseLength = 30 # waiting time for propogation in seconds self.waitTime = 20 # interval for checking ph level in milliseconds # must be a multiple of 8 I.E. 1,2,4,8,16,24,32, self.phCheckInterval = 64 # digital output pin index for valveIndex # temp callibration # celsius = (analog +20)/(0.2825) self.celsiusCoefficient = 3.5172 self.celsiusIntercept = 71.6 self.changed = False self.shutdown = False
def initializeComponents(self): logFileName = datetime.datetime.fromtimestamp(int(Utility.currentTimeSeconds())).strftime('%Y%m%d:%H:%M:%S') + ".csv" self.logger = PhLogger(os.path.join(os.path.dirname(__file__), logFileName)) self.loggerThread = LoggerThread(self.logger, threading.Event(), self.g) self.setupInterfaceKit()