12
12
13
13
@dataclass
14
14
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
+
15
22
name : str
16
23
update_period : float = 0.2
17
24
@@ -29,16 +36,44 @@ async def update(
29
36
attr : AttrR ,
30
37
) -> None :
31
38
try :
39
+ # TODO: Async sleep?
32
40
response = await controller .connection .get (self .name )
33
41
await attr .set (response ["value" ])
34
42
except Exception as e :
35
43
print (f"update loop failed:{ e } " )
36
44
37
45
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
+
38
66
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" ),
42
77
)
43
78
44
79
def __init__ (self , settings : IPConnectionSettings ) -> None :
@@ -48,11 +83,31 @@ def __init__(self, settings: IPConnectionSettings) -> None:
48
83
asyncio .run (self .initialise ())
49
84
50
85
async def connect (self ) -> None :
86
+ """Connection settigns with Eiger Detector using HTTP"""
51
87
self .connection = HTTPConnection (
52
88
self ._ip_settings , headers = {"Content-Type" : "application/json" }
53
89
)
54
90
55
91
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
+ """
56
111
# Adding extra loop prior to backend loop creating the Attributes to be PVs
57
112
connection = HTTPConnection (
58
113
self ._ip_settings , headers = {"Content-Type" : "application/json" }
@@ -145,28 +200,53 @@ async def initialise(self) -> None:
145
200
await connection .close ()
146
201
147
202
async def close (self ) -> None :
203
+ """Closing HTTP connection with device"""
148
204
await self .connection .close ()
149
205
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
+
150
210
@command
151
211
async def initialize (self ):
212
+ """Command to initialize Detector - will create a PVI button"""
152
213
await self .connection .put ("detector/api/1.8.0/command/initialize" , "" )
153
214
154
215
@command
155
216
async def disarm (self ):
217
+ """Command to disarm Detector - will create a PVI button"""
156
218
await self .connection .put ("detector/api/1.8.0/command/disarm" , "" )
157
219
158
220
@command
159
221
async def abort (self ):
222
+ """Command to abort any tasks Detector - will create a PVI button"""
160
223
await self .connection .put ("detector/api/1.8.0/command/abort" , "" )
161
224
162
- @command
163
- async def arm (self ):
164
- await self .connection .put ("detector/api/1.8.0/command/arm" , "" )
165
-
166
225
@command
167
226
async def cancel (self ):
227
+ """Command to cancel readings from Detector - will create a PVI button"""
168
228
await self .connection .put ("detector/api/1.8.0/command/cancel" , "" )
169
229
170
230
@command
171
231
async def trigger (self ):
232
+ """
233
+ Command to trigger Detector when manual triggering is switched on.
234
+ will create a PVI button
235
+ """
172
236
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