forked from NSLS-II/lsdc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmx_annealer.py
168 lines (130 loc) · 5.04 KB
/
fmx_annealer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
''' Originally FMX's annealer code from the file 2021-02-02 FMX annealer 4 Jun.html'''
import logging
logger = logging.getLogger(__name__)
import epics
import time
import daq_utils
def blStrGet():
"""
Return beamline string
blStr: 'AMX' or 'FMX'
Beamline is determined by querying hostname
"""
if daq_utils.beamline == 'fmx':
blStr = 'XF:17IDC-ES:FMX'
elif daq_utils.beamline == 'amx':
blStr = 'XF:17IDB-ES:AMX'
else:
logger.error('Error - this code is only available in AMX and FMX')
blStr = -1
return blStr
def govMsgGet(configStr = 'Robot'): #TODO Replace these functions with the Ophyd versions
"""
Returns Governor message
configStr: Governor configuration, 'Robot' or 'Human', default: 'Robot'
Examples:
govMsgGet()
govMsgGet(configStr = 'Human')
"""
blStr = blStrGet()
if blStr == -1: return -1
devStr = '{Gov:' + configStr + '}'
stsStr = 'Sts:Msg-Sts'
pvStr = blStr + devStr + stsStr
govMsg = epics.caget(pvStr)
return govMsg
def govStatusGet(stateStr, configStr = 'Robot'):
"""
Returns the current active status for a Governor state
configStr: Governor configuration, 'Robot' or 'Human', default: 'Robot'
stateStr: Governor short version state. Example: 'SA' for sample alignment
one of ['M', 'SE', 'SA', 'DA', 'XF', 'BL', 'BS', 'AB', 'CB', 'DI']
Examples
govStatusGet('SA')
govStatusGet('SA', configStr = 'Human')
"""
blStr = blStrGet()
if blStr == -1: return -1
if stateStr not in ['M', 'SE', 'SA', 'DA', 'XF', 'BL', 'BS', 'AB', 'CB', 'DI']:
logger.error('stateStr must be one of: M, SE, SA, DA, XF, BL, BS, AB, CB, DI]')
return -1
devStr = '{Gov:' + configStr + '-St:' + stateStr + '}'
stsStr = 'Sts:Active-Sts'
pvStr = blStr + devStr + stsStr
govStatus = epics.caget(pvStr)
return govStatus
def govStateSet(stateStr, configStr = 'Robot'):
"""
Sets Governor state
configStr: Governor configuration, 'Robot' or 'Human', default: 'Robot'
stateStr: Governor short version state. Example: 'SA' for sample alignment
one of ['M', 'SE', 'SA', 'DA', 'XF', 'BL', 'BS', 'AB', 'CB', 'DI']
Examples:
govStateSet('SA')
govStateSet('AB', configStr = 'Human')
"""
blStr = blStrGet()
if blStr == -1: return -1
if stateStr not in ['M', 'SE', 'SA', 'DA', 'XF', 'BL', 'BS', 'AB', 'CB', 'DI']:
logger.error('stateStr must be one of: M, SE, SA, DA, XF, BL, BS, AB, CB, DI]')
return -1
devStr = '{Gov:' + configStr + '}'
cmdStr = 'Cmd:Go-Cmd'
pvStr = blStr + devStr + cmdStr
logger.debug(f'governor PV: {pvStr}')
epics.caput(pvStr, stateStr)
while not govStatusGet(stateStr, configStr = configStr):
print(govMsgGet(configStr = configStr))
time.sleep(2)
print(govMsgGet(configStr = configStr))
return
from ophyd import PVPositioner, PVPositionerPC, Device, Component as Cpt, EpicsMotor, EpicsSignal, EpicsSignalRO
from ophyd.status import SubscriptionStatus
# XF:17IDC-ES:FMX{Wago:1}AnnealerIn-Sts
# XF:17IDC-ES:FMX{Wago:1}AnnealerAir-Sel
## DONE Redo ophyd object with proper PV
class FmxAnnealer(Device):
air = Cpt(EpicsSignal, '1}AnnealerAir-Sel')
inStatus = Cpt(EpicsSignalRO, '2}AnnealerIn-Sts') # status: 0 (Not In), 1 (In)
outStatus = Cpt(EpicsSignalRO, '2}AnnealerOut-Sts') # status: 0 (Not In), 1 (In)
def anneal(self, anneal_time):
def status_callback(value, old_value, **kwargs):
if old_value == 0 and value == 1:
return True
else:
return False
status = SubscriptionStatus(self.inStatus, status_callback, run=False)
self.air.put(1)
status.wait(5)
time.sleep(anneal_time)
status = SubscriptionStatus(self.outStatus, status_callback, run=False)
self.air.put(0)
status.wait(5)
class AmxAnnealer(Device):
air = Cpt(EpicsSignal, '1}AnnealerAir-Sel')
inStatus = Cpt(EpicsSignalRO, '1}AnnealerAir-Sts') # status: 0 (Not In), 1 (In)
def anneal(self, anneal_time):
def in_callback(value, old_value, **kwargs):
if old_value == 0 and value == 1:
return True
else:
return False
def out_callback(value, old_value, **kwargs):
if old_value == 1 and value == 0:
return True
else:
return False
status = SubscriptionStatus(self.inStatus, in_callback, run=False)
self.air.put(1)
status.wait(5)
time.sleep(anneal_time)
status = SubscriptionStatus(self.inStatus, out_callback, run=False)
self.air.put(0)
status.wait(5)
## FMX annealer aka cryo blocker
fmxAnnealer = FmxAnnealer('XF:17IDC-ES:FMX{Wago:', name='annealer',
read_attrs=[],
labels=['fmx'])
amxAnnealer = AmxAnnealer('XF:17IDB-ES:AMX{Wago:', name='annealer',
read_attrs=[],
labels=['amx'])