class Watchman: cbid = None retries = 3 def __init__(self, door_state, voltage_read, voltage_write): self.door_state = EpicsSignalRO(door_state) self.mesh_voltage = EpicsSignal(voltage_read, write_pv=voltage_write) print('Using door pv {}'.format(door_state)) def start(self): """Sets up self.callback to be run when door state changes""" # Make sure we don't start 2 processes self.stop() print('Starting door watcher') self.door_state.subscribe(self.callback) def callback(self, old_value=None, value=None, **kwargs): """To be run every time the door state changes""" print('Door PV changed from {} to {}'.format(old_value, value)) if old_value == 1 and value == 0: print('Zeroing the mesh voltage because door was opened') # Let's retry a few times in case of a network error for i in range(self.retries): try: self.mesh_voltage.put(0) except Exception: pass def stop(self): """Shutdown the watcher""" if self.cbid is not None: print('Stopping door watcher') self.door_state.unsubscribe(self.cbid) self.cbid = None
Will become current actual position array, gets filled by EpicsSignalRO timestamp : float Will become current timestamp for actual position array, i.e ``timestamp`` of ``value`` """ # Get Current array and associated timestamp # Assuming timestamp corresponds to last point in array, is this an OK # assumption? # Only taking new arrays, check for update comparison = value == old_value if not comparison.all(): enc_vals.append(value) timestamps.append(timestamp) # System time may be better, why? cbid = sig.subscribe(cb) # callback id print('Acquiring Data From PV %s ...' % enc_pv) print('Please wait %s s' % acq_time) time.sleep(acq_time - (EPICS_SAMPLE_TIME / 2)) # wait time found by experiment # cb seems to always finish its cycle before exiting, waiting exact acq_time # seems to always give an extra array # sig.unsubscribe not working in script, causes seg fault sig.destroy() # This has desired behavior print('Data Acquired, generated file %s' % outfile_name) # Inspecting with datetime.fromtimestamp(current_timestamp), this appears # to be correct # Should have list [arr_1, arr_2, ... , arr_(acq_time/EPICS_SAMPLE_TIME)] # Need to covert to arrays of tvals that match up with enc_vals for i in range(len(enc_vals)): curr_time_array = np.zeros(enc_vals[i].size)