Files
x07ma/script/local.py
2015-09-24 10:50:31 +02:00

70 lines
2.2 KiB
Python

###################################################################################################
# Deployment specific global definitions - executed after startup.py
###################################################################################################
FILENAME = None
data_file = None
#Uncomment this line to create the simulated devices needed to the tutorial scripts.
#run("tutorial/devices")
#The persistence strategy is overriden to adjust file names
import ch.psi.pshell.data.ScanPersistenceStrategyTable
class Strategy(ch.psi.pshell.data.ScanPersistenceStrategyTable):
def getLogFileName(self):
return time.strftime('%Y%m%d%H%M%S') + '_' + controller.getExecutingContext() + '_logs'
def getDatasetName(self, scan):
global FILENAME, data_file
name = controller.getExecutingContext() if FILENAME is None else FILENAME
data_file = time.strftime('%Y%m%d_%H%M') + '_' + name + '_' + str(controller.dataManager.getScanIndex()).zfill(4)
print "Opened data file: " + controller.dataManager.openOutput() + "/" + data_file
return data_file
controller.dataManager.setScanStrategy(Strategy())
#Reading Energy Scan configuration file
def getPars(element):
f = open(controller.setup.getConfigPath() + '/energy_scan.properties')
try:
for line in f:
tokens = line.split("=")
if tokens[0] == str(element):
tokens = tokens[1].split(";")
for i in range(len(tokens)):
tokens[i] = float(tokens[i].strip())
return tokens
finally:
f.close()
raise Exception ("Invalid element: " + str(element))
#Pseudo-devices
energy = None
class SimulatedEnergy(Writable):
def write(self, value):
self.put(value)
def put(self, value, timeout = None):
global energy
energy = value
def close(self):
pass
class SimulatedEnergyReadback(Readable):
def read(self):
global energy
return energy;
def get(self):
return self.read()
def close(self):
pass
sim_energy = SimulatedEnergy()
sim_energy_readback = SimulatedEnergyReadback()