From bcad769329b3f704a4e1cdafe2bb4204f49c1ef8 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sun, 19 Apr 2020 19:34:55 +0000 Subject: [PATCH] - raise exception i case hendi cannot be enabled git-svn-id: http://moon:8086/svn/projects/HendiControl@369 fda53097-d464-4ada-af97-ba876c37ca34 --- Control/brewpi/controller.py | 58 ++++++++++++++++++------------------ Control/brewpi/hendiCtrl.py | 4 +-- Control/brewpi/plant.py | 20 +++++++++---- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/Control/brewpi/controller.py b/Control/brewpi/controller.py index 84f34bb..da303f4 100644 --- a/Control/brewpi/controller.py +++ b/Control/brewpi/controller.py @@ -174,37 +174,37 @@ class Controller(TimerListener): try: msg = self.queue.get(block=True, timeout=wait) print ("Received: ", msg) - if msg == commands.PAUSE: - pass - - elif msg == commands.RUN: - if not self.processTimer.isActive: - self.fp_log = open(self.receipe['Name'] + '.log', "w") - self.time = 0 - self.rast_index = 0 - self.reportTimer.start(self.report_interval) - self.processTimer.start(self.dt / self.sim_warp_factor) - - # Stirrer and plant - self.stirrer.activate() - self.plant.activate(True) - self.stirrer.setCycleTime(self.stirrCycleTime) - self.receipe_done = False - else: - self.rast_index += 1 - self.rast_done = False - self.ovenState = ovenStates.IDLE - - elif msg == commands.ABORT: - run = False - - elif msg == commands.STIRR_ON: - self.stirrer.activate() - - elif msg == commands.STIRR_OFF: - self.stirrer.deactivate() except: + continue + + if msg == commands.PAUSE: pass + elif msg == commands.RUN: + self.stirrer.activate() + self.plant.activate(True) + if not self.processTimer.isActive: + self.fp_log = open(self.receipe['Name'] + '.log', "w") + self.time = 0 + self.rast_index = 0 + self.reportTimer.start(self.report_interval) + self.processTimer.start(self.dt / self.sim_warp_factor) + + # Stirrer and plant + self.stirrer.setCycleTime(self.stirrCycleTime) + self.receipe_done = False + else: + self.rast_index += 1 + self.rast_done = False + self.ovenState = ovenStates.IDLE + + elif msg == commands.ABORT: + run = False + + elif msg == commands.STIRR_ON: + self.stirrer.activate() + + elif msg == commands.STIRR_OFF: + self.stirrer.deactivate() # Stirrer and plant self.stirrer.deactivate() diff --git a/Control/brewpi/hendiCtrl.py b/Control/brewpi/hendiCtrl.py index 60b880c..5e8cd85 100644 --- a/Control/brewpi/hendiCtrl.py +++ b/Control/brewpi/hendiCtrl.py @@ -114,9 +114,9 @@ class HendiCtrl(): self.__write(req) rsp = self.__read() if "OK" not in rsp[0]: - raise Exception("Command not accepted ({})".format(rsp[1])) + raise Exception(rsp[1]) - return rsp[1] + return rsp[1] == '1' def getCapabilties(self): return self.caps diff --git a/Control/brewpi/plant.py b/Control/brewpi/plant.py index 8f832fc..3b3d2ca 100644 --- a/Control/brewpi/plant.py +++ b/Control/brewpi/plant.py @@ -16,16 +16,24 @@ class Plant(APlant): self.cycleCounter = 0 def activate(self, enable=True): - if enable == True: - self.heater.remoteEnable(enable) - self.heater.setSwitch(enable) + if enable: if not self.heater.isRemoteEnable(): - raise Exception ("Heater: Cannot enable remote mode!") - else: + try: + self.heater.remoteEnable(enable) + except: + raise Exception("Error: Could not activate heater!") self.heater.setSwitch(enable) - self.heater.remoteEnable(enable) + print ("Plant activated") + else: + if self.heater.isRemoteEnable(): + self.heater.setSwitch(enable) + self.heater.remoteEnable(enable) + print ("Plant deactivated") def process(self, dt=1): + if not self.heater.isRemoteEnable(): + return + isOn = self.isOn self.cycleCounter += dt if self.cycleCounter >= self.cycleTime: