@@ -35,6 +35,11 @@ async def update(
35
35
36
36
37
37
class EigerController (Controller ):
38
+ detector_state = AttrR (
39
+ String (),
40
+ handler = EigerHandler ("detector/api/1.8.0/status/state" ),
41
+ )
42
+
38
43
def __init__ (self , settings : IPConnectionSettings ) -> None :
39
44
super ().__init__ ()
40
45
self ._ip_settings = settings
@@ -80,8 +85,11 @@ async def initialise(self) -> None:
80
85
case _:
81
86
print (f"Could not process { parameter_name } " )
82
87
83
- # finding appropriate naming to ensure repeats are not ovewritten
84
- if parameter_name in list (attributes .keys ()):
88
+ # finding appropriate naming to ensure repeats are not ovewritten and ensuring that PV has not been created already
89
+ if (
90
+ parameter_name in list (attributes .keys ())
91
+ and parameter_name not in self .__dict__ .keys ()
92
+ ):
85
93
# Adding original instance of the duplicate into dictionary to rename original instance in attributes later
86
94
if parameter_name not in list (pv_clashes .keys ()):
87
95
pv_clashes [
@@ -108,14 +116,28 @@ async def initialise(self) -> None:
108
116
),
109
117
)
110
118
111
- # Renaming original instance of duplicate in Attribute
119
+ # Renaming original instance of duplicate in Attribute / Removing unique names already created
112
120
for clash_name , unique_name in pv_clashes .items ():
113
- attributes [unique_name ] = attributes .pop (clash_name )
114
- print (f"Replacing the repeat,{ clash_name } , with { unique_name } " )
121
+ if unique_name in self .__dict__ .keys ():
122
+ del attributes [clash_name ]
123
+ print (
124
+ f"{ unique_name } was already created before, { clash_name } is being deleted"
125
+ )
126
+
127
+ else :
128
+ attributes [unique_name ] = attributes .pop (clash_name )
129
+ print (f"Replacing the repeat,{ clash_name } , with { unique_name } " )
115
130
116
131
for name , attribute in attributes .items ():
117
132
setattr (self , name , attribute )
118
133
134
+ # Check current state of detector_state to see if initializing is required.
135
+ detector_state_val = await connection .get (self .detector_state .updater .name )
136
+ if detector_state_val ["value" ] == "na" :
137
+ print ("Initializing Detector" )
138
+ await connection .put ("detector/api/1.8.0/command/initialize" , "" )
139
+
140
+ a = 1
119
141
await connection .close ()
120
142
121
143
async def close (self ) -> None :
0 commit comments