Skip to content

Commit

Permalink
Merge 08fda94 into 29f2231
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jul 26, 2019
2 parents 29f2231 + 08fda94 commit 34ade90
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 9 deletions.
131 changes: 131 additions & 0 deletions apstools/migration/config-CNTPAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# ID @(#)getinfo.c 6.6 01/15/16 CSS
# Device nodes
PC_BIT3PCI = pci=0:0 @vme_0
HW_GPIBENET = 10.0.122.20 @gpib_0
SDEV_0 = /dev/ttyS0 9600 raw
SDEV_1 = /dev/ttyS1 9600 raw
SDEV_2 = /dev/ttyS5 9600 raw
SDEV_3 = /dev/ttyS3 9600 raw
SDEV_4 = /dev/ttyS4 9600 raw
VM_EPICS_M1 = 12bmb1: 24
VM_EPICS_M1 = 12bma: 32
VM_EPICS_M1 = 12bmb2: 16
PSE_MAC_MOT = FES 4
PSE_MAC_MOT = GS 4
PSE_MAC_MOT = STB 4
PSE_MAC_MOT = PREAMP 4
VM_EPICS_SC = 12bmb1:scaler1 16
VM_EPICS_PV = 12bmb1:3820:scaler1 32
VM_EPICS_PV = XSPRESS3-EXAMPLE: 16
VM_EPICS_PV = 12bmb1:ET1:RBV_pvTemp 1
# CAMAC Slot Assignments
# CA_name_unit = slot [crate_number]
# Motor cntrl steps sign slew base backl accel nada flags mne name
MOT000 = EPICS_M2:1/1 4000 1 1000 100 100 125 0 0x003 mono mono
MOT001 = EPICS_M2:2/2 2000 1 2000 200 50 125 0 0x003 hxt hxt
MOT002 = EPICS_M2:1/2 2000 -1 2000 200 50 125 0 0x003 mslide mslide
MOT003 = EPICS_M2:1/3 2000 -1 2000 200 50 125 0 0x003 mchi mchi
MOT004 = EPICS_M2:1/4 2000 -1 2000 200 50 125 0 0x003 mtheta mtheta
MOT005 = EPICS_M2:0/12 2000 -1 2000 200 50 125 0 0x003 stbhu SampleTabHU
MOT006 = EPICS_M2:0/13 2000 1 2000 200 50 125 0 0x003 stbhd SampleTabHD
MOT007 = EPICS_M2:0/14 8000 1 2000 200 50 125 0 0x003 stbv1 SampleTabV1
MOT008 = EPICS_M2:0/15 8000 1 2000 200 50 125 0 0x003 stbv2 SampleTabV2
MOT009 = EPICS_M2:0/16 8000 1 2000 200 50 125 0 0x003 stbv3 SampleTabV3
MOT010 = MAC_MOT:2/0 400 1 400 200 50 125 0 0x003 stbht stbht
MOT011 = MAC_MOT:2/1 400 1 400 200 50 125 0 0x003 stbtrn stbtrn
MOT012 = MAC_MOT:2/2 400 1 400 200 50 125 0 0x003 tbtrn tb2trn
MOT013 = MAC_MOT:2/3 400 1 400 200 50 125 0 0x003 tbht tb2ht
MOT014 = EPICS_M2:0/17 400 -1 400 200 50 125 0 0x003 fst FE Slit Top
MOT015 = EPICS_M2:0/18 400 1 400 200 100 125 0 0x003 fsb FE Slit Bot
MOT016 = EPICS_M2:0/19 400 1 400 200 100 125 0 0x003 fsi FE Slit In
MOT017 = EPICS_M2:0/20 400 1 400 200 100 125 0 0x003 fso FE Slit Out
MOT018 = EPICS_M2:2/11 400 1 400 200 100 125 0 0x003 sav sav
MOT019 = EPICS_M2:2/12 400 1 400 200 100 125 0 0x003 sah sah
MOT020 = EPICS_M2:2/9 400 1 400 200 50 125 0 0x003 bsv bsv
MOT021 = EPICS_M2:2/10 400 1 400 200 50 125 0 0x003 bsh bsh
MOT022 = EPICS_M2:2/13 400 -1 51200 5120 50 125 0 0x003 gsin gsin
MOT023 = EPICS_M2:2/14 400 -1 51200 5120 50 125 0 0x003 gsout gsout
MOT024 = EPICS_M2:2/15 500 -1 51200 5120 50 125 0 0x003 gsbot gsbot
MOT025 = EPICS_M2:2/16 500 -1 51200 5120 50 125 0 0x003 gstop gstop
MOT026 = EPICS_M2:2/8 500 -1 51200 5120 50 125 0 0x003 gith gith
MOT027 = EPICS_M2:2/3 400 1 51200 5120 50 125 0 0x003 zt zt
MOT028 = EPICS_M2:2/4 400 1 51200 5120 50 125 0 0x003 ttuv ttuv
MOT029 = EPICS_M2:2/5 400 1 51200 5120 50 125 0 0x003 ttuh ttuh
MOT030 = EPICS_M2:2/6 400 1 51200 5120 50 125 0 0x003 ttdv ttdv
MOT031 = EPICS_M2:2/7 200 1 1000 100 100 125 0 0x003 ttdh ttdh
MOT032 = EPICS_M2:2/1 400 1 51200 5120 50 125 0 0x003 hzt hzt
MOT033 = MAC_MOT:0/0 2000 1 2000 200 50 125 0 0x003 fshgap fshgap
MOTPAR:read_mode = 7
MOT034 = MAC_MOT:0/1 2000 1 2000 200 50 125 0 0x003 fshce fshce
MOTPAR:read_mode = 7
MOT035 = MAC_MOT:0/2 2000 1 2000 200 50 125 0 0x003 fsvgap fsvgap
MOTPAR:read_mode = 7
MOT036 = MAC_MOT:0/3 2000 1 2000 200 50 125 0 0x003 fsvce fsvce
MOTPAR:read_mode = 7
MOT037 = MAC_MOT:1/0 2000 1 2000 200 50 125 0 0x003 gshgap gshgap
MOTPAR:read_mode = 7
MOT038 = MAC_MOT:1/1 2000 1 2000 200 50 125 0 0x003 gshce gshce
MOTPAR:read_mode = 7
MOT039 = MAC_MOT:1/2 2000 1 2000 200 50 125 0 0x003 gsvgap gsvgap
MOTPAR:read_mode = 7
MOT040 = MAC_MOT:1/3 2000 1 2000 200 50 125 0 0x003 gsvce gsvce
MOTPAR:read_mode = 7
MOT041 = MAC_MOT:3/0 2000 1 2000 200 50 125 0 0x003 preamp1 preamp1
MOTPAR:read_mode = 7
MOT042 = MAC_MOT:3/1 2000 1 2000 200 50 125 0 0x003 preamp2 preamp2
MOTPAR:read_mode = 7
MOT043 = MAC_MOT:3/2 2000 1 2000 200 50 125 0 0x003 preamp3 preamp3
MOTPAR:read_mode = 7
MOT044 = MAC_MOT:3/3 2000 1 2000 200 50 125 0 0x003 preamp4 preamp4
MOTPAR:read_mode = 7
MOT045 = NONE:2/1 400 1 51200 5120 50 125 0 0x003 setmv setmv
MOTPAR:read_mode = 7
# Counter ctrl unit chan scale flags mne name
CNT000 = EPICS_SC 0 0 10000000 0x001 sec Seconds
CNTPAR:misc_par_1 = .S1
CNT001 = NONE 0 0 1 0x000 mononc mononc
CNT002 = NONE 11 1 1 0x000 mononrg mononrg
CNT003 = NONE 11 2 1 0x000 encdnrg encdnrg
CNT004 = EPICS_SC 0 1 1 0x000 i0 i0
CNTPAR:misc_par_1 = .S2
CNT005 = EPICS_SC 0 2 1 0x002 i1 i1
CNTPAR:misc_par_1 = .S3
CNT006 = EPICS_SC 0 3 1 0x000 i2 i2
CNTPAR:misc_par_1 = .S3
CNT007 = EPICS_SC 0 4 1 0x000 i3 i3
CNTPAR:misc_par_1 = .S4
CNT008 = NONE 0 0 1 0x000 mu mu
CNT009 = NONE 0 0 1 0x000 mu23 mu23
CNT010 = NONE 0 0 1 0x000 mu12 mu12
CNT011 = NONE 0 0 1 0x000 mu01 mu01
CNT012 = NONE 0 0 1 0x000 flatot flatot
CNT013 = NONE 0 0 1 0x000 flbtot flbtot
CNT014 = NONE 0 0 1 0x000 flctot flctot
CNT015 = NONE 0 0 1 0x000 icrtot icrtot
CNT016 = EPICS_PV 0 0 1 0x000 fla01 fla01
CNTPAR:misc_par_1 = .S27
CNT017 = EPICS_PV 0 1 1 0x000 fla02 fla02
CNTPAR:misc_par_1 = .S31
CNT018 = EPICS_PV 0 2 1 0x000 fla03 fla03
CNTPAR:misc_par_1 = .S23
CNT019 = EPICS_PV 0 3 1 0x000 fla04 fla04
CNTPAR:misc_par_1 = .S5
CNT020 = EPICS_PV 0 4 1 0x000 fla05 fla05
CNTPAR:misc_par_1 = .S6
CNT021 = EPICS_PV 0 5 1 0x000 fla06 fla06
CNTPAR:misc_par_1 = .S7
CNT022 = EPICS_PV 0 6 1 0x000 fla07 fla07
CNTPAR:misc_par_1 = .S8
CNT023 = EPICS_PV 0 7 1 0x000 fla08 fla08
CNTPAR:misc_par_1 = .S9
CNT024 = EPICS_PV 0 8 1 0x000 fla09 fla09
CNTPAR:misc_par_1 = .S10
CNT025 = EPICS_PV 0 9 1 0x000 fla10 fla10
CNTPAR:misc_par_1 = .S11
CNT026 = EPICS_PV 0 10 1 0x000 fla11 fla11
CNTPAR:misc_par_1 = .S12
CNT027 = EPICS_PV 0 11 1 0x000 fla12 fla12
CNTPAR:misc_par_1 = .S13
CNT028 = EPICS_PV 0 12 1 0x000 fla13 fla13
CNTPAR:misc_par_1 = .S14
CNT029 = EPICS_PV 2 0 1 0x000 TC1 TC1
File renamed without changes.
77 changes: 68 additions & 9 deletions apstools/migration/spec2ophyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re


CONFIG_FILE = 'config-8idi'
CONFIG_FILE = 'config-CNTPAR'
KNOWN_DEVICES = "PSE_MAC_MOT VM_EPICS_M1 VM_EPICS_PV VM_EPICS_SC".split()


Expand All @@ -21,9 +21,19 @@ class Spec2ophydBase(object):

def obj_keys_to_list(self):
items = []
for k in self.str_keys:
v = self.__getattribute__(k)
if v is not None:
keys = list(self.str_keys)

if ("mne" in keys
and "name" in keys
and hasattr(self, "mne")
and hasattr(self, "name")
and self.mne == self.name
):
keys.pop(keys.index("name")) # redundant, do not show

for k in keys:
if hasattr(self, k):
v = self.__getattribute__(k)
items.append(f"{k}='{v}'")
return items

Expand Down Expand Up @@ -78,15 +88,48 @@ def __init__(self, mne, nm, pvname, config_text):
self.mne = mne
self.name = nm
self.pvname = pvname
self.device = None
self.signal_name = "EpicsSignal"

lr = config_text.split(sep="=", maxsplit=1)
def pop_word(line, int_result=False):
line = line.strip()
pos = line.find(" ")
l, r = line[:pos].strip(), line[pos:].strip()
if int_result:
l = int(l)
return l, r

self.ctrl, r = pop_word(lr[1])
self.unit, r = pop_word(r, True)

self.str_keys = "mne config_line name pvname signal_name".split()
self.cntpar = {}

def setDevice(self, devices):
if self.ctrl.startswith("EPICS_PV"):
device_list = devices.get("VM_EPICS_PV")
if device_list is not None:
self.device = device_list[self.unit]
self.pvname = self.device.prefix
self.ophyd_device = "EpicsSignal"
elif self.ctrl.startswith("NONE"):
self.ignore = True

def ophyd_config(self):
s = f"{self.mne} = {self.signal_name}('{self.pvname}', name='{self.mne}')"
suffix = None
if "misc_par_1" in self.cntpar:
suffix = self.cntpar.pop("misc_par_1")
pvname = f"{self.device.prefix}{suffix}"
s = f"{self.mne} = EpicsSignal('{pvname}', name='{self.mne}')"
if self.mne != self.name:
s += f" # {self.name}"
if self.ignore:
s = "# NONE: " + s
if len(self.cntpar) > 0:
terms = [f"{k}={v}" for k, v in self.cntpar.items()]
s += f" # {', '.join(terms)}"
return s


Expand Down Expand Up @@ -126,7 +169,7 @@ def pop_word(line, int_result=False):
self.motpar = {}
self.macro_prefix = None
self.str_keys = "mne config_line name macro_prefix".split()

def __str__(self):
items = self.obj_keys_to_list()
txt = self.item_name_value("pvname") or self.item_name_value("ctrl")
Expand Down Expand Up @@ -155,9 +198,9 @@ def setDevice(self, devices):

def ophyd_config(self):
s = f"{self.mne} = EpicsMotor('{self.pvname}', name='{self.mne}')"
suffix = self.motpar.get("misc_par_1")
if suffix is not None:
del self.motpar["misc_par_1"]
suffix = None
if "misc_par_1" in self.motpar:
suffix = self.motpar.pop("misc_par_1")
pvname = f"{self.device.prefix}{suffix}"
s = f"{self.mne} = EpicsMotor('{pvname}', name='{self.mne}')"
if self.pvname is None:
Expand Down Expand Up @@ -209,6 +252,7 @@ def pop_word(line, int_result=False):
self.pvname = None
self.reported_pvs = []
self.str_keys = "mne config_line name unit chan".split()
self.cntpar = {}

def __str__(self):
items = self.obj_keys_to_list()
Expand Down Expand Up @@ -237,8 +281,16 @@ def setDevice(self, devices):

def ophyd_config(self):
s = f"# counter: {self.mne} = {self}"
suffix = None
if "misc_par_1" in self.cntpar:
suffix = self.cntpar.pop("misc_par_1")
pvname = f"{self.device.prefix}{suffix}"
s = f"{self.mne} = EpicsSignal('{pvname}', name='{self.mne}')"
if self.ignore:
s = f"# line {self.config_line}: {self.raw}"
if len(self.cntpar) > 0:
terms = [f"{k}={v}" for k, v in self.cntpar.items()]
s += f" # {', '.join(terms)}"
return s


Expand All @@ -257,6 +309,7 @@ def __init__(self, config_file):
def read_config(self, config_file=None):
self.config_file = config_file or self.config_file
motor = None
counter = None
with open(self.config_file, 'r') as f:
for line_number, line in enumerate(f.readlines()):
line = line.strip()
Expand All @@ -273,17 +326,23 @@ def read_config(self, config_file=None):
device.config_line = line_number
device.index = len(self.devices[device.name])
self.devices[device.name].append(device)
elif word0.startswith("CNTPAR:"):
item = self.collection[-1] # most recent item
if isinstance(item, (SpecSignal, SpecCounter)):
k, v = line[len("CNTPAR:"):].split("=")
item.cntpar[k.strip()] = v.strip()
elif word0.startswith("MOTPAR:"):
if motor is not None:
k, v = line[len("MOTPAR:"):].split("=")
motor.motpar[k.strip()] = v.strip()
elif re.match("CNT\d*", line) is not None:
counter = SpecCounter(line)
counter.setDevice(self.devices)
if counter.ctrl == "EPICS_PV":
signal = SpecSignal(counter.mne, counter.name, counter.pvname, line)
signal.setDevice(self.devices)
self.collection.append(signal)
else:
counter.setDevice(self.devices)
if counter.pvname is not None:
pvname = counter.pvname.split(".")[0]
if pvname not in self.scalers:
Expand Down

0 comments on commit 34ade90

Please sign in to comment.