Skip to content

Commit

Permalink
Merge pull request #3 from simonsobs/koopman/UTAustin
Browse files Browse the repository at this point in the history
Various fixes for tests
  • Loading branch information
CAWNoodle authored Sep 16, 2024
2 parents 4d14a27 + 1e4467f commit 869810b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
15 changes: 10 additions & 5 deletions socs/agents/scpi_psu/agent.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import argparse
import os
import socket
import time
from typing import Optional

import txaio
from ocs import ocs_agent, site_config
from ocs.ocs_twisted import TimeoutLock

from socs.agents.scpi_psu.drivers import PsuInterface, ScpiPsuInterface

# For logging
txaio.use_twisted()


class ScpiPsuAgent:
def __init__(self, agent, ip_address, gpib_slot=None, port=None):
Expand Down Expand Up @@ -77,16 +82,13 @@ def init(self, session, params=None):

self.log.info("Connected to psu: {}".format(self.idn))

session.add_message('Initialized PSU.')
auto_acquire = params.get('auto_acquire', False)

if auto_acquire:
acq_params = None
if self.psu.num_channels == 1:
acq_params = {'channels': [1]}
if self.psu.num_channels != 0:
acq_params = {'channels': [i + 1 for i in range(self.psu.num_channels)]}
self.agent.start('monitor_output', acq_params)
# while not self._initialize_module():
# time.sleep(5)
return True, 'Initialized PSU.'

def _initialize_module(self):
Expand Down Expand Up @@ -375,6 +377,9 @@ def make_parser(parser=None):


def main(args=None):
# Start logging
txaio.start_logging(level=os.environ.get("LOGLEVEL", "info"))

parser = make_parser()
args = site_config.parse_args(agent_class='ScpiPsuAgent',
parser=parser,
Expand Down
1 change: 1 addition & 0 deletions socs/agents/scpi_psu/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def clear(self):
class PsuInterface(PrologixInterface):
def __init__(self, ip_address, gpibAddr, verbose=False, **kwargs):
self.verbose = verbose
self.num_channels = 0
super().__init__(ip_address, gpibAddr, **kwargs)

def enable(self, ch):
Expand Down
3 changes: 2 additions & 1 deletion tests/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ hosts:
{'agent-class': 'ScpiPsuAgent',
'instance-id': 'psuK',
'arguments': [['--ip-address', '127.0.0.1'],
['--gpib-slot', '1']
['--gpib-slot', '1'],
['--mode', 'init']
]
},
{'agent-class': 'PfeifferAgent',
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_scpi_psu_agent_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
"scpi_psu_agent",
args=["--log-dir", "./logs/"],
)
run_agent_acq = create_agent_runner_fixture(
"../socs/agents/scpi_psu/agent.py",
"scpi_psu_agent",
args=["--log-dir", "./logs/",
"--mode", "acq"],
)
client = create_client_fixture("psuK")
gpib_emu = create_device_emulator(
{
Expand All @@ -37,6 +43,12 @@ def test_scpi_psu_init_psu(wait_for_crossbar, gpib_emu, run_agent, client):
check_resp_success(resp)


@pytest.mark.integtest
def test_scpi_psu_init_psu_acq_mode(wait_for_crossbar, gpib_emu, run_agent_acq, client):
resp = client.init.status()
check_resp_success(resp)


@pytest.mark.integtest
def test_scpi_psu_set_output(wait_for_crossbar, gpib_emu, run_agent, client):
client.init()
Expand Down Expand Up @@ -64,6 +76,7 @@ def test_scpi_psu_set_voltage(wait_for_crossbar, gpib_emu, run_agent, client):
@pytest.mark.integtest
def test_scpi_psu_monitor_output(wait_for_crossbar, gpib_emu, run_agent, client):
responses = {
"CHAN:OUTP:STAT?": "1",
"MEAS:VOLT? CH1": "3.14",
"MEAS:CURR? CH1": "6.28",
"MEAS:VOLT? CH2": "2.72",
Expand All @@ -77,3 +90,7 @@ def test_scpi_psu_monitor_output(wait_for_crossbar, gpib_emu, run_agent, client)
resp = client.monitor_output.start(test_mode=True, wait=0)
resp = client.monitor_output.wait()
check_resp_success(resp)

# stop process, else test hangs on auto-reconnection
client.monitor_output.stop()
client.monitor_output.wait()

0 comments on commit 869810b

Please sign in to comment.