Skip to content

Commit 642f396

Browse files
committed
Add Commands
1 parent 6ea88a6 commit 642f396

File tree

1 file changed

+87
-7
lines changed

1 file changed

+87
-7
lines changed

src/eiger_fastcs/eiger_controller.py

Lines changed: 87 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313
@dataclass
1414
class EigerHandler:
15+
"""
16+
Handler for FastCS Attribute Creation
17+
18+
Dataclass that is called using the AttrR, AttrRW function.
19+
Handler uses uri of detector to collect data for PVs
20+
"""
21+
1522
name: str
1623
update_period: float = 0.2
1724

@@ -29,16 +36,44 @@ async def update(
2936
attr: AttrR,
3037
) -> None:
3138
try:
39+
# TODO: Async sleep?
3240
response = await controller.connection.get(self.name)
3341
await attr.set(response["value"])
3442
except Exception as e:
3543
print(f"update loop failed:{e}")
3644

3745

46+
@dataclass
47+
class LogicHandler:
48+
"""
49+
Handler for FastCS Attribute Creation
50+
51+
Dataclass that is called using the AttrR, AttrRW function.
52+
Used for dynamically created attributes that are added for additional logic
53+
"""
54+
55+
name: str
56+
57+
async def put(
58+
self,
59+
controller: "EigerController",
60+
attr: AttrW,
61+
value: Any,
62+
) -> None:
63+
await attr.set(value)
64+
65+
3866
class EigerController(Controller):
39-
detector_state = AttrR(
40-
String(),
41-
handler=EigerHandler("detector/api/1.8.0/status/state"),
67+
"""
68+
Controller Class for Eiger Detector
69+
70+
Used for dynamic creation of variables useed in logic of the EigerFastCS backend.
71+
Sets up all connections with the Simplon API to send and receive information
72+
"""
73+
74+
manual_trigger = AttrRW(
75+
Bool(),
76+
handler=LogicHandler("manual trigger"),
4277
)
4378

4479
def __init__(self, settings: IPConnectionSettings) -> None:
@@ -48,11 +83,31 @@ def __init__(self, settings: IPConnectionSettings) -> None:
4883
asyncio.run(self.initialise())
4984

5085
async def connect(self) -> None:
86+
"""Connection settigns with Eiger Detector using HTTP"""
5187
self.connection = HTTPConnection(
5288
self._ip_settings, headers={"Content-Type": "application/json"}
5389
)
5490

5591
async def initialise(self) -> None:
92+
"""
93+
Method to create all PVs from the tickit-devices simulator/device at startup
94+
Initialises the detector at the end of PV creation
95+
96+
Where to find PVs created in tickit-devices.
97+
detector-status: eiger_status.py
98+
detector-config: eiger_settings.py
99+
stream-status: stream_status.py
100+
stream-config: stream_config.py
101+
monitor-status: monitor_status.py
102+
monitor-config: monitor_config.py
103+
104+
Populates all PVs set in simulator/device in attributes dictionary
105+
(Name of PV, FastCS Attribute) after checking for any clashes with
106+
other subsystems and if the PV has already been created in the self
107+
dictionary keys.
108+
109+
Initialises detector on startup.
110+
"""
56111
# Adding extra loop prior to backend loop creating the Attributes to be PVs
57112
connection = HTTPConnection(
58113
self._ip_settings, headers={"Content-Type": "application/json"}
@@ -145,28 +200,53 @@ async def initialise(self) -> None:
145200
await connection.close()
146201

147202
async def close(self) -> None:
203+
"""Closing HTTP connection with device"""
148204
await self.connection.close()
149205

206+
async def arm(self):
207+
"""Arming Detector called by the start acquisition button"""
208+
await self.connection.put("detector/api/1.8.0/command/arm", "")
209+
150210
@command
151211
async def initialize(self):
212+
"""Command to initialize Detector - will create a PVI button"""
152213
await self.connection.put("detector/api/1.8.0/command/initialize", "")
153214

154215
@command
155216
async def disarm(self):
217+
"""Command to disarm Detector - will create a PVI button"""
156218
await self.connection.put("detector/api/1.8.0/command/disarm", "")
157219

158220
@command
159221
async def abort(self):
222+
"""Command to abort any tasks Detector - will create a PVI button"""
160223
await self.connection.put("detector/api/1.8.0/command/abort", "")
161224

162-
@command
163-
async def arm(self):
164-
await self.connection.put("detector/api/1.8.0/command/arm", "")
165-
166225
@command
167226
async def cancel(self):
227+
"""Command to cancel readings from Detector - will create a PVI button"""
168228
await self.connection.put("detector/api/1.8.0/command/cancel", "")
169229

170230
@command
171231
async def trigger(self):
232+
"""
233+
Command to trigger Detector when manual triggering is switched on.
234+
will create a PVI button
235+
"""
172236
await self.connection.put("detector/api/1.8.0/command/trigger", "")
237+
238+
@command
239+
async def start_acquisition(self):
240+
"""
241+
Command to start acquiring detector image.
242+
243+
Iterates through arming and triggering the detector if manual trigger off.
244+
If manual triggers are on, it arms the detector, ready for triggering.
245+
"""
246+
await self.arm()
247+
# Current functionality is for ints triggering and multiple ntriggers for
248+
# automatic triggering
249+
if not self.manual_trigger._value:
250+
for i in range(self.ntrigger._value):
251+
print(f"Acquisition number: {i+1}")
252+
await self.trigger()

0 commit comments

Comments
 (0)