Skip to content

Commit e80b503

Browse files
committed
Update to new Backend API
Remove asyncio.run in EigerController __init__
1 parent 03c7030 commit e80b503

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

src/eiger_fastcs/__main__.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from fastcs.backends.asyncio_backend import AsyncioBackend
66
from fastcs.backends.epics.backend import EpicsBackend
77
from fastcs.backends.epics.gui import EpicsGUIOptions
8-
from fastcs.mapping import Mapping
98

109
from eiger_fastcs import __version__
1110
from eiger_fastcs.eiger_controller import EigerController
@@ -51,27 +50,21 @@ def ioc(
5150
):
5251
ui_path = OPI_PATH if OPI_PATH.is_dir() else Path.cwd()
5352

54-
mapping = get_controller_mapping(ip, port)
53+
controller = EigerController(ip, port)
5554

56-
backend = EpicsBackend(mapping, pv_prefix)
55+
backend = EpicsBackend(controller, pv_prefix)
5756
backend.create_gui(
5857
EpicsGUIOptions(output_path=ui_path / "eiger.bob", title=f"Eiger - {pv_prefix}")
5958
)
60-
backend.get_ioc().run()
59+
backend.run()
6160

6261

6362
@app.command()
6463
def asyncio(ip: str = EigerIp, port: int = EigerPort):
65-
mapping = get_controller_mapping(ip, port)
66-
67-
backend = AsyncioBackend(mapping)
68-
backend.run_interactive_session()
69-
70-
71-
def get_controller_mapping(ip: str, port: int) -> Mapping:
7264
controller = EigerController(ip, port)
7365

74-
return Mapping(controller)
66+
backend = AsyncioBackend(controller)
67+
backend.run_interactive_session()
7568

7669

7770
# test with: python -m eiger_fastcs

src/eiger_fastcs/eiger_controller.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from typing import Any, Literal
77

88
import numpy as np
9-
from attr import Attribute
10-
from fastcs.attributes import AttrR, AttrRW, AttrW
9+
from fastcs.attributes import Attribute, AttrR, AttrRW, AttrW
1110
from fastcs.controller import Controller
1211
from fastcs.datatypes import Bool, Float, Int, String
1312
from fastcs.wrappers import command, scan
@@ -177,14 +176,6 @@ def __init__(self, ip: str, port: int) -> None:
177176
self._parameter_updates: set[str] = set()
178177
self._parameter_update_lock = asyncio.Lock()
179178

180-
# Initialize parameters from hardware - run on ephemeral asyncio loop
181-
# TODO: Make the backend asyncio loop available earlier
182-
asyncio.run(self.initialise())
183-
184-
async def connect(self) -> None:
185-
"""Reopen connection on backend asyncio loop"""
186-
self.connection.open()
187-
188179
async def initialise(self) -> None:
189180
"""Create attributes by introspecting detector.
190181
@@ -197,7 +188,7 @@ async def initialise(self) -> None:
197188
state_val = await self.connection.get("detector/api/1.8.0/status/state")
198189
if state_val["value"] == "na":
199190
print("Initializing Detector")
200-
await self.connection.put("detector/api/1.8.0/command/initialize")
191+
await self.initialize()
201192

202193
try:
203194
parameters = await self._introspect_detector()
@@ -210,8 +201,6 @@ async def initialise(self) -> None:
210201
for name, attribute in attributes.items():
211202
setattr(self, name, attribute)
212203

213-
await self.connection.close()
214-
215204
async def _introspect_detector(self) -> list[EigerParameter]:
216205
parameters = []
217206
for subsystem, mode in product(
@@ -302,10 +291,6 @@ def _tag_key_clashes(parameters: list[EigerParameter]):
302291
other.has_unique_key = False
303292
break
304293

305-
async def close(self) -> None:
306-
"""Closing HTTP connection with device"""
307-
await self.connection.close()
308-
309294
@detector_command
310295
async def initialize(self):
311296
await self.connection.put(command_uri("initialize"))

tests/system/test_introspection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def test_introspection(sim_eiger_controller: EigerController):
6565
controller = sim_eiger_controller
6666
# controller = eiger_controller
6767

68-
await controller.connect()
68+
controller.connection.open()
6969
_parameters = await controller._introspect_detector()
7070
controller._tag_key_clashes(_parameters)
7171
parameters = {p.name: _serialise_parameter(p) for p in _parameters}
@@ -78,4 +78,4 @@ async def test_introspection(sim_eiger_controller: EigerController):
7878

7979
assert parameters == expected_parameters, "Detector API does not match"
8080

81-
await controller.close()
81+
await controller.connection.close()

0 commit comments

Comments
 (0)