diff --git a/socs/agents/hwp_pmx/agent.py b/socs/agents/hwp_pmx/agent.py index d52eb90e2..74e4fc4c6 100644 --- a/socs/agents/hwp_pmx/agent.py +++ b/socs/agents/hwp_pmx/agent.py @@ -58,6 +58,18 @@ class CancelShutdown(BaseAction): def process(self, module): self.log.info("Cancel shutdown...") + @dataclass + class CheckI(BaseAction): + def process(self, module): + msg, val = module.check_current() + self.log.info(msg + "...") + + @dataclass + class CheckV(BaseAction): + def process(self, module): + msg, val = module.check_voltage() + self.log.info(msg + "...") + @dataclass class SetI(BaseAction): curr: float @@ -74,12 +86,24 @@ def process(self, module): msg, val = module.set_voltage(self.volt) self.log.info(msg + "...") + @dataclass + class CheckILim(BaseAction): + def process(self, module): + msg, val = module.check_current_limit() + self.log.info(msg + "...") + + @dataclass + class CheckVLim(BaseAction): + def process(self, module): + msg, val = module.check_voltage_limit() + self.log.info(msg + "...") + @dataclass class SetILim(BaseAction): curr: float def process(self, module): - msg = module.set_current_limit(self.curr) + msg, val = module.set_current_limit(self.curr) self.log.info(msg + "...") @dataclass @@ -87,7 +111,7 @@ class SetVLim(BaseAction): volt: float def process(self, module): - msg = module.set_voltage_limit(self.volt) + msg, val = module.set_voltage_limit(self.volt) self.log.info(msg + "...") @@ -184,7 +208,27 @@ def ign_ext(self, session, params): return True, 'Set PMX Kikusui to direct control' @defer.inlineCallbacks - @ocs_agent.param('curr', default=0, type=float, check=lambda x: 0 <= x <= 3) + def check_i(self, session, params): + """check_i() + **Task** - Set the current setting. + """ + action = Actions.CheckI(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Check current is done' + + @defer.inlineCallbacks + def check_v(self, session, params): + """check_v() + **Task** - Set the voltage setting. + """ + action = Actions.CheckV(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Check voltage is done' + + @defer.inlineCallbacks + @ocs_agent.param('curr', default=0, type=float) def set_i(self, session, params): """set_i(curr=0) **Task** - Set the current. @@ -198,7 +242,7 @@ def set_i(self, session, params): return True, 'Set current is done' @defer.inlineCallbacks - @ocs_agent.param('volt', default=0, type=float, check=lambda x: 0 <= x <= 35) + @ocs_agent.param('volt', default=0, type=float) def set_v(self, session, params): """set_v(volt=0) **Task** - Set the voltage. @@ -212,9 +256,29 @@ def set_v(self, session, params): return True, 'Set voltage is done' @defer.inlineCallbacks - @ocs_agent.param('curr', default=1., type=float, check=lambda x: 0. <= x <= 3.) + def check_i_lim(self, session, params): + """check_i_lim() + **Task** - Check the current protection limit. + """ + action = Actions.CheckILim(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Check current protection limit is done' + + @defer.inlineCallbacks + def check_v_lim(self, session, params): + """check_v_lim() + **Task** - Check the voltage protection limit. + """ + action = Actions.CheckVLim(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Check voltage protection limit is done' + + @defer.inlineCallbacks + @ocs_agent.param('curr', default=1.3, type=float) def set_i_lim(self, session, params): - """set_i_lim(curr=1) + """set_i_lim(curr=1.3) **Task** - Set the drive current limit. Parameters: @@ -226,9 +290,9 @@ def set_i_lim(self, session, params): return True, 'Set voltage limit is done' @defer.inlineCallbacks - @ocs_agent.param('volt', default=32., type=float, check=lambda x: 0. <= x <= 35.) + @ocs_agent.param('volt', default=37., type=float) def set_v_lim(self, session, params): - """set_v_lim(volt=32) + """set_v_lim(volt=37) **Task** - Set the drive voltage limit. Parameters: @@ -475,8 +539,12 @@ def main(args=None): agent.register_task('set_on', PMX.set_on, blocking=False) agent.register_task('set_off', PMX.set_off, blocking=False) agent.register_task('clear_alarm', PMX.clear_alarm, blocking=False) + agent.register_task('check_i', PMX.check_i, blocking=False) + agent.register_task('check_v', PMX.check_v, blocking=False) agent.register_task('set_i', PMX.set_i, blocking=False) agent.register_task('set_v', PMX.set_v, blocking=False) + agent.register_task('check_i_lim', PMX.check_i_lim, blocking=False) + agent.register_task('check_v_lim', PMX.check_v_lim, blocking=False) agent.register_task('set_i_lim', PMX.set_i_lim, blocking=False) agent.register_task('set_v_lim', PMX.set_v_lim, blocking=False) agent.register_task('use_ext', PMX.use_ext, blocking=False) diff --git a/socs/agents/hwp_pmx/drivers/PMX_ethernet.py b/socs/agents/hwp_pmx/drivers/PMX_ethernet.py index f24816667..6637760e4 100644 --- a/socs/agents/hwp_pmx/drivers/PMX_ethernet.py +++ b/socs/agents/hwp_pmx/drivers/PMX_ethernet.py @@ -154,21 +154,29 @@ def ign_external_voltage(self): self.wait() return self.check_source() + def check_current_limit(self): + """ Check the PMX current protection limit """ + val = float(self.send_message(b'curr:prot?\n')) + msg = "Current protection limit = {:.3f} A".format(val) + return msg, val + + def check_voltage_limit(self): + """ Check the PMX voltage protection limit """ + val = float(self.send_message(b'volt:prot?\n')) + msg = "Voltage protection limit = {:.3f} V".format(val) + return msg, val + def set_current_limit(self, curr_lim): - """ Set the PMX current limit """ + """ Set the PMX current protection limit """ self.send_message(b'curr:prot %a\n' % curr_lim, read=False) self.wait() - val = float(self.send_message(b'curr:prot?\n')) - msg = "Current Limit: {:.3f} A".format(val) - return msg + return self.check_current_limit() def set_voltage_limit(self, vol_lim): - """ Set the PMX voltage limit """ + """ Set the PMX voltage protection limit """ self.send_message(b'volt:prot %a\n' % vol_lim, read=False) self.wait() - val = float(self.send_message(b'volt:prot?\n')) - msg = "Voltage Limit: {:.3f} V".format(val) - return msg + return self.check_voltage_limit() def check_prot(self): """ Check the protection status