Commit fc43e609 authored by Jose Tiago Macara Coutinho's avatar Jose Tiago Macara Coutinho Committed by blissadm_ID31@bibhelm
Browse files

SPEC config: add keithley multim

parent 7685a397
......@@ -16,6 +16,7 @@ import datetime
__all__ = ['SpecConfig', 'Device', 'Motor', 'Counter']
GPIB_CTRLS = set(('GPIB_ENET'))
MOT_CTRLS = set(('NI660x', 'SPEC_M2', 'MAC_MOT', 'MAXE'))
CNT_CTRLS = set(('MAC_CNT', 'VCT6', 'MAC_CNT', 'SFTWARE'))
......@@ -25,7 +26,8 @@ DEV_MAP = {
'PSE_MAC_MOT':'MAC_MOT', 'PSE_MAC_C':'MAC_CNT',
'PSE_MAC_T':'MAC_CNT', 'VM_SPEC_M2':'SPEC_M2',
'SW_SFTWARE':'SFTWARE', 'PCI_NI660xT':'NI660x',
'VM_VCTT':'VCT6', 'VM_VCTC':'VCT6'
'VM_VCTT':'VCT6', 'VM_VCTC':'VCT6',
'HW_GPIBENET': 'GPIB_ENET', 'HW_GPIBENET_L': 'GPIB_ENET',
}
HEADER_TEMPLATE = """\
......@@ -108,7 +110,7 @@ class Device:
self.__objecttype = 'Motor Controller' if self.type in MOT_CTRLS else self.__objecttype
self.__objecttype = 'Counter Controller' if self.type in CNT_CTRLS else self.__objecttype
self.__objecttype = 'GPIB Controller' if 'GPIB' in self.type else self.__objecttype
self.__objecttype = 'GPIB Controller' if self.type in GPIB_CTRLS else self.__objecttype
self.__objecttype = 'MCA' if 'MCA' in self.type else self.__objecttype
......@@ -267,7 +269,10 @@ class Device:
self.ctrl = ltype
self.__setType()
def addChannel(self, channel):
self.num = max(self.num, int(channel)+1)
class Motor:
"""
A motor
......@@ -414,7 +419,7 @@ class Counter:
self.ctrl = ctrl
self.unit = int(unit)
self.chan = int(chan)
self.scale = int(scale)
self.scale = scale
self.flags = int(flags, 16)
# 7 chars max
self.mne = mne[:7]
......@@ -599,6 +604,11 @@ class SpecConfig:
ctrlstr = ''
# make a copy of ctrl types so we can pop from it with the order we need
ctrltypes = dict(self.ctrltypes)
# generate GPIB devices
for ctrl_type in GPIB_CTRLS:
for node in ctrltypes.pop(ctrl_type, ()):
ctrlstr += str(node)
# generate motor devices
for ctrl_type in MOT_CTRLS:
for node in ctrltypes.pop(ctrl_type, ()):
......
......@@ -169,6 +169,14 @@ SPEC_SAFETY_SHUTTER_TEMPLATE = """\
safshutsetup {name} {uri}
"""
SPEC_MULTIM_TEMPLATE = """\
##########################
# Multim counter: {name}
#########################
multimsetup {name} type={type} integrate={integrate} scale={scale}
"""
class WagoSetup:
def __init__(self, name, description=''):
......@@ -280,6 +288,8 @@ class Generator(object):
self.__tango_axis_manager_servers = OrderedDict()
# map of tango lima servers <server full name (str): server info (TServer)>
self.__tango_lima_servers = OrderedDict()
# map of gpibs interfaces: <session name: dict(url: unit)>
self.__gpibs = OrderedDict()
# spec configuration object
self.__spec_config = None
......@@ -343,9 +353,7 @@ class Generator(object):
dev_name = '{0}/emotion/{1}'.format(self.beamline, tango_server)
axis_manager = TServer('BlissAxisManager', tango_server, None,
[TDevice('BlissAxisManager', dev_name)])
# Don't put it in the list of tango servers. We assume they were
# manually created
#self.__tango_servers[axis_manager['server']] = axis_manager
self.__tango_servers[axis_manager['server']] = axis_manager
self.__tango_axis_manager_servers[tango_server] = axis_manager
return axis_manager
......@@ -439,7 +447,8 @@ class Generator(object):
def __add_emotion_axis_to_spec_controller(self, name, config_name, ctrl):
mot_config = self.config.get_config(config_name)
ctrl_addr = 'MAC_MOT:{0}/{1}'.format(ctrl.getCtrlIndex(), ctrl.num)
chan = ctrl.num
ctrl_addr = 'MAC_MOT:{0}/{1}'.format(ctrl.getCtrlIndex(), chan)
sign = mot_config.get('sign') or 1
spec_motor = Motor(ctrl=ctrl_addr, steps=int(1E6), mne=name,
......@@ -448,7 +457,7 @@ class Generator(object):
if config_name != name:
spec_motor.addPar('MOTPAR:axis_name = %s' % config_name)
self.spec_config.addMotor(spec_motor)
ctrl.num += 1
ctrl.addChannel(chan)
self.__spec_macros.add('tango_mot.mac')
def add_emotion(self, session_name, name, config_name):
......@@ -481,11 +490,11 @@ class Generator(object):
del cfg['name']
ctrl = self.__spec_setup_icepaps.get(icepap)
if ctrl is None:
ctrl = Device(ltype='PSE_MAC_MOT', addr='icepap', num=0)
ctrl = Device(ltype='PSE_MAC_MOT', addr='icepap', num=0, conf=icepap)
self.spec_config.addDevice(ctrl)
self.__spec_setup_icepaps[icepap] = ctrl
addr = cfg.pop('address')
assert addr.count('/') == 1
module, chan = addr.split('/')
addr = 'MAC_MOT:{0}/{1}'.format(ctrl.getCtrlIndex(), addr)
spec_motor = Motor(ctrl=addr, mne=name, name=name,
steps=cfg.pop('steps', 1),
......@@ -497,7 +506,7 @@ class Generator(object):
for k, v in cfg.items():
spec_motor.addPar('MOTPAR:{0} = {1}'.format(k, v))
self.spec_config.addMotor(spec_motor)
ctrl.num += 1
ctrl.addChannel(chan)
self.__spec_macros.add('ice.mac')
......@@ -664,6 +673,31 @@ class Generator(object):
####################
def add_keithley(self, session_name, name, config_name):
config = self.config.get_config(config_name)
spec_ctrl = config.get('spec_controller', 'tango')
if spec_ctrl == 'multim':
self.add_keithley_multim(session_name, name, config_name)
else:
self.add_keithley_tango(session_name, name, config_name)
def add_keithley_multim(self, session_name, name, config_name):
config = self.config.get_config(config_name)
url = config.get('gpib_url')
gpib_unit = self.get_gpib_enet(session_name, url=url)
pad = config.get('gpib_pad')
scale = config.get('scale', 1E12)
integ = config.get('integrate', True)
counter = Counter(ctrl='NONE', unit=gpib_unit, chan=pad,
mne=name, name=name)
self.spec_config.addCounter(counter)
self.__spec_macros.add('multim.mac')
integ_str = 'yes' if integ else 'no'
keithley_setup = SPEC_MULTIM_TEMPLATE.format(name=name, type='kscpi',
integrate=integ_str,
scale=scale)
self.__spec_setup.append(keithley_setup)
def add_keithley_tango(self, session_name, name, config_name):
config = self.config.get_config(config_name)
server_host = config.get(SERVER_HOST_KEY)
keithley_dev_name = '{0}/{1}/{2}'.format(self.beamline, 'keithley',
......@@ -714,7 +748,7 @@ class Generator(object):
server = TServer('CT2', name, server_host, [
TDevice('CT2', ct2_dev_name, card_name=name)])
self.__tango_servers[server['server']] = server
counter_ctrl = Device(ltype='PSE_MAC_C', addr='ct2', num=10,
counter_ctrl = Device(ltype='PSE_MAC_C', addr='ct2', num=13,
conf=ct2_dev_name)
self.spec_config.addDevice(counter_ctrl)
......@@ -813,11 +847,12 @@ class Generator(object):
self.spec_config.addDevice(counter_ctrl)
counter_ctrl.num = 0
unit = counter_ctrl.getCtrlIndex()
counter = Counter(ctrl='MAC_CNT', unit=unit, chan=counter_ctrl.num, mne=name,
chan = counter_ctrl.num
counter = Counter(ctrl='MAC_CNT', unit=unit, chan=chan, mne=name,
name=name)
counter.addPar('CNTPAR:attr_name = ' + attr_name)
self.spec_config.addCounter(counter)
counter_ctrl.num += 1
counter_ctrl.addChannel(chan)
self.__spec_macros.add('attributes.mac')
......@@ -957,18 +992,16 @@ class Generator(object):
if bv_type != 'bv':
raise TypeError('channel type {0!r} is not supported'.format(bv_type))
if counter_type in SPEC_XBPM_MAP:
unit = server.xbpm_ctrl.getCtrlIndex()
chan = SPEC_XBPM_MAP[counter_type]
counter = Counter(ctrl='MAC_CNT', unit=unit, chan=chan,
mne=name, name=name)
self.spec_config.addCounter(counter)
server.xbpm_ctrl.num += 1
ctrl = server.xbpm_ctrl
elif counter_type == 'diode_current':
unit = server.xbpmbv_ctrl.getCtrlIndex()
counter = Counter(ctrl='MAC_CNT', unit=unit, chan=0,
mne=name, name=name)
self.spec_config.addCounter(counter)
server.xbpmbv_ctrl.num += 1
chan = 0
ctrl = server.xbpmbv_ctrl
unit = ctrl.getCtrlIndex()
counter = Counter(ctrl='MAC_CNT', unit=unit, chan=chan,
mne=name, name=name)
self.spec_config.addCounter(counter)
ctrl.addChannel(chan)
def __add_lima_full(self, session_name, name, config_name):
self._log.debug('adding full lima %r from %s', name, session_name)
......@@ -983,8 +1016,23 @@ class Generator(object):
def add_serial(self, session_name, name):
pass
def add_gpib(self, session_name, name):
pass
def get_gpib_enet(self, session_name, url):
url_proto = 'enet'
head = '%s://' % url_proto
if not url.startswith(head):
raise ValueError('Invalid GPIB ENET URL: %s' % url)
if session_name not in self.__gpibs:
self.__gpibs[session_name] = dict()
gpibs = self.__gpibs[session_name]
if url in gpibs:
return gpibs[url]
unit = len(gpibs)
host = url.strip(head)
conf = '@gpib_%s' % unit
gpib_ctrl = Device(ltype='HW_GPIBENET_L', addr=host, num='', conf=conf)
self.spec_config.addDevice(gpib_ctrl)
gpibs[url] = unit
return unit
def add_gasrig(self, session_name, name):
pass
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment