Skip to content

Commit

Permalink
Merge pull request #382 from BCDA-APS/381-spec2ophyd
Browse files Browse the repository at this point in the history
spec2ophyd analyses
  • Loading branch information
prjemian authored Jul 21, 2020
2 parents cb0bf61 + e746f63 commit 83cfab7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env python

"""
test spec2ophyd
develop spec2ophyd
"""

import os
import spec2ophyd
import sys


def main():
cf = "config-CNTPAR"
cf = os.path.join(os.path.dirname(__file__), "config-MOTPAR")
sys.argv.append(cf)
spec2ophyd.main()

Expand Down
40 changes: 39 additions & 1 deletion apstools/migration/spec2ophyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ def __init__(self, config_file):
self.collection = []
self.unhandled = []

def find_pv_in_collection(self, pv):
for obj in self.collection:
if pv == obj.pvname:
return obj

def read_config(self, config_file=None):
self.config_file = config_file or self.config_file
motor = None
Expand Down Expand Up @@ -382,6 +387,19 @@ def read_config(self, config_file=None):
self.scalers.append(pvname)
self.collection.append(scaler)

if counter.pvname is None:
scaler = None
else:
scaler = self.find_pv_in_collection(
counter.pvname.split(".")[0])
if scaler is not None:
# clock = scaler.channels.chan01.s
fmt = "%s = %s.channels.chan%02d.s"
reassignment = fmt % (
counter.mne,
scaler.name,
counter.chan+1)
counter = reassignment
self.collection.append(counter)
elif re.match("MOT\d*", line) is not None:
motor = SpecMotor(line)
Expand All @@ -392,8 +410,28 @@ def read_config(self, config_file=None):


def create_ophyd_setup(spec_config):
print('"""')
print("ophyd commands from SPEC config file")
print()
print(f"file: {spec_config.config_file}")
print()
print("CAUTION: Review the object names below before using them!")
print(" Some names may not be valid python identifiers")
print(" or may be reserved (such as ``time`` or ``del``)")
print(" or may be vulnerable to re-definition because")
print(" they are short or common.")
print('"""')
print()
print("from ophyd import EpicsMotor, EpicsSignal")
print("from ophyd.scaler import ScalerCH")
print()
for device in spec_config.collection:
print(f"{device.ophyd_config()}")
if hasattr(device, "ophyd_config"):
print(f"{device.ophyd_config()}")
if hasattr(device, "signal_name") and device.signal_name == "ScalerCH":
print(f"{device.name}.select_channels(None)")
else:
print(device)


def get_options():
Expand Down

0 comments on commit 83cfab7

Please sign in to comment.