コード例 #1
0
ファイル: opal_config_scan.py プロジェクト: bhill-slac/lcls2
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B', metavar='PVBASE', required=True, help='PV base')
    parser.add_argument('-p', type=int, choices=range(0, 8), default=0,
                        help='platform (default 0)')
    parser.add_argument('-x', metavar='XPM', type=int, required=True, help='master XPM')
    parser.add_argument('-C', metavar='COLLECT_HOST', default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t', type=int, metavar='TIMEOUT', default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-c', type=int, metavar='READOUT_COUNT', default=1, help='# of events to aquire at each step (default 1)')
    parser.add_argument('-g', type=int, metavar='GROUP_MASK', help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config', metavar='ALIAS', help='configuration alias (e.g. BEAM)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()

    if args.g is not None:
        if args.g < 1 or args.g > 255:
            parser.error('readout group mask (-g) must be 1-255')

    if args.c < 1:
        parser.error('readout count (-c) must be >= 1')

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    try:
        instrument = control.getInstrument()
    except KeyboardInterrupt:
        instrument = None

    if instrument is None:
        sys.exit('Error: failed to read instrument name (check -C <COLLECT_HOST>)')

    # configure logging handlers
    if args.v:
        level=logging.DEBUG
    else:
        level=logging.WARNING
    logger = SysLog(instrument=instrument, level=level)
    logging.info('logging initialized')

    # get initial DAQ state
    daqState = control.getState()
    logging.info('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    # optionally set BEAM or NOBEAM
    if args.config is not None:
        # config alias request
        rv = control.setConfig(args.config)
        if rv is not None:
            logging.error('%s' % rv)

    # instantiate MyDAQ
    mydaq = MyDAQ(control, daqState=daqState, args=args)

    mydaq.stage()

    # -- begin script --------------------------------------------------------

    configure_dict = {"configure": {"reconfig_keys": ["tmoopal_0:user.start_ns", "tmoopal_0:user.gate_ns"]}}

    for start_ns in (0, 1000):
        for gate_ns in (10000, 20000):
            beginstep_dict = {"beginstep": {"reconfig_values": {"tmoopal_0:user.start_ns": start_ns, "tmoopal_0:user.gate_ns": gate_ns}}}
            # trigger
            mydaq.trigger(phase1Info = dict(configure_dict, **beginstep_dict))

    # -- end script ----------------------------------------------------------

    mydaq.unstage()

    mydaq.push_socket.send_string('shutdown') #shutdown the daq communicator thread
    mydaq.comm_thread.join()
コード例 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    group = parser.add_mutually_exclusive_group()
    group.add_argument('--config', metavar='ALIAS', help='configuration alias')
    group.add_argument('-B',
                       action="store_true",
                       help='shortcut for --config BEAM')
    args = parser.parse_args()

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    # get initial DAQ state
    daqState = control.getState()
    print('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    config = None
    if args.config:
        config = args.config
    elif args.B:
        config = "BEAM"

    if config:
        # config alias request
        rv = control.setConfig(config)
        if rv is not None:
            print('Error: %s' % rv)

    RE = RunEngine({})

    # cpo thinks this is more for printout of each step
    from bluesky.callbacks.best_effort import BestEffortCallback
    bec = BestEffortCallback()

    # Send all metadata/data captured to the BestEffortCallback.
    RE.subscribe(bec)

    # Make plots update live while scans run.
    #from bluesky.utils import install_kicker
    #install_kicker()

    from ophyd.sim import det, motor
    from bluesky.plans import scan, count
    from bluesky.preprocessors import fly_during_wrapper

    mydaq = MyDAQ(control, motor, daqState=daqState)
    dets = [mydaq]  # just one in this case, but it could be more than one

    print('motor', motor.position,
          motor.name)  # in some cases we have to look at ".value"
    RE(scan(dets, motor, -1, 1, 3))
    print('motor', motor.position)
    #RE(count(dets, num=3))

    # only 1 callback! and 3 steps inside it.  doesn't feel useful for us
    #RE(fly_during_wrapper(count([det], num=3), dets))

    mydaq.push_socket.send_string('shutdown')  #shutdown the daq thread
    mydaq.comm_thread.join()
コード例 #3
0
if args.v:
    print(f'Trying to connect with DAQ at host {args.C} platform {args.p}...')
instrument = control.getInstrument()
if instrument is None:
    print(f'Failed to connect with DAQ at host {args.C} platform {args.p}')
    sys.exit(1)

if args.v:
    level = logging.DEBUG
else:
    level = logging.WARNING
logger = SysLog(instrument=instrument, level=level)
logging.info('logging initialized')

# get initial DAQ state
daqState = control.getState()
logging.info('initial state: %s' % daqState)
if daqState == 'error':
    sys.exit(1)

# optionally set BEAM or NOBEAM
if args.config is not None:
    # config alias request
    rv = control.setConfig(args.config)
    if rv is not None:
        logging.error('%s' % rv)

RE = RunEngine({})

# cpo thinks this is more for printout of each step
from bluesky.callbacks.best_effort import BestEffortCallback
コード例 #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B', metavar='PVBASE', required=True, help='PV base')
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-x',
                        metavar='XPM',
                        type=int,
                        required=True,
                        help='master XPM')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-c',
                        type=int,
                        metavar='READOUT_COUNT',
                        default=1,
                        help='# of events to aquire at each step (default 1)')
    parser.add_argument('-g',
                        type=int,
                        metavar='GROUP_MASK',
                        help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config',
                        metavar='ALIAS',
                        help='configuration alias (e.g. BEAM)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()

    if args.g is not None:
        if args.g < 1 or args.g > 255:
            parser.error('readout group mask (-g) must be 1-255')

    if args.c < 1:
        parser.error('readout count (-c) must be >= 1')

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    # configure logging handlers
    instrument = control.getInstrument()
    if args.v:
        level = logging.DEBUG
    else:
        level = logging.WARNING
    logger = SysLog(instrument=instrument, level=level)
    logging.info('logging initialized')

    # get initial DAQ state
    daqState = control.getState()
    logging.info('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    # optionally set BEAM or NOBEAM
    if args.config is not None:
        # config alias request
        rv = control.setConfig(args.config)
        if rv is not None:
            logging.error('%s' % rv)

    RE = RunEngine({})

    # cpo thinks this is more for printout of each step
    from bluesky.callbacks.best_effort import BestEffortCallback
    bec = BestEffortCallback()

    # Send all metadata/data captured to the BestEffortCallback.
    RE.subscribe(bec)

    from ophyd.sim import motor1, motor2
    from bluesky.plans import scan

    # instantiate MyDAQ object
    mydaq = MyDAQ(control, daqState=daqState, args=args)
    dets = [mydaq]  # just one in this case, but it could be more than one

    # configure MyDAQ object with a set of motors
    mydaq.configure(motors=[motor1, motor2])

    # Scan motor1 from -10 to 10 and motor2 from -0.1 to 0.1, stopping
    # at 15 equally-spaced points along the way and reading dets.
    RE(scan(dets, motor1, -10, 10, motor2, -0.1, 0.1, 15))

    mydaq.push_socket.send_string('shutdown')  #shutdown the daq thread
    mydaq.comm_thread.join()
コード例 #5
0
ファイル: opal_config_scan.py プロジェクト: pcdshub/lcls2
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-B', metavar='PVBASE', required=True, help='PV base')
    parser.add_argument('-p',
                        type=int,
                        choices=range(0, 8),
                        default=0,
                        help='platform (default 0)')
    parser.add_argument('-x',
                        metavar='XPM',
                        type=int,
                        required=True,
                        help='master XPM')
    parser.add_argument('-C',
                        metavar='COLLECT_HOST',
                        default='localhost',
                        help='collection host (default localhost)')
    parser.add_argument('-t',
                        type=int,
                        metavar='TIMEOUT',
                        default=10000,
                        help='timeout msec (default 10000)')
    parser.add_argument('-c',
                        type=int,
                        metavar='READOUT_COUNT',
                        default=1,
                        help='# of events to aquire at each step (default 1)')
    parser.add_argument('-g',
                        type=int,
                        metavar='GROUP_MASK',
                        help='bit mask of readout groups (default 1<<plaform)')
    parser.add_argument('--config',
                        metavar='ALIAS',
                        help='configuration alias (e.g. BEAM)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()

    if args.g is not None:
        if args.g < 1 or args.g > 255:
            parser.error('readout group mask (-g) must be 1-255')

    if args.c < 1:
        parser.error('readout count (-c) must be >= 1')

    # instantiate DaqControl object
    control = DaqControl(host=args.C, platform=args.p, timeout=args.t)

    try:
        instrument = control.getInstrument()
    except KeyboardInterrupt:
        instrument = None

    if instrument is None:
        sys.exit(
            'Error: failed to read instrument name (check -C <COLLECT_HOST>)')

    # configure logging handlers
    if args.v:
        level = logging.DEBUG
    else:
        level = logging.WARNING
    logger = SysLog(instrument=instrument, level=level)
    logging.info('logging initialized')

    # get initial DAQ state
    daqState = control.getState()
    logging.info('initial state: %s' % daqState)
    if daqState == 'error':
        sys.exit(1)

    # optionally set BEAM or NOBEAM
    if args.config is not None:
        # config alias request
        rv = control.setConfig(args.config)
        if rv is not None:
            logging.error('%s' % rv)

    # instantiate ConfigurationScan
    scan = ConfigurationScan(control, daqState=daqState, args=args)

    scan.stage()

    # -- begin script --------------------------------------------------------

    # PV scan setup
    motors = [
        MyFloatPv("tmoopal_step_value"),
        MyStringPv("tmoopal_step_docstring")
    ]
    scan.configure(motors=motors)

    # configuration scan setup
    keys_dict = {
        "configure": {
            "step_keys": ["tmoopal_0:user.black_level"],
            "NamesBlockHex":
            scan.getBlock(transitionid=DaqControl.transitionId['Configure'],
                          add_names=True,
                          add_shapes_data=False).hex()
        }
    }
    # scan loop
    for black_level in [15, 31, 47]:
        # update
        scan.update(value=scan.step_count())
        values_dict = \
          {"beginstep": {"step_values":        {"tmoopal_0:user.black_level": black_level},
                         "ShapesDataBlockHex": scan.getBlock(transitionid=DaqControl.transitionId['BeginStep'],
                                                             add_names=False, add_shapes_data=True).hex()}}
        # trigger
        scan.trigger(phase1Info={**keys_dict, **values_dict})

    # -- end script ----------------------------------------------------------

    scan.unstage()

    scan.push_socket.send_string(
        'shutdown')  #shutdown the daq communicator thread
    scan.comm_thread.join()
コード例 #6
0
from types import SimpleNamespace

logger = logging.getLogger(__name__)

_control = DaqControl(
    host='drp-neh-ctl001',
    platform=2,
    timeout=1000,
)

_instr = _control.getInstrument()
if _instr is None:
    err = 'Failed to connect to LCLS-II DAQ'
    logger.error(err)

_state = _control.getState()
if _state == 'error':
    err = 'Daq is in error state'
    logger.error(err)

# Construct the args that DaqScan is looking for
args = SimpleNamespace(
    v=True,  # Verbosity
    B='DAQ:NEH',  # PV Base
    detname='scan',  # Detector name
    scantype='scan',  # scan type
    g=36,  # Bit mask of readout groups
    c=120,  # Events per step
    p=2,  # Platform
    x=0,  # Master XPM
)