From 39428375bc0928b12e6e51b898cc57220fc7e292 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 9 Aug 2023 14:56:31 -0400 Subject: [PATCH 1/5] add query task for sample heater output --- socs/agents/lakeshore372/agent.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/socs/agents/lakeshore372/agent.py b/socs/agents/lakeshore372/agent.py index f7793f4a1..6c902b3c4 100644 --- a/socs/agents/lakeshore372/agent.py +++ b/socs/agents/lakeshore372/agent.py @@ -14,6 +14,9 @@ from socs.Lakeshore.Lakeshore372 import LS372 +heater_display_key = {'1': 'current', + '2': 'power'} + def still_power_to_perc(power, res, lead, max_volts): cur = np.sqrt(power / res) @@ -461,6 +464,32 @@ def set_heater_range(self, session, params): return True, f'Set {heater_string} heater range to {params["range"]}' + @ocs_agent.param('_') + def get_sample_output(self, session, params): + """get_heater_range(heater) + + **Task** - Query the heater range for servoing cryostat. + + Parameters: + heater (str): Name of heater to get range for, either 'sample' or + 'still'. + + """ + with self._lock.acquire_timeout(job='get_sample_output') as acquired: + if not acquired: + self.log.warn(f"Could not start Task because " + f"{self._lock.job} is already running") + return False, "Could not acquire lock" + + session.set_status('running') + + heater_perc = self.module.sample_heater.get_sample_heater_output() + heater_settings = self.module.sample_heater.get_heater_setup() + res = float(heater_settings[0]) + display_mode = heater_display_key[heater_settings[3]] + + return True, 'Sample heater res {} ohms, display mode set to {} at {}%'.format(res, display_mode, heater_perc) + @ocs_agent.param('channel', type=int, check=lambda x: 1 <= x <= 16) @ocs_agent.param('mode', type=str, choices=['current', 'voltage']) def set_excitation_mode(self, session, params): @@ -1442,6 +1471,7 @@ def main(args=None): agent.register_task('set_heater_output', lake_agent.set_heater_output) agent.register_task('set_still_output', lake_agent.set_still_output) agent.register_task('get_still_output', lake_agent.get_still_output) + agent.register_task('get_sample_output', lake_agent.get_sample_output) agent.register_process('acq', lake_agent.acq, lake_agent._stop_acq) agent.register_process('custom_pid', lake_agent.custom_pid, lake_agent._stop_custom_pid) agent.register_task('enable_control_chan', lake_agent.enable_control_chan) From 0139fe86cdee79d2f2a2758ba3f9b959c31dca6c Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Mon, 14 Aug 2023 16:13:35 -0400 Subject: [PATCH 2/5] fix get_sample_output() task docstring --- socs/agents/lakeshore372/agent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socs/agents/lakeshore372/agent.py b/socs/agents/lakeshore372/agent.py index 6c902b3c4..1e0d06924 100644 --- a/socs/agents/lakeshore372/agent.py +++ b/socs/agents/lakeshore372/agent.py @@ -466,7 +466,7 @@ def set_heater_range(self, session, params): @ocs_agent.param('_') def get_sample_output(self, session, params): - """get_heater_range(heater) + """get_sample_output() **Task** - Query the heater range for servoing cryostat. From f977536a74c57eeba02170708ee7246d9c4e1312 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Tue, 15 Aug 2023 16:53:50 -0400 Subject: [PATCH 3/5] add session.data to get_sample_output() --- socs/agents/lakeshore372/agent.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/socs/agents/lakeshore372/agent.py b/socs/agents/lakeshore372/agent.py index 1e0d06924..ccada8329 100644 --- a/socs/agents/lakeshore372/agent.py +++ b/socs/agents/lakeshore372/agent.py @@ -468,11 +468,15 @@ def set_heater_range(self, session, params): def get_sample_output(self, session, params): """get_sample_output() - **Task** - Query the heater range for servoing cryostat. + **Task** - Query sample heater ouput (res, display mode, output in %) + for servoing cryostat. - Parameters: - heater (str): Name of heater to get range for, either 'sample' or - 'still'. + Notes: + The sample heater output is stored in the session data + object in the format:: + + >>> response.session['data'] + {"sample_resistance": 1000} """ with self._lock.acquire_timeout(job='get_sample_output') as acquired: @@ -488,6 +492,10 @@ def get_sample_output(self, session, params): res = float(heater_settings[0]) display_mode = heater_display_key[heater_settings[3]] + session.data = {"sample_resistance": res, + "display_mode": display_mode, + "heater_power_percent": heater_perc} + return True, 'Sample heater res {} ohms, display mode set to {} at {}%'.format(res, display_mode, heater_perc) @ocs_agent.param('channel', type=int, check=lambda x: 1 <= x <= 16) From 539fd8f712d78d33c2c10316059866a593a039b1 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Tue, 15 Aug 2023 17:02:01 -0400 Subject: [PATCH 4/5] add session.data structure in docstring --- socs/agents/lakeshore372/agent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/socs/agents/lakeshore372/agent.py b/socs/agents/lakeshore372/agent.py index ccada8329..3e2d3645b 100644 --- a/socs/agents/lakeshore372/agent.py +++ b/socs/agents/lakeshore372/agent.py @@ -476,7 +476,9 @@ def get_sample_output(self, session, params): object in the format:: >>> response.session['data'] - {"sample_resistance": 1000} + {'sample_resistance': 1020.0, + 'display_mode': 'current', + 'heater_power_percent': 0.0005} """ with self._lock.acquire_timeout(job='get_sample_output') as acquired: From 25e124b0f34dca7ab3070261cf4c1e3e05ef2a47 Mon Sep 17 00:00:00 2001 From: sanahabhimani Date: Wed, 16 Aug 2023 14:54:04 -0400 Subject: [PATCH 5/5] add test for get_sample_output() task --- tests/integration/test_ls372_agent_integration.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/integration/test_ls372_agent_integration.py b/tests/integration/test_ls372_agent_integration.py index 5fda1df15..7e5ace2fa 100644 --- a/tests/integration/test_ls372_agent_integration.py +++ b/tests/integration/test_ls372_agent_integration.py @@ -257,6 +257,14 @@ def test_ls372_get_input_setup(wait_for_crossbar, emulator, run_agent, client): assert resp.session['op_code'] == OpCode.SUCCEEDED.value +@pytest.mark.integtest +def test_ls372_get_sample_output(wait_for_crossbar, emulator, run_agent, client): + client.init_lakeshore() + resp = client.get_sample_output() + assert resp.status == ocs.OK + assert resp.session['op_code'] == OpCode.SUCCEEDED.value + + @pytest.mark.integtest def test_ls372_sample_custom_pid(wait_for_crossbar, emulator, run_agent, client): client.init_lakeshore()