diff --git a/docs/agents/hwp_pmx.rst b/docs/agents/hwp_pmx.rst index d462283a6..a72402bea 100644 --- a/docs/agents/hwp_pmx.rst +++ b/docs/agents/hwp_pmx.rst @@ -26,8 +26,8 @@ An example site-config-file block:: 'instance-id': 'hwp-pmx', 'arguments': [['--ip', '10.10.10.100'], ['--port', '5025'], - ['--mode', 'acq'], - ['--sampling-frequency', 1],]}, + ['--sampling-frequency', 1], + ['--supervisor-id', 'hwp-supervisor']]}, Docker Compose `````````````` diff --git a/socs/agents/hwp_pmx/agent.py b/socs/agents/hwp_pmx/agent.py index ada2a860a..0f670d578 100644 --- a/socs/agents/hwp_pmx/agent.py +++ b/socs/agents/hwp_pmx/agent.py @@ -1,16 +1,94 @@ import argparse -import os import time +from dataclasses import dataclass +from queue import Queue import txaio +from twisted.internet import defer, reactor, threads + +txaio.use_twisted() + from ocs import ocs_agent, site_config -from ocs.ocs_twisted import TimeoutLock -from twisted.internet import reactor import socs.agents.hwp_pmx.drivers.PMX_ethernet as pmx from socs.agents.hwp_supervisor.agent import get_op_data -txaio.use_twisted() + +class Actions: + class BaseAction: + def __post_init__(self): + self.deferred = defer.Deferred() + self.log = txaio.make_logger() + + def process(self, *args, **kwargs): + raise NotImplementedError + + @dataclass + class SetOn(BaseAction): + def process(self, module): + self.log.info("Setting PMX on...") + module.turn_on() + + @dataclass + class SetOff(BaseAction): + def process(self, module): + self.log.info("Setting PMX off...") + module.turn_off() + + @dataclass + class UseExt(BaseAction): + def process(self, module): + self.log.info("Setting PMX Kikusui to PID control...") + module.use_external_voltage() + + @dataclass + class IgnExt(BaseAction): + def process(self, module): + self.log.info("Setting PMX Kikusui to direct control...") + module.ign_external_voltage() + + @dataclass + class ClearAlarm(BaseAction): + def process(self, module): + self.log.info("Clear PMX alarm...") + module.clear_alarm() + + @dataclass + class CancelShutdown(BaseAction): + def process(self, module): + self.log.info("Cancel shutdown...") + + @dataclass + class SetI(BaseAction): + curr: float + + def process(self, module): + msg, val = module.set_current(self.curr) + self.log.info(msg + "...") + + @dataclass + class SetV(BaseAction): + volt: float + + def process(self, module): + msg, val = module.set_voltage(self.volt) + self.log.info(msg + "...") + + @dataclass + class SetILim(BaseAction): + curr: float + + def process(self, module): + msg = module.set_current_limit(self.curr) + self.log.info(msg + "...") + + @dataclass + class SetVLim(BaseAction): + volt: float + + def process(self, module): + msg = module.set_voltage_limit(self.volt) + self.log.info(msg + "...") class HWPPMXAgent: @@ -31,10 +109,10 @@ def __init__(self, agent, ip, port, f_sample=1, supervisor_id=None, self.agent: ocs_agent.OCSAgent = agent self.log = agent.log - self.lock = TimeoutLock() self.ip = ip self.port = port + self.action_queue = Queue() self.f_sample = f_sample @@ -52,83 +130,59 @@ def __init__(self, agent, ip, port, f_sample=1, supervisor_id=None, self.agent.register_feed('rotation_action', record=True) - @ocs_agent.param('auto_acquire', default=False, type=bool) - def init_connection(self, session, params=None): - """init_connection(auto_acquire=False) - **Task** - Initialize connection to PMX - - Parameters: - auto_acquire (bool, optional): Default is False. Starts data - acquisition after initialization if True. - """ - if self._initialized: - self.log.info("Connection already initialized. Returning...") - return True, "Connection already initialized" - - with self.lock.acquire_timeout(0, job='init_connection') as acquired: - if not acquired: - self.log.warn( - 'Could not run init_connection because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - try: - self.dev = pmx.PMX(ip=self.ip, port=self.port) - self.log.info('Connected to PMX Kikusui') - except BrokenPipeError: - self.log.error('Could not establish connection to PMX Kikusui') - reactor.callFromThread(reactor.stop) - return False, 'Unable to connect to PMX Kikusui' - - if params['auto_acquire']: - self.agent.start('acq') - - return True, 'Connection to PMX established' - + @defer.inlineCallbacks def set_on(self, session, params): """set_on() **Task** - Turn on the PMX Kikusui. """ - with self.lock.acquire_timeout(3, job='set_on') as acquired: - if not acquired: - self.log.warn( - 'Could not set on because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - if self.shutdown_mode: - return False, "Shutdown mode is in effect" - - self.dev.turn_on() + action = Actions.SetOn(**params) + self.action_queue.put(action) + session.data = yield action.deferred return True, 'Set PMX Kikusui on' + @defer.inlineCallbacks def set_off(self, session, params): """set_off() **Task** - Turn off the PMX Kikusui. """ - with self.lock.acquire_timeout(3, job='set_off') as acquired: - if not acquired: - self.log.warn( - 'Could not set on because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - if self.shutdown_mode: - return False, "Shutdown mode is in effect" - - self.dev.turn_off() + action = Actions.SetOff(**params) + self.action_queue.put(action) + session.data = yield action.deferred return True, 'Set PMX Kikusui off' + @defer.inlineCallbacks def clear_alarm(self, session, params): """clear_alarm() **Task** - Clear alarm and exit protection mode. """ - with self.lock.acquire_timeout(3, job='clear_alarm') as acquired: - if not acquired: - self.log.warn( - 'Could not clear alarm because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - self.dev.clear_alarm() - self.prot = 0 + action = Actions.ClearAlarm(**params) + self.action_queue.put(action) + session.data = yield action.deferred return True, 'Clear alarm' + @defer.inlineCallbacks + def use_ext(self, session, params): + """use_ext() + **Task** - Set the PMX Kikusui to use an external voltage control. Doing so + enables PID control. + """ + action = Actions.UseExt(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Set PMX Kikusui to PID control' + + @defer.inlineCallbacks + def ign_ext(self, session, params): + """ign_ext() + **Task** - Set the PMX Kiksui to ignore external voltage control. Doing so + disables the PID and switches to direct control. + """ + action = Actions.IgnExt(**params) + self.action_queue.put(action) + session.data = yield action.deferred + 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 set_i(self, session, params): """set_i(curr=0) @@ -137,18 +191,12 @@ def set_i(self, session, params): Parameters: curr (float): set current """ - with self.lock.acquire_timeout(3, job='set_i') as acquired: - if not acquired: - self.log.warn( - 'Could not set i because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - if self.shutdown_mode: - return False, "Shutdown mode is in effect" - - msg, val = self.dev.set_current(params['curr']) - return True, msg + action = Actions.SetI(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Set current is done' + @defer.inlineCallbacks @ocs_agent.param('volt', default=0, type=float, check=lambda x: 0 <= x <= 35) def set_v(self, session, params): """set_v(volt=0) @@ -157,18 +205,12 @@ def set_v(self, session, params): Parameters: volt (float): set voltage """ - with self.lock.acquire_timeout(3, job='set_v') as acquired: - if not acquired: - self.log.warn( - 'Could not set v because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - if self.shutdown_mode: - return False, "Shutdown mode is in effect" - - msg, val = self.dev.set_voltage(params['volt']) - return True, msg + action = Actions.SetV(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Set voltage is done' + @defer.inlineCallbacks @ocs_agent.param('curr', default=1., type=float, check=lambda x: 0. <= x <= 3.) def set_i_lim(self, session, params): """set_i_lim(curr=1) @@ -177,14 +219,12 @@ def set_i_lim(self, session, params): Parameters: curr (float): limit current """ - with self.lock.acquire_timeout(3, job='set_i_lim') as acquired: - if not acquired: - self.log.warn( - 'Could not set v lim because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - msg = self.dev.set_current_limit(params['curr']) - return True, msg + action = Actions.SetILim(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Set voltage limit is done' + @defer.inlineCallbacks @ocs_agent.param('volt', default=32., type=float, check=lambda x: 0. <= x <= 35.) def set_v_lim(self, session, params): """set_v_lim(volt=32) @@ -193,58 +233,40 @@ def set_v_lim(self, session, params): Parameters: volt (float): limit voltage """ - with self.lock.acquire_timeout(3, job='set_v_lim') as acquired: - if not acquired: - self.log.warn( - 'Could not set v lim because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - msg = self.dev.set_voltage_limit(params['volt']) - return True, msg + action = Actions.SetVLim(**params) + self.action_queue.put(action) + session.data = yield action.deferred + return True, 'Set current limit is done' - def use_ext(self, session, params): - """use_ext() - **Task** - Set the PMX Kikusui to use an external voltage control. Doing so - enables PID control. + @defer.inlineCallbacks + def initiate_shutdown(self, session, params): + """ initiate_shutdown() + **Task** - Initiate the shutdown of the agent. """ - with self.lock.acquire_timeout(3, job='use_ext') as acquired: - if not acquired: - self.log.warn( - 'Could not use external voltage because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - if self.shutdown_mode: - return False, "Shutdown mode is in effect" + self.log.warn("INITIATING SHUTDOWN") - self.dev.use_external_voltage() - return True, 'Set PMX Kikusui to PID control' + action = Actions.SetOff(**params) + self.action_queue.put(action) + session.data = yield action.deferred + self.shutdown_mode = True + return True, "Initiated shutdown mode" - def ign_ext(self, session, params): - """ign_ext() - **Task** - Set the PMX Kiksui to ignore external voltage control. Doing so - disables the PID and switches to direct control. + @defer.inlineCallbacks + def cancel_shutdown(self, session, params): + """cancel_shutdown() + **Task** - Cancels shutdown mode, allowing other tasks to update the power supply """ - with self.lock.acquire_timeout(3, job='ign_ext') as acquired: - if not acquired: - self.log.warn( - 'Could not ignore external voltage because {} is already running'.format(self.lock.job)) - return False, 'Could not acquire lock' - - if self.shutdown_mode: - return False, "Shutdown mode is in effect" - - self.dev.ign_external_voltage() - return True, 'Set PMX Kikusui to direct control' + action = Actions.CancelShutdown(**params) + self.action_queue.put(action) + session.data = yield action.deferred + self.shutdown_mode = False + return True, "Cancelled shutdown mode" - @ocs_agent.param('test_mode', default=False, type=bool) - def acq(self, session, params): - """acq(test_mode=False) + def main(self, session, params): + """main() **Process** - Start data acquisition. - Parameters: - test_mode (bool, optional): Run the Process loop only once. - This is meant only for testing. Default is False. - Notes: The most recent data collected is stored in session data in the structure:: @@ -256,106 +278,101 @@ def acq(self, session, params): 'last_updated': 1649085992.719602} """ - sleep_time = 1 / self.f_sample - 0.01 + PMX = None + session.set_status('running') - with self.lock.acquire_timeout(0, job='acq') as acquired: - if not acquired: - self.log.warn("Could not start acq because {} is already running" - .format(self.lock.job)) - return False, "Could not acquire lock." - - session.set_status('running') - self.take_data = True - - last_release = time.time() - while self.take_data: - current_time = time.time() - if current_time - last_release > 1.: - last_release = time.time() - if not self.lock.release_and_acquire(timeout=10): - self.log.warn(f"Failed to re-acquire lock, currently held by {self.lock.job}.") - continue - - data = { - 'timestamp': current_time, - 'block_name': 'hwppmx', - 'data': {} - } + threads.blockingCallFromThread(reactor, self._clear_queue) + sleep_time = 1 / self.f_sample - 0.01 + last_daq = 0 + while session.status in ['starting', 'running']: + if PMX is None: try: - msg, curr = self.dev.meas_current() - data['data']['current'] = curr - - msg, volt = self.dev.meas_voltage() - data['data']['voltage'] = volt - - msg, code = self.dev.check_error() - data['data']['err_code'] = code - data['data']['err_msg'] = msg - - prot_code = self.dev.check_prot() - if prot_code != 0: - self.prot = prot_code - - prot_msg = self.dev.get_prot_msg(self.prot) - data['data']['prot_code'] = self.prot - data['data']['prot_msg'] = prot_msg - - msg, src = self.dev.check_source() - data['data']['source'] = src - except BaseException: - time.sleep(sleep_time) + PMX = pmx.PMX(ip=self.ip, port=self.port) + except ConnectionRefusedError: + self.log.error( + "Could not connect to PMX. " + "Retrying after 30 sec..." + ) + time.sleep(30) continue - self.agent.publish_to_feed('hwppmx', data) - session.data = {'curr': curr, - 'volt': volt, - 'prot': self.prot, - 'prot_msg': prot_msg, - 'source': src, - 'last_updated': current_time} + now = time.time() + if now - last_daq > sleep_time: + self._get_and_publish_data(PMX, session) + last_daq = now - time.sleep(sleep_time) + self._process_actions(PMX) + time.sleep(0.1) - if params['test_mode']: - break + PMX.close() + return True, 'Stopped main' - self.agent.feeds['hwppmx'].flush_buffer() - - return True, 'Acquisition exited cleanly.' - - def _stop_acq(self, session, params=None): + def _stop_main(self, session, params): """ Stop acq process. """ - if self.take_data: - self.take_data = False - return True, 'requested to stop taking data.' - else: - return False, 'acq is not currently running' - - def initiate_shutdown(self, session, params): - """ initiate_shutdown() - - **Task** - Initiate the shutdown of the agent. - """ - self.log.warn("INITIATING SHUTDOWN") - - with self.lock.acquire_timeout(10, job='shutdown') as acquired: - if not acquired: - self.log.error("Could not acquire lock for shutdown.") - return False, "Could not acquire lock." - - self.shutdown_mode = True - self.dev.turn_off() - - def cancel_shutdown(self, session, params): - """cancel_shutdown() - - **Task** - Cancels shutdown mode, allowing other tasks to update the power supply - """ - self.shutdown_mode = False - return True, "Cancelled shutdown mode" + session.set_status('stopping') + return True, 'Set main status to stopping' + + def _process_actions(self, PMX: pmx.PMX): + while not self.action_queue.empty(): + action = self.action_queue.get() + if action.__class__.__name__ in ['SetOn', 'SetOff', 'SetI', 'SetV', 'UseExt', 'IgnExt']: + if self.shutdown_mode: + self.log.warn("Shutdown mode is in effect") + action.deferred.errback(Exception("Action cancelled by shutdown mode")) + return + try: + self.log.info(f"Running action {action}") + res = action.process(PMX) + reactor.callFromThread(action.deferred.callback, res) + except Exception as e: + self.log.error(f"Error processing action: {action}") + reactor.callFromThread(action.deferred.errback, e) + + def _clear_queue(self): + while not self.action_queue.empty(): + action = self.action_queue.get() + action.deferred.errback(Exception("Action cancelled")) + + def _get_and_publish_data(self, PMX: pmx.PMX, session): + now = time.time() + data = {'timestamp': now, + 'block_name': 'hwppmx', + 'data': {}} + + try: + msg, curr = PMX.meas_current() + data['data']['current'] = curr + + msg, volt = PMX.meas_voltage() + data['data']['voltage'] = volt + + msg, code = PMX.check_error() + data['data']['err_code'] = code + data['data']['err_msg'] = msg + + prot_code = PMX.check_prot() + if prot_code != 0: + self.prot = prot_code + + prot_msg = PMX.get_prot_msg(self.prot) + data['data']['prot_code'] = self.prot + data['data']['prot_msg'] = prot_msg + + msg, src = PMX.check_source() + data['data']['source'] = src + self.agent.publish_to_feed('hwppmx', data) + session.data = {'curr': curr, + 'volt': volt, + 'prot': self.prot, + 'prot_msg': prot_msg, + 'source': src, + 'last_updated': now} + except BaseException: + self.log.warn("Exception in getting data") + return def monitor_supervisor(self, session, params): """monitor_supervisor() @@ -427,9 +444,7 @@ def make_parser(parser=None): help="ip address for kikusui PMX") pgroup.add_argument('--port', type=int, help="port for kikusui PMX") - pgroup.add_argument('--mode', type=str, default='acq', choices=['init', 'acq'], - help="Starting action for the agent.") - pgroup.add_argument('--sampling-frequency', type=float, + pgroup.add_argument('--sampling-frequency', type=float, default=2., help="Sampling frequency for data acquisition") pgroup.add_argument('--supervisor-id', type=str, help="Instance ID for HWP Supervisor agent") @@ -440,42 +455,35 @@ def make_parser(parser=None): def main(args=None): - txaio.start_logging(level=os.environ.get("LOGLEVEL", "info")) - parser = make_parser() args = site_config.parse_args(agent_class='HWPPMXAgent', parser=parser, args=args) agent, runner = ocs_agent.init_site_agent(args) - if args.mode == 'init': - init_params = {'auto_acquire': False} - elif args.mode == 'acq': - init_params = {'auto_acquire': True} - - kwargs = {'ip': args.ip, 'port': args.port, - 'supervisor_id': args.supervisor_id, - 'no_data_timeout': args.no_data_timeout, } + kwargs = { + 'ip': args.ip, 'port': args.port, 'supervisor_id': args.supervisor_id, + 'no_data_timeout': args.no_data_timeout + } if args.sampling_frequency is not None: kwargs['f_sample'] = args.sampling_frequency PMX = HWPPMXAgent(agent, **kwargs) - agent.register_task('init_connection', PMX.init_connection, startup=init_params) - agent.register_process('acq', PMX.acq, PMX._stop_acq) + agent.register_process('main', PMX.main, PMX._stop_main, startup=True) agent.register_process( 'monitor_supervisor', PMX.monitor_supervisor, PMX._stop_monitor_supervisor, startup=True) - agent.register_task('set_on', PMX.set_on) - agent.register_task('set_off', PMX.set_off) - agent.register_task('clear_alarm', PMX.clear_alarm) - agent.register_task('set_i', PMX.set_i) - agent.register_task('set_v', PMX.set_v) - agent.register_task('set_i_lim', PMX.set_i_lim) - agent.register_task('set_v_lim', PMX.set_v_lim) - agent.register_task('use_ext', PMX.use_ext) - agent.register_task('ign_ext', PMX.ign_ext) - agent.register_task('initiate_shutdown', PMX.initiate_shutdown) - agent.register_task('cancel_shutdown', PMX.cancel_shutdown) + 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('set_i', PMX.set_i, blocking=False) + agent.register_task('set_v', PMX.set_v, 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) + agent.register_task('ign_ext', PMX.ign_ext, blocking=False) + agent.register_task('initiate_shutdown', PMX.initiate_shutdown, blocking=False) + agent.register_task('cancel_shutdown', PMX.cancel_shutdown, blocking=False) runner.run(agent, auto_reconnect=True) diff --git a/socs/agents/hwp_pmx/drivers/PMX_ethernet.py b/socs/agents/hwp_pmx/drivers/PMX_ethernet.py index 872719c31..f24816667 100644 --- a/socs/agents/hwp_pmx/drivers/PMX_ethernet.py +++ b/socs/agents/hwp_pmx/drivers/PMX_ethernet.py @@ -50,7 +50,7 @@ def send_message(self, msg, read=True): self.conn.sendall(msg) time.sleep(0.5) if read: - data = self.conn.recv(self.buffer_size).decode('utf-8') + data = self.conn.recv(self.buffer_size).strip().decode('utf-8') return data return except (socket.timeout, OSError): diff --git a/tests/default.yaml b/tests/default.yaml index de7cace0f..82c39d69d 100644 --- a/tests/default.yaml +++ b/tests/default.yaml @@ -48,7 +48,6 @@ hosts: 'instance-id': 'hwp-pmx', 'arguments': [['--ip', '127.0.0.1'], ['--port', '5025'], - ['--mode', 'init'], ] }, {'agent-class': 'CryomechCPAAgent', diff --git a/tests/integration/test_hwp_pmx_agent_integration.py b/tests/integration/test_hwp_pmx_agent_integration.py index 1da0bb16b..23bf35a97 100644 --- a/tests/integration/test_hwp_pmx_agent_integration.py +++ b/tests/integration/test_hwp_pmx_agent_integration.py @@ -2,7 +2,6 @@ import pytest from integration.util import docker_compose_file # noqa: F401 from integration.util import create_crossbar_fixture -from ocs.base import OpCode from ocs.testing import create_agent_runner_fixture, create_client_fixture from socs.testing.device_emulator import create_device_emulator @@ -15,6 +14,14 @@ client = create_client_fixture('hwp-pmx') kikusui_emu = create_device_emulator({}, relay_type='tcp', port=5025) +default_responses = { + 'meas:volt?': '2', + 'meas:curr?': '1', + ':system:error?': '+0,"No error"\n', + 'stat:ques?': '0', + 'volt:ext:sour?': 'source_name' +} + @pytest.mark.integtest def test_testing(wait_for_crossbar): @@ -22,140 +29,123 @@ def test_testing(wait_for_crossbar): assert True -# This ends up hanging for some reason that I can't figure out at the moment. -# @pytest.mark.integtest -# def test_hwp_pmx_failed_connection_kikusui(wait_for_crossbar, run_agent_idle, client): -# resp = client.init_connection.start() -# print(resp) -# # We can't really check anything here, the agent's going to exit during the -# # init_conneciton task because it cannot connect to the Kikusui. +@pytest.mark.integtest +def test_hwp_rotation_main(wait_for_crossbar, kikusui_emu, run_agent, client): + responses = default_responses.copy() + responses['meas:curr?'] = '1' + kikusui_emu.define_responses(responses) + client.main.stop() + resp = client.main.wait() + assert resp.session['data']['curr'] == 1.0 + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_set_on(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'output 1': '', - 'output?': '1'} + responses = default_responses.copy() + responses.update({ + 'output 1': '', + 'output?': '1' + }) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.set_on() print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_set_off(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'output 0': '', - 'output?': '0'} + responses = default_responses.copy() + responses.update({ + 'output 0': '', 'output?': '0' + }) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.set_off() print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_set_i(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'curr 1.000000': '', - 'curr?': '1.000000'} + responses = default_responses.copy() + responses.update({'curr 1.000000': '', + 'curr?': '1.000000'}) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.set_i(curr=1) print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_set_i_lim(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'curr:prot 2.000000': '', - 'curr:prot?': '2.000000'} + responses = default_responses.copy() + responses.update({'curr:prot 2.000000': '', + 'curr:prot?': '2.000000'}) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.set_i_lim(curr=2) print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_set_v(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'volt 1.000000': '', - 'volt?': '1.000000'} + responses = default_responses.copy() + responses.update({'volt 1.000000': '', + 'volt?': '1.000000'}) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.set_v(volt=1) print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_set_v_lim(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'volt:prot 10.000000': '', - 'volt:prot?': '10.000000'} + responses = default_responses.copy() + responses.update({ + 'volt:prot 10.0': '', + 'volt:prot?': '10.000000' + }) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.set_v_lim(volt=10) print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_use_ext(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'volt:ext:sour VOLT': '', - 'volt:ext:sour?': 'source_name'} + responses = default_responses.copy() + responses.update({'volt:ext:sour VOLT': '', + 'volt:ext:sour?': 'source_name'}) kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made resp = client.use_ext() print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.status == ocs.OK + assert resp.session['success'] @pytest.mark.integtest def test_hwp_rotation_ign_ext(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'volt:ext:sour NONE': '', - 'volt:ext:sour?': 'False'} + responses = default_responses.copy() + responses.update({'volt:ext:sour NONE': '', + 'volt:ext:sour?': 'False'}) kikusui_emu.define_responses(responses) - client.init_connection.wait() # wait for connection to be made resp = client.ign_ext() print(resp) - assert resp.status == ocs.OK print(resp.session) - assert resp.session['op_code'] == OpCode.SUCCEEDED.value - - -@pytest.mark.integtest -def test_hwp_rotation_acq(wait_for_crossbar, kikusui_emu, run_agent, client): - responses = {'meas:volt?': '2', - 'meas:curr?': '1', - ':system:error?': '+0,"No error"\n', - 'stat:ques?': '0', - 'volt:ext:sour?': 'source_name'} - kikusui_emu.define_responses(responses) - - client.init_connection.wait() # wait for connection to be made - resp = client.acq.start(test_mode=True) - assert resp.status == ocs.OK - - resp = client.acq.wait(timeout=20) assert resp.status == ocs.OK - assert resp.session['op_code'] == OpCode.SUCCEEDED.value + assert resp.session['success']