Configuration change: Context
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
#Number of cycles must be small otherwise generates a following error
|
||||
def before_read(position, scan):
|
||||
global total_time, steps,d_output
|
||||
import time
|
||||
if d_output ==1:
|
||||
print('enter before_read')
|
||||
start = time.time()
|
||||
caput("X07MB-OP2:SMPL",1)
|
||||
time.sleep(0.75)
|
||||
if d_output ==1:
|
||||
print "Waiting..."
|
||||
cawait ("X07MB-OP2:SMPL-DONE",1, 10000)
|
||||
print "Done"
|
||||
t = time.time()-start
|
||||
if d_output ==1:
|
||||
print t
|
||||
if t > (total_time/steps):
|
||||
print "Before took too long, step = ", (total_time/steps)
|
||||
if d_output ==1:
|
||||
print('leave before_read')
|
||||
# end before_read
|
||||
print(t)
|
||||
|
||||
|
||||
def after(record, scan):
|
||||
pass
|
||||
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
#setup_plotting(line_plots = [mca_1])
|
||||
|
||||
print('running')
|
||||
# scan definition
|
||||
#centre = -0.858 # Vertical
|
||||
centre = 5 # for hor scan)
|
||||
cycles = 3
|
||||
stepsize = 0.001
|
||||
d_range=0.02
|
||||
|
||||
|
||||
x0 =centre-d_range
|
||||
x1 =centre+d_range
|
||||
|
||||
|
||||
# General definitions
|
||||
|
||||
Motor = ScanX
|
||||
RBV = ScanX_RBV
|
||||
#Motor = ScanY
|
||||
#RBV = ScanY_RBV
|
||||
speed=0
|
||||
d_output=0 # 1+ debugging output
|
||||
# general preactions
|
||||
caput("X07MB-OP2:START-CSMPL",0) # cont sampling off
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",1)
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:SMPL",1) # start one cycle to get system in defined state
|
||||
time.sleep(0.1)
|
||||
|
||||
#cscan(ScanX, [keith_1] , 18, 18.3, 100, latency = 0.0, time = 2.0, before_read = before_read, after_read = None)
|
||||
|
||||
n_cycles=cycles+1
|
||||
dwell=(n_cycles)*0.2 # time per step
|
||||
|
||||
steps=int(abs((x1-x0)/stepsize))
|
||||
total_time=steps*dwell
|
||||
#caput(Motor.getChannelName()+".VBAS",speed*.5)
|
||||
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",cycles)
|
||||
print(' parameters for scan ')
|
||||
print('range',x0,x1)
|
||||
print('total time',total_time)
|
||||
print('stepsize',stepsize)
|
||||
print('steps ',steps, ' cycles ' ,cycles)
|
||||
|
||||
print('speed',speed)
|
||||
|
||||
print(x0,x1,dwell,total_time,steps,speed,speed*0.5)
|
||||
|
||||
#ScanX.config.minSpeed = speed*.5
|
||||
#ScanX.config.save()
|
||||
|
||||
# OTF
|
||||
#ret = cscan(Motor, [keith_1,keith_2,keith_3,RBV] , x0, x1, steps=steps, latency =0.0, time = total_time, before_read = before_read, after_read = None, domain_axis="Time")
|
||||
#ret = cscan(Motor, [keith_1,keith_2,keith_3,RBV] , x0, x1, steps=steps, latency =0.0, time = total_time, before_read = before_read, after_read = None)
|
||||
|
||||
# step by step
|
||||
ret = lscan(Motor, [keith_1,keith_2, RBV] , x0, x1, steps, latency = 0.0, relative = False, passes = 1, zigzag = False, before_read = before_read, after_read = None, title = None)
|
||||
|
||||
#General postactions
|
||||
|
||||
caput(Motor.getChannelName()+'.VBAS',0.125)
|
||||
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",5)
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:START-CSMPL",1)
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:SMPL",1)
|
||||
|
||||
|
||||
|
||||
# now plot the data
|
||||
|
||||
|
||||
# read data from data set
|
||||
|
||||
y = ret.getReadable(1)
|
||||
x = ret.getPositions(0)
|
||||
|
||||
# create processed tab
|
||||
p = plot(y, xdata=x, title="Processed")[0]
|
||||
|
||||
#function = interpolate(y,x,"cubic")
|
||||
|
||||
d = deriv(y,x) # calc derivative
|
||||
|
||||
plot_function(p, interpolate(d,x,"cubic"), "Deriv", x)
|
||||
|
||||
p.setLegendVisible(True)
|
||||
(normalization, mean_val, sigma) = fit_gaussian(y, x)
|
||||
print (' ===================================== ')
|
||||
print ('RESULT GAUISSIAN FIT')
|
||||
print ('sigma',sigma)
|
||||
print ('position',mean_val)
|
||||
|
||||
|
||||
fitted_gaussian_function = Gaussian(normalization, mean_val, sigma)
|
||||
plot_function(p, fitted_gaussian_function, "Fit", x)
|
||||
|
||||
p.addText(min(x), max(y)+1, ' '+get_exec_pars().path, Color.YELLOW)
|
||||
p.addText(min(x), max(y)-10, ' sigma '+str(sigma), Color.YELLOW)
|
||||
|
||||
|
||||
#plots = get_plot_snapshots("Processed")
|
||||
#p2 = plot(y, xdata=x, title="Processed_2")[0]
|
||||
#plot_function(p2, interpolate(d,x,"cubic"), "Deriv", x)
|
||||
|
||||
plots = get_plot_snapshots("Processed")
|
||||
|
||||
print plots
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
#Number of cycles must be small otherwise generates a following error
|
||||
def before_read(position, scan):
|
||||
global total_time, steps
|
||||
import time
|
||||
start = time.time()
|
||||
caput("X07MB-OP2:SMPL",1)
|
||||
time.sleep(0.1)
|
||||
print "Waiting..."
|
||||
cawait ("X07MB-OP2:SMPL-DONE",1, 10000)
|
||||
print "Done"
|
||||
t = time.time()-start
|
||||
print t
|
||||
if t > (total_time/steps):
|
||||
print "Before took too long, step = ", (total_time/steps)
|
||||
|
||||
def after(record, scan):
|
||||
pass
|
||||
|
||||
#setup_plotting(line_plots = [mca_1])
|
||||
|
||||
print('running')
|
||||
|
||||
|
||||
#cscan(ScanX, [keith_1] , 18, 18.3, 100, latency = 0.0, time = 2.0, before_read = before_read, after_read = None)
|
||||
x0=16
|
||||
x1=16.3
|
||||
cycles = 1
|
||||
dwell=(1+cycles)*0.2 # time per step
|
||||
total_time=20.0
|
||||
steps=int(total_time/dwell/4.)
|
||||
speed=(x1-x0)/total_time
|
||||
print(x0,x1,dwell,total_time,steps,speed,speed*0.5)
|
||||
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",cycles)
|
||||
caput("X07MB-ES-MA1:ScanX.VBAS",speed*.5)
|
||||
#ScanX.config.minSpeed = speed*.5
|
||||
#ScanX.config.save()
|
||||
|
||||
ret = cscan(ScanX, [keith_1,keith_2,keith_3,ScanX_RBV] , x0, x1, steps=steps, latency =0.0, time = total_time, before_read = before_read, after_read = None, domain_axis="Time")
|
||||
caput("X07MB-ES-MA1:ScanX.VBAS",0.3)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
run("CPython/GaussFit_wrapper")
|
||||
|
||||
x=[-200.30429237268825, -200.2650700434188, -200.22115208318002, -199.9457671375377, -199.86345548879072, -199.85213073174933, -199.35687977133284, -199.13811861090275, -197.97304970346386, -197.2952215624348, -195.09076092936948, -192.92276048970703, -191.96871876227698, -189.49577852322938, -187.9652790409825, -183.63756456925222, -180.04899765472996, -178.43839623242422, -174.07311671294445, -172.0410133577918, -165.90824309893102, -160.99771795989466, -159.30176653939253, -154.27688897558514, -152.0854103810786, -145.75652847587313, -140.80843828908465, -139.23982133191495, -134.27073891256106, -132.12649284133064, -125.95947209775511, -121.00309550337462, -119.26736932643232, -114.2706655484383, -112.07393889578914, -105.72295990367157, -100.8088439880125, -99.2034906238494, -94.30042325164636, -92.15010048151461, -85.92203653534293, -81.03913275494665, -79.27412793784428, -74.33487658582118, -72.06274362408762, -65.76562628131825, -60.91255356825276, -59.20334389560392, -54.33286972659312, -52.19387171350535, -45.94978737932291, -41.03014719193582, -39.301602568238906, -34.35572209014114, -32.04464301272608, -25.8221033382824, -20.922074315528747, -19.21590299233186, -14.31090212502093, -12.217203140101386, -5.9283722049240435, -0.9863587170369246, 0.7408048387279834, 5.71126832601389, 7.972628957879352, 14.204559894256546, 19.11839959633025, 20.8218087836657, 25.678748486941828, 27.822718344586864, 34.062659474970715, 38.9745656819391, 40.77409719734158, 45.72080631619803, 47.974156754056835, 54.23453768983539, 59.12020360609568, 60.77306570712026, 65.70734521458867, 67.8344660434617, 74.03187028154134, 78.96532114824849, 80.76070945985495, 85.74802197591286, 87.9140889204674, 94.18082276873524, 99.25790470037091, 100.68454787413205, 105.7213026221542, 107.79483801526698, 113.99555681638138, 119.0707052529143, 120.72715813056156, 125.77551384921307, 127.91257836719551, 134.2011330887875, 139.23043006997628, 140.71673537840158, 145.76288138835983, 147.80216629676042, 154.06420451405637, 159.0846626604798, 160.76183155710717, 165.73699067536242, 167.9265357747636, 173.96705069576544, 178.2522282751915, 179.9042617354548, 183.54586165856657, 185.23269803071796, 189.41678143751972, 191.87149157986588, 192.8741468985015, 195.0241934550453, 195.966634211846, 197.9821647518146, 198.99006812859284, 199.33202054855676, 199.91897441965887, 200.11536227958896, 200.22280936469997, 200.25181179127208]
|
||||
y=[11.0, 6.0, 8.0, 5.0, 11.0, 7.0, 18.0, 11.0, 12.0, 10.0, 8.0, 6.0, 16.0, 4.0, 12.0, 9.0, 15.0, 14.0, 8.0, 20.0, 15.0, 8.0, 9.0, 11.0, 13.0, 12.0, 13.0, 15.0, 13.0, 20.0, 10.0, 7.0, 17.0, 11.0, 20.0, 13.0, 13.0, 23.0, 14.0, 10.0, 17.0, 15.0, 20.0, 16.0, 14.0, 13.0, 18.0, 22.0, 9.0, 20.0, 12.0, 14.0, 17.0, 19.0, 14.0, 14.0, 23.0, 19.0, 15.0, 20.0, 20.0, 21.0, 20.0, 23.0, 22.0, 15.0, 10.0, 17.0, 21.0, 15.0, 23.0, 23.0, 25.0, 18.0, 16.0, 21.0, 22.0, 16.0, 16.0, 14.0, 19.0, 20.0, 18.0, 20.0, 23.0, 13.0, 16.0, 20.0, 25.0, 15.0, 15.0, 17.0, 22.0, 26.0, 19.0, 30.0, 25.0, 17.0, 17.0, 23.0, 16.0, 27.0, 21.0, 21.0, 26.0, 27.0, 21.0, 17.0, 20.0, 20.0, 21.0, 19.0, 25.0, 19.0, 13.0, 23.0, 20.0, 20.0, 18.0, 20.0, 19.0, 25.0]
|
||||
|
||||
[off, amp, com, sigma] = profile_gauss_stats(x, y, off=None, amp=None, com=None, sigma=None)
|
||||
print "Gauss: ", [off, amp, com, sigma]
|
||||
from mathutils import Gaussian
|
||||
|
||||
#Plotting results
|
||||
from mathutils import Gaussian
|
||||
g = Gaussian(amp, com, sigma)
|
||||
fit = [g.value(i)+off for i in x]
|
||||
|
||||
plot([y, fit], ["data", "fit"], xdata = x)
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
run_fda( "users/0_Translate_to_PSHELL/Mono_pitch.xml",
|
||||
{"Pitch.Start" : -10600.0, "Pitch.End" : -10700.0})
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
#Line scan
|
||||
|
||||
d = Channel("X07MB-OP2-SAI_08:MEAN", 'd')
|
||||
set_device_alias(d, "dev1")
|
||||
|
||||
|
||||
def before(position, scan):
|
||||
caput("X07MB-OP2:SMPL.PROC",1)
|
||||
cawait ("X07MB-OP2:SMPL-DONE",1, 10000)
|
||||
|
||||
def after(record, scan):
|
||||
pass
|
||||
|
||||
setup_plotting(line_plots = [mca_1])
|
||||
|
||||
lscan(scan_y, [keith_1, d, mca_1], -10.0, -9.0, 10, latency = 0.01, before_read=before, after_read=after)
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
#Number of cycles must be small otherwise generates a following error
|
||||
|
||||
start = -10.0
|
||||
end = -5.0
|
||||
acc_distance = 1.0
|
||||
|
||||
def before(position, scan):
|
||||
time.sleep(0.1)
|
||||
|
||||
def after(record, scan):
|
||||
global start, end
|
||||
if scan_y.position < start:
|
||||
record.invalidate()
|
||||
if scan_y.position > end:
|
||||
scan.abort()
|
||||
|
||||
#setup_plotting(line_plots = [mca_1])
|
||||
|
||||
scan_y.move(start - acc_distance)
|
||||
scan_y.moveAsync(end + acc_distance)
|
||||
|
||||
mscan(trigger, [scan_y.readback, keith_1], 1000, timeout = None, before_read = before, after_read = after)
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
#Number of cycles must be small otherwise generates a following error
|
||||
def before_read(position, scan):
|
||||
global total_time, steps,d_output
|
||||
import time
|
||||
if d_output ==1:
|
||||
print('enter before_read')
|
||||
start = time.time()
|
||||
caput("X07MB-OP2:SMPL",1)
|
||||
time.sleep(0.75)
|
||||
if d_output ==1:
|
||||
print "Waiting..."
|
||||
cawait ("X07MB-OP2:SMPL-DONE",1, 10000)
|
||||
print "Done"
|
||||
t = time.time()-start
|
||||
if d_output ==1:
|
||||
print t
|
||||
if t > (total_time/steps):
|
||||
print "Before took too long, step = ", (total_time/steps)
|
||||
if d_output ==1:
|
||||
print('leave before_read')
|
||||
# end before_read
|
||||
print(t)
|
||||
|
||||
|
||||
def after(record, scan):
|
||||
pass
|
||||
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
#setup_plotting(line_plots = [mca_1])
|
||||
|
||||
print('running')
|
||||
# scan definition
|
||||
|
||||
x0=-0.84
|
||||
|
||||
x1=-0.875
|
||||
cycles = 4
|
||||
total_time=20.
|
||||
# General definitions
|
||||
Motor = ScanY
|
||||
RBV = ScanY_RBV
|
||||
|
||||
d_output=0 # 1+ debugging output
|
||||
# general preactions
|
||||
caput("X07MB-OP2:START-CSMPL",0) # cont sampling off
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",1)
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:SMPL",1) # start one cycle to get system in defined state
|
||||
time.sleep(0.1)
|
||||
|
||||
#cscan(ScanX, [keith_1] , 18, 18.3, 100, latency = 0.0, time = 2.0, before_read = before_read, after_read = None)
|
||||
n_cycles=cycles+1
|
||||
dwell=(n_cycles)*0.2 # time per step
|
||||
|
||||
steps=int(total_time/dwell)
|
||||
speed=(x1-x0)/total_time
|
||||
#caput(Motor.getChannelName()+".VBAS",speed*.5)
|
||||
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",cycles)
|
||||
print(' parameters for scan ')
|
||||
print('range',x0,x1)
|
||||
print('total time',total_time)
|
||||
print('steps ',steps, ' cycles ' ,cycles)
|
||||
print('speed',speed)
|
||||
|
||||
print(x0,x1,dwell,total_time,steps,speed,speed*0.5)
|
||||
|
||||
#ScanX.config.minSpeed = speed*.5
|
||||
#ScanX.config.save()
|
||||
|
||||
# OTF
|
||||
#ret = cscan(Motor, [keith_1,keith_2,keith_3,RBV] , x0, x1, steps=steps, latency =0.0, time = total_time, before_read = before_read, after_read = None, domain_axis="Time")
|
||||
#ret = cscan(Motor, [keith_1,keith_2,keith_3,RBV] , x0, x1, steps=steps, latency =0.0, time = total_time, before_read = before_read, after_read = None)
|
||||
|
||||
# step by step
|
||||
ret = lscan(Motor, [keith_1,keith_2, RBV] , x0, x1, steps, latency = 0.0, relative = False, passes = 1, zigzag = False, before_read = before_read, after_read = None, title = None)
|
||||
|
||||
#General postactions
|
||||
|
||||
caput(Motor.getChannelName()+'.VBAS',0.125)
|
||||
|
||||
caput("X07MB-OP2:TOTAL-CYCLES",5)
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:START-CSMPL",1)
|
||||
time.sleep(0.1)
|
||||
caput("X07MB-OP2:SMPL",1)
|
||||
|
||||
|
||||
|
||||
# now plot the data
|
||||
|
||||
|
||||
# read data from data set
|
||||
|
||||
y = ret.getReadable(1)
|
||||
x = ret.getPositions(0)
|
||||
|
||||
# create processed tab
|
||||
p = plot(y, xdata=x, title="Processed")[0]
|
||||
|
||||
#function = interpolate(y,x,"cubic")
|
||||
|
||||
d = deriv(y,x) # calc derivative
|
||||
|
||||
plot_function(p, interpolate(d,x,"cubic"), "Deriv", x)
|
||||
|
||||
p.setLegendVisible(True)
|
||||
(normalization, mean_val, sigma) = fit_gaussian(y, x)
|
||||
print (' ===================================== ')
|
||||
print ('RESULT GAUISSIAN FIT')
|
||||
print ('sigma',sigma)
|
||||
print ('position',mean_val)
|
||||
|
||||
|
||||
fitted_gaussian_function = Gaussian(normalization, mean_val, sigma)
|
||||
plot_function(p, fitted_gaussian_function, "Fit", x)
|
||||
|
||||
p.addText(min(x), max(y), get_exec_pars().path, Color.RED)
|
||||
|
||||
#plots = get_plot_snapshots("Processed")
|
||||
#p2 = plot(y, xdata=x, title="Processed_2")[0]
|
||||
#plot_function(p2, interpolate(d,x,"cubic"), "Deriv", x)
|
||||
|
||||
plots = get_plot_snapshots("Processed")
|
||||
|
||||
print plots
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
|
||||
y = [0,1,2,3,5,15, 60, 17, 14,6,3,2] #ret.getReadable(0)
|
||||
x = [0,1,2,3,4,5,6,7,8,9,10,11] #ret.getPositions(0)
|
||||
|
||||
p = plot(y, xdata=x, title="Processed")[0]
|
||||
|
||||
#function = interpolate(y,x,"cubic")
|
||||
d = deriv(y,x)
|
||||
plot_function(p, interpolate(d,x,"cubic"), "Deriv", x)
|
||||
|
||||
p.setLegendVisible(True)
|
||||
(normalization, mean_val, sigma) = fit_gaussian(y, x)
|
||||
fitted_gaussian_function = Gaussian(normalization, mean_val, sigma)
|
||||
plot_function(p, fitted_gaussian_function, "Fit", x)
|
||||
|
||||
p.addText(x[5], max(y)+2, get_exec_pars().path, Color.RED)
|
||||
|
||||
plots = get_plot_snapshots("Processed")
|
||||
print plots
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#Pre-actions
|
||||
#Scan
|
||||
print "Start OTF"
|
||||
scan_completed = False
|
||||
try:
|
||||
while True:
|
||||
waiting = True
|
||||
|
||||
class Time(Readable):
|
||||
def __init__(self):
|
||||
self.start = time.time()
|
||||
def read(self):
|
||||
return time.time()-self.start
|
||||
tm = Time()
|
||||
|
||||
class norm_tey(Readable):
|
||||
def read(self):
|
||||
return float(cadc1.take())/float(cadc2.take())
|
||||
|
||||
class norm_diode(Readable):
|
||||
def read(self):
|
||||
return float(cadc3.take())/float(cadc2.take())
|
||||
|
||||
snaps = (pol_mode, pol_angle,pol_offset)
|
||||
diags = (current.cache)
|
||||
sensors = [energy_ma_rbv, cadc1, cadc2, cadc3, cadc4, cadc5, norm_tey(), norm_diode(), tm]
|
||||
|
||||
tm.setAlias("time")
|
||||
cadc1.setAlias("tey_raw")
|
||||
cadc2.setAlias("i0")
|
||||
cadc3.setAlias("diode_raw")
|
||||
|
||||
def monitoring_task():
|
||||
global scan_completed
|
||||
time.sleep(5.0)
|
||||
scan_completed = True
|
||||
get_exec_pars().currentScan.abort()
|
||||
|
||||
monitoring_future = fork(monitoring_task)[0]
|
||||
|
||||
print "Scanning...",
|
||||
try:
|
||||
mscan( energy_ma_rbv, sensors, -1, None, \
|
||||
enabled_plots=["norm_tey", "norm_diode", cadc1, cadc3, cadc2], \
|
||||
snaps=snaps, diags=diags)
|
||||
finally:
|
||||
monitoring_future.cancel(True)
|
||||
|
||||
print "Finished Energy scan."
|
||||
if after_sample(): #Repeat if id error and not ABORT_ON_ID_ERROR:
|
||||
break
|
||||
|
||||
except:
|
||||
if not scan_completed:
|
||||
print sys.exc_info()
|
||||
print("Aborting...")
|
||||
raise
|
||||
@@ -0,0 +1,15 @@
|
||||
import sys
|
||||
name = 'X07MB-OP2:SMPL-DONE'
|
||||
#name = 'X07MB-OP2-SAI_07:SUM'
|
||||
try:
|
||||
for i in range(1000):
|
||||
print i
|
||||
|
||||
with Channel(name) as c:
|
||||
for j in range(200):
|
||||
c.get()
|
||||
time.sleep(0.00)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
finally:
|
||||
print i,j
|
||||
@@ -0,0 +1,15 @@
|
||||
import sys
|
||||
name = 'X07MB-OP2:SMPL-DONE'
|
||||
#name = 'X07MB-OP2-SAI_07:SUM'
|
||||
try:
|
||||
for i in range(1000):
|
||||
|
||||
print i
|
||||
c=Channel(name)
|
||||
for j in range(200):
|
||||
c.get()
|
||||
time.sleep(0.00)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
finally:
|
||||
print i,j
|
||||
@@ -0,0 +1,144 @@
|
||||
import java.lang.System as System
|
||||
class Channel2(java.beans.PropertyChangeListener, Writable, Readable):
|
||||
def __init__(self, channel_name, type = None, size = None, callback=None, alias = None, monitored=None):
|
||||
""" Create an object that encapsulates an Epics PV connection.
|
||||
Args:
|
||||
channel_name(str):name of the channel
|
||||
type(str, optional): type of PV. By default gets the PV standard field type.
|
||||
Scalar values: 'b', 'i', 'l', 'd', 's'.
|
||||
Array values: '[b', '[i,', '[l', '[d', '[s'.
|
||||
size(int, optional): the size of the channel
|
||||
callback(function, optional): The monitor callback.
|
||||
alias(str): name to be used on scans.
|
||||
"""
|
||||
#System.gc()
|
||||
self.channel = create_channel(channel_name, type, size)
|
||||
self.callback = callback
|
||||
self._alias = alias
|
||||
if monitored is not None: self.set_monitored(monitored)
|
||||
#FinalizeTrigger.ensureFinalizer(self)
|
||||
|
||||
def get_channel_name(self):
|
||||
"""Return the name of the channel.
|
||||
"""
|
||||
return self.channel.name
|
||||
|
||||
def get_size(self):
|
||||
"""Return the size of the channel.
|
||||
"""
|
||||
return self.channel.size
|
||||
|
||||
def set_size(self, size):
|
||||
"""Set the size of the channel.
|
||||
"""
|
||||
self.channel.size = size
|
||||
|
||||
def is_connected(self):
|
||||
"""Return True if channel is connected.
|
||||
"""
|
||||
return self.channel.connected
|
||||
|
||||
def is_monitored(self):
|
||||
"""Return True if channel is monitored
|
||||
"""
|
||||
return self.channel.monitored
|
||||
|
||||
def set_monitored(self, value):
|
||||
"""Set a channel monitor to trigger the callback function defined in the constructor.
|
||||
"""
|
||||
self.channel.monitored = value
|
||||
if (value):
|
||||
self.channel.addPropertyChangeListener(self)
|
||||
else:
|
||||
self.channel.removePropertyChangeListener(self)
|
||||
|
||||
def propertyChange(self, pce):
|
||||
if pce.getPropertyName() == "value":
|
||||
if self.callback is not None:
|
||||
self.callback(pce.getNewValue())
|
||||
|
||||
def put(self, value, timeout=None):
|
||||
"""Write to channel and wait value change. In the case of a timeout throws a TimeoutException.
|
||||
Args:
|
||||
value(obj): value to be written
|
||||
timeout(float, optional): timeout in seconds. If none waits forever.
|
||||
"""
|
||||
if (timeout==None):
|
||||
self.channel.setValue(value)
|
||||
else:
|
||||
self.channel.setValueAsync(value).get(int(timeout*1000), java.util.concurrent.TimeUnit.MILLISECONDS);
|
||||
|
||||
def putq(self, value):
|
||||
"""Write to channel and don't wait.
|
||||
"""
|
||||
self.channel.setValueNoWait(value)
|
||||
|
||||
def get(self, force = False):
|
||||
"""Get channel value.
|
||||
"""
|
||||
return self.channel.getValue(force)
|
||||
|
||||
def wait_for_value(self, value, timeout=None, comparator=None):
|
||||
"""Wait channel to reach a value, using a given comparator. In the case of a timeout throws a TimeoutException.
|
||||
Args:
|
||||
value(obj): value to be verified.
|
||||
timeout(float, optional): timeout in seconds. If None waits forever.
|
||||
comparator (java.util.Comparator, optional). If None, uses Object.equals.
|
||||
"""
|
||||
if comparator is None:
|
||||
if timeout is None:
|
||||
self.channel.waitForValue(value)
|
||||
else:
|
||||
self.channel.waitForValue(value, int(timeout*1000))
|
||||
else:
|
||||
if timeout is None:
|
||||
self.channel.waitForValue(value, comparator)
|
||||
else:
|
||||
self.channel.waitForValue(value, comparator, int(timeout*1000))
|
||||
|
||||
def close(self):
|
||||
"""Close the channel.
|
||||
"""
|
||||
Epics.closeChannel(self.channel)
|
||||
|
||||
def getName(self):
|
||||
return self.get_channel_name()
|
||||
|
||||
def setAlias(self, alias):
|
||||
self._alias = alias
|
||||
|
||||
def getAlias(self):
|
||||
return self._alias if self._alias else self.getName()
|
||||
|
||||
def write(self, value):
|
||||
self.put(value)
|
||||
|
||||
def read(self):
|
||||
return self.get()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.close()
|
||||
|
||||
#def finalize(self): pass #TODO: if not overriden, __del__ is not called!!!
|
||||
#def __del__(self):
|
||||
# self.close()
|
||||
|
||||
|
||||
import sys
|
||||
name = 'X07MB-OP2:SMPL-DONE'
|
||||
#name = 'X07MB-OP2-SAI_07:SUM'
|
||||
try:
|
||||
for i in range(1000):
|
||||
|
||||
print i
|
||||
c=Channel2(name)
|
||||
for j in range(200):
|
||||
c.get()
|
||||
time.sleep(0.00)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
finally:
|
||||
print i,j
|
||||
Reference in New Issue
Block a user