...
 
Commits (12)
......@@ -1580,7 +1580,7 @@ class AxisState(object):
"""
#: state regular expression validator
STATE_VALIDATOR = re.compile("^[A-Z0-9]+\s*$")
STATE_VALIDATOR = re.compile("^[A-Z0-9_]+\s*$")
_STANDARD_STATES = {
"READY": "Axis is READY",
......@@ -1764,7 +1764,7 @@ class AxisState(object):
# (copy constructor)
if "(" in state:
full_states = [s.strip() for s in state.split("|")]
p = re.compile("^([A-Z0-9]+)\s\((.+)\)", re.DOTALL)
p = re.compile("^([A-Z0-9_]+)\s\((.+)\)", re.DOTALL)
for full_state in full_states:
m = p.match(full_state)
try:
......
......@@ -415,7 +415,7 @@ class IntegratingCounter(Counter):
self,
name,
controller,
master_controller=None,
master_controller,
grouped_read_handler=None,
conversion_function=None,
):
......@@ -437,10 +437,7 @@ class IntegratingCounter(Counter):
name, grouped_read_handler, conversion_function, controller
)
if master_controller is None:
self._master_controller_ref = lambda: None
else:
self._master_controller_ref = weakref.ref(master_controller)
self._master_controller_ref = weakref.ref(master_controller)
def get_values(self, from_index=0):
"""
......
......@@ -29,7 +29,8 @@ def Group(*axes_list):
# can be kept or not
key = "".join(sorted(axes))
gid = GROUP_NAMES.setdefault(key, GROUP_ID.next())
g = _Group("group_%d" % gid, axes)
g = _Group("axes_group_%d" % gid, {})
g._axes.update(axes)
return g
......
......@@ -87,7 +87,7 @@ import numpy
import gevent
from bliss.common.measurement import SamplingCounter
from bliss.comm.util import get_interface
from bliss.comm.util import get_interface, get_comm
from bliss.config.settings import HashSetting
from bliss.comm.exceptions import CommunicationError
from bliss.comm.scpi import Cmd as SCPICmd
......@@ -643,6 +643,39 @@ class Multimeter2000(BaseMultimeter):
)
class AmmeterDDC(object):
def __init__(self, config):
self.interface = get_comm(config)
self.name = config['name']
def initialize(self):
self.interface.write('F1X\r\n') # Amp function
self.interface.write('G0X\r\n') # Reading with prefix (NDCA<value>)
self.interface.write('T4X\r\n') # Continuous triggered by X
def initialize_sensor(self, sensor):
pass
def measure(self, func=None):
# change to '\r\n' will make it faster but we don't know what it does!
cmd = 'X\r\n'
return [float(self.interface.write_readline(cmd)[4:])]
def read_all(self,*counters):
return self.measure()
def __enter__(self):
return self
def __exit__(self, *args):
pass
class Ammeter6512(AmmeterDDC):
pass
def Multimeter(config):
class_name = config["class"]
model = config.get("model")
......@@ -660,8 +693,12 @@ def Multimeter(config):
if class_name in ("Multimeter", "Ammeter"):
class_name += model
elif not class_name.endswith(model):
raise ValueError("class: {0} != model: {1}".format(class_name, model))
klass = globals()[class_name]
raise ValueError('class: {0} != model: {1}'.format(class_name, model))
try:
klass = globals()[class_name]
except KeyError:
raise ValueError('Unknown keithley model {} (hint: DDC needs a model ' \
'in YAML)'.format(model))
obj = klass(config, **kwargs)
obj.initialize()
return obj
......
......@@ -195,7 +195,10 @@ class RoiCounters(object):
)
roi.name = name
roi_id = self._proxy.addNames((name,))[0]
self._proxy.Start()
# set the RunLevel high enough to allow other operations like
# Mask/ffield/Background
#self._proxy.RunLevel = 5
#self._proxy.Start()
self._proxy.setRois((roi_id, roi.x, roi.y, roi.width, roi.height))
self._set_roi_settings(roi_id, roi)
......@@ -247,6 +250,9 @@ class RoiCounters(object):
rois_values.extend((roi_id, roi.x, roi.y, roi.width, roi.height))
self._roi_ids[roi.name] = roi_id
if rois_values:
# set the RunLevel high enough to allow other operations like
# Mask/ffield/Background
self._proxy.RunLevel = 5
self._proxy.Start()
self._proxy.setRois(rois_values)
......
......@@ -461,7 +461,15 @@ class musst(object):
buffer_size, nb_buffer = self.get_event_buffer_size()
buffer_memory = buffer_size * nb_buffer
current_offset, current_buffer_id = self.get_event_memory_pointer()
for i in range(10):
curr_state = self.STATE
current_offset, current_buffer_id = self.get_event_memory_pointer()
if current_buffer_id == 0 and current_offset != 64:
break
if curr_state != self.RUN_STATE:
break
gevent.sleep(100e-3) # wait a little bit before re-asking
current_offset = current_buffer_id * buffer_size + current_offset
from_offset = (from_event_id * nb_counters) % buffer_memory
......@@ -584,6 +592,8 @@ class musst(object):
if not isinstance(value, str):
value = self.__frequency_conversion.get(value)
if isinstance(value, tuple):
value = value[0]
return self.putget("TMRCFG %s" % value)
def get_channel(self, channel_id, type=None, switch=None, switch_name=None):
......
......@@ -46,5 +46,5 @@ DEFAULT_CONTROLLER = simulation_diode_controller()
def simulation_diode(name, config, default=DEFAULT_CONTROLLER):
controller = None if config.get("independent") else default
if config.get("integration"):
return SimulationDiodeIntegratingCounter(name, controller)
return SimulationDiodeIntegratingCounter(name, controller, lambda: None)
return SimulationDiodeSamplingCounter(name, controller)
......@@ -97,7 +97,7 @@ class LakeShore330(object):
(float): current temperature [K]
"""
self._channel = channel
return self.send_cmd("KRDG?")
return float(self.send_cmd("KRDG?"))
def setpoint(self, channel, value=None):
""" Set/Read the control setpoint
......@@ -115,7 +115,7 @@ class LakeShore330(object):
# send the setpoint
self.send_cmd("SETP", value)
def range(self, channel, range=None):
def range(self, channel, value=None):
""" Set/Read the heater range (0=off 1=low 2=medium 3=high)
Args:
channel (int): output channel. Valid entries: 1 or 2
......@@ -127,7 +127,7 @@ class LakeShore330(object):
"""
self._channel = channel
if value is None:
return float(self.send_cmd("RANGE?"))
return int(self.send_cmd("RANGE?"))
# send the range
self.send_cmd("RANGE", value)
......
......@@ -26,7 +26,7 @@ class LakeShore332(LakeShore330):
channel(int): loop channel. Valid entries: 1 or 2
Kwargs:
input (str): which input to control from. Valid entries: A or B
off (bool): switch on (True) or off (False) the control loop
enable (bool): switch on (True) or off (False) the control loop
Returns:
None if set
input (str): which input to control from
......@@ -34,12 +34,13 @@ class LakeShore332(LakeShore330):
"""
self._channel = channel
inp = kwargs.get("input", "")
off = kwargs.get("off")
off = kwargs.get("enable")
if isinstance(off, bool):
self.send_cmd("CSET", inp, 1, int(off))
else:
asw = send_cmd("CSET?").split(",")
return asw[1], bool(asw[3])
asw = self.send_cmd("CSET?").split(",")
# return asw[1], bool(asw[3])
return asw[0], asw[1], bool(asw[2]), bool(asw[3])
def cmode(self, channel, mode=None):
""" Read/Set Control Loop Mode
......
......@@ -7,6 +7,7 @@
import numpy
import time
import warnings
import gevent
from gevent import event
from bliss.common.event import dispatcher
......@@ -35,10 +36,9 @@ def _get_group_reader(counters_or_groupreadhandler):
class BaseCounterAcquisitionDevice(AcquisitionDevice):
def __init__(self, counter, count_time, **keys):
npoints = max(1, keys.pop("npoints", 1))
prepare_once = keys.pop("prepare_once", True)
start_once = keys.pop("start_once", npoints > 1)
npoints = keys.pop("npoints")
prepare_once = keys.pop("prepare_once")
start_once = keys.pop("start_once")
AcquisitionDevice.__init__(
self,
counter,
......@@ -106,8 +106,20 @@ class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
* prepare_once --
* start_once --
"""
npoints = max(1, keys.pop("npoints", 1))
prepare_once = keys.pop("prepare_once", True)
start_once = keys.pop("start_once", npoints > 1)
reader, counters = _get_group_reader(counters_or_groupreadhandler)
BaseCounterAcquisitionDevice.__init__(self, reader, count_time, **keys)
BaseCounterAcquisitionDevice.__init__(
self,
reader,
count_time,
npoints=npoints,
prepare_once=prepare_once,
start_once=start_once,
**keys
)
self._event = event.Event()
self._stop_flag = False
......@@ -210,11 +222,39 @@ class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
class IntegratingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
def __init__(self, counters_or_groupreadhandler, count_time=None, **keys):
if any(
filter(
None,
(keys.pop(k, None) for k in ("npoints", "prepare_once", "start_once")),
)
):
warnings.warn(
"IntegratingCounterAcquisitionDevice: npoints, \
prepare_once or start_once flags will be overwritten\
by master controller"
)
reader, counters = _get_group_reader(counters_or_groupreadhandler)
BaseCounterAcquisitionDevice.__init__(self, reader, count_time, **keys)
BaseCounterAcquisitionDevice.__init__(
self,
reader,
count_time,
npoints=None,
prepare_once=None,
start_once=None,
**keys
)
for cnt in counters:
self.add_counter(cnt)
@AcquisitionDevice.parent.setter
def parent(self, p):
self._AcquisitionDevice__parent = p
self._AcquisitionDevice__npoints = p.npoints
self._AcquisitionDevice__prepare_once = p.prepare_once
self._AcquisitionDevice__start_once = p.start_once
def prepare(self):
self.device.prepare(*self.grouped_read_counters)
......
......@@ -595,6 +595,7 @@ class Scan(object):
def goto_peak(self, counter):
pk, axis_name = self.peak(counter, return_axis_name=True)
axis = getattr(setup_globals, axis_name)
print('Move motor {0} to peak @ {1:.4f}'.format(axis_name, pk))
with error_cleanup(axis, restore_list=(cleanup_axis.POS,)):
axis.move(pk)
return axis
......@@ -603,6 +604,7 @@ class Scan(object):
def goto_com(self, counter):
com, axis_name = self.com(counter, return_axis_name=True)
axis = getattr(setup_globals, axis_name)
print('Move motor {0} to COM @ {1:.4f}'.format(axis_name, com))
with error_cleanup(axis, restore_list=(cleanup_axis.POS,)):
axis.move(com)
return axis
......@@ -611,6 +613,7 @@ class Scan(object):
def goto_cen(self, counter):
cen, fwhm, axis_name = self.cen(counter, return_axis_name=True)
axis = getattr(setup_globals, axis_name)
print('Move motor {0} to CEN @ {1:.4f}'.format(axis_name,cen))
with error_cleanup(axis, restore_list=(cleanup_axis.POS,)):
axis.move(cen)
return axis
......
......@@ -220,7 +220,7 @@ following methods (further detailed) are mandatory:
* Called ???
### Calibration methods
* `home_search(self, axis)`
* `home_search(self, axis, switch)`
* Must ???
* Called ???
* `home_state(self, axis)`
......