Exemple #1
0
def main():
    pvdb = {}
    with open("xcor_list.json") as f:
        mags = json.load(f)
        pvs = [MagnetPV(mag["devname"], "XCOR{}".format(mag["devname"].split(":")[-1]), prefix=mag["devname"]) for mag in mags]
        for pv in pvs:
            pvdb.update(**pv.pvdb)
                  
    _, run_options = ioc_arg_parser(
        default_prefix='',
        desc="Simulated Corrector Magnet IOC")
    run(pvdb, **run_options)
Exemple #2
0
        async def random(self, instance):
            logger.debug('read random from %s', type(self).__name__)
            return random.randint(1, 100)

    # PV: {prefix}group4:subgroup4:random
    # (TODO BUG) {prefix}subgroup4:random
    @SubGroup
    class group4(PVGroup):
        @SubGroup
        class subgroup4(PVGroup):
            @pvproperty
            async def random(self, instance):
                logger.debug('read random from %s', type(self).__name__)
                return random.randint(1, 100)


if __name__ == '__main__':
    ioc_options, run_options = ioc_arg_parser(
        default_prefix='subgroups:',
        desc='Run an IOC with groups of groups of PVs.')
    ioc = MyPVGroup(**ioc_options)

    # here's what accessing a pvproperty descriptor looks like:
    print('random using the descriptor getter is:', ioc.random)

    # and for subgroups:
    print('subgroup4 is:', ioc.group4.subgroup4)
    print('subgroup4.random is:', ioc.group4.subgroup4.random)

    run(ioc.pvdb, **run_options)
Exemple #3
0
def main():
    service = CavityService()
    asyncio.get_event_loop()
    _, run_options = ioc_arg_parser(default_prefix='',
                                    desc="Simulated CM Cavity Service")
    run(service, **run_options)
Exemple #4
0
def main():
    service = KlystronService()
    loop = asyncio.get_event_loop()
    _, run_options = ioc_arg_parser(default_prefix='',
                                    desc="Simulated Klystron Service")
    run(service, **run_options)
    name="b",
    value=2.0,
    record='ai',
    doc='A float',
    put=put_handler,
)

pv_c = PVSpec(
    name="c",
    value=[1, 2, 3],
    record='waveform',
    doc='An array of integers',
    put=put_handler,
)

pvdb = {
    pvspec.name: pvspec.create(group=None)
    for pvspec in [pv_a, pv_b, pv_c]
}

if __name__ == '__main__':
    print("pvdb contents:", pvdb)

    ioc_options, run_options = ioc_arg_parser(
        default_prefix='pvspec:',
        desc="A simple IOC without using the PVGroup-style class syntax.")

    # It's up to you to add on the prefix and support any other ioc_options:
    pvdb = {ioc_options['prefix'] + name: data for name, data in pvdb.items()}
    run(pvdb, **run_options)
Exemple #6
0
    input_count_rate = pvproperty(
        name='InputCountRate', dtype=unknown, read_only=True)
    output_count_rate = pvproperty(
        name='OutputCountRate', dtype=unknown, read_only=True)
    mca_bin_width = pvproperty(
        name='MCABinWidth_RBV', dtype=unknown, read_only=True)
    calibration_energy = pvproperty(
        name='CalibrationEnergy_RBV', dtype=unknown, read_only=True)
    current_pixel = pvproperty(name='CurrentPixel', dtype=unknown)
    dynamic_range = pvproperty(
        name='DynamicRange_RBV', dtype=unknown, read_only=True)
    preset_events = pvproperty_with_rbv(name='PresetEvents', dtype=unknown)
    preset_triggers = pvproperty_with_rbv(name='PresetTriggers', dtype=unknown)
    trace_data = pvproperty(name='TraceData', dtype=unknown)
    trace_mode = pvproperty_with_rbv(value='Mode', name='TraceMode', dtype=str)
    trace_time_array = pvproperty(name='TraceTimeArray', dtype=unknown)
    trace_time = pvproperty_with_rbv(name='TraceTime', dtype=unknown)


class McaDxpIOC(PVGroup):
    mca = SubGroup(EpicsMCAGroup, prefix='mca')
    dxp = SubGroup(EpicsDXPGroup, prefix='dxp:')


if __name__ == '__main__':
    ioc_options, run_options = ioc_arg_parser(
        default_prefix='test_mca:',
        desc="ophyd.tests.test_mca test IOC")
    ioc = McaDxpIOC(**ioc_options)
    run(ioc.pvdb, **run_options)
        # Loop and grab items from the queue one at a time
        async for event, context, data in ctx.monitor(self.pv_to_mirror):
            if event == 'subscription':
                print('* Client pushed a new value in the queue')
                print(f'\tValue={data.data} {data.metadata}')

                # Mirror the value, status, severity, and timestamp:
                await self.mirrored.write(data.data,
                                          timestamp=data.metadata.timestamp,
                                          status=data.metadata.status,
                                          severity=data.metadata.severity)
            elif event == 'connection':
                print(f'* Client connection state changed: {data}')
                if data == 'disconnected':
                    # Raise an alarm - our client PV is disconnected.
                    await self.mirrored.write(
                        self.mirrored.value,
                        status=ca.AlarmStatus.LINK,
                        severity=ca.AlarmSeverity.MAJOR_ALARM)


if __name__ == '__main__':
    ioc_options, run_options = ioc_arg_parser(
        default_prefix='mirror:',
        desc=dedent(MirrorClientIOC.__doc__),
        supported_async_libs=('asyncio', ),
    )

    ioc = MirrorClientIOC('simple:A', **ioc_options)
    run(ioc.pvdb, startup_hook=ioc.__ainit__, **run_options)
Exemple #8
0
 def run_server():
     import asyncio
     asyncio.set_event_loop(asyncio.new_event_loop())
     run(ioc.pvdb, module_name='caproto.asyncio.server')
Exemple #9
0
    async def motor(fields, instance, value):
        """ tweak_motor_forward motor.TWF """
        slf = fields.parent.group
        pos = slf.motor.value
        move_by = slf.motor.field_inst.tweak_step_size.value
        logger.info(f"TWF: TWV={move_by}, passing {pos+move_by} to VAL")
        await slf.motor.write(pos + move_by)

    @motor.fields.tweak_motor_reverse.putter
    async def motor(fields, instance, value):
        """ tweak_motor_reverse motor.TWR"""
        slf = fields.parent.group
        pos = slf.motor.value
        move_by = slf.motor.field_inst.tweak_step_size.value
        logger.info(f"TWR: TWV={move_by}, passing {pos-move_by} to VAL")
        await slf.motor.write(slf.motor.value - move_by)


if __name__ == "__main__":
    ioc_options, run_options = ioc_arg_parser(default_prefix=PV_prefix,
                                              desc="demo IOC using caproto")
    print("ioc_options" + str(ioc_options))

    ioc = DemoIOC(**ioc_options)

    run_options["log_pv_names"] = True
    print("run_options:" + str(run_options))
    run(ioc.pvdb, **run_options)  # blocking

    print("end")
Exemple #10
0
def main():
    service = GenericPVService()
    _, run_options = ioc_arg_parser(default_prefix='',
                                    desc="Generic PV Service")
    run(service, **run_options)
        """
        called when the a new value is written into "jog" PV
        """
        print(f"Server: {'bit'} Got 'put' request from outside: new value is {value} and type {type(value)}")
        if self.device is not None:
            self.device.set_bit_client(value)
        else:
            print('device is None')

    @set_bit.putter
    async def set_bit(self, instance, value):
        """
        called when the a new value is written into "jog" PV
        """
        print(f"Server: {'set_bit'} Got 'put' request from outside: new value is {value} and type {type(value)}")
        if self.device is not None:
            self.device.set_bit_server(value)
        else:
            print('device is None')

if __name__ == '__main__':
    device = Device()

    ioc_options, run_options = ioc_arg_parser(
        default_prefix='TEST:PUTTER.',
        desc='description')
    server  = Server(**ioc_options)
    server.device = device
    #start async caproto server IO
    run(server.pvdb, **run_options)
Exemple #12
0
def main():
    ioc_options, run_options = ioc_arg_parser(default_prefix=prefix,
                                              desc=IOCMain.__doc__)
    ioc = create_ioc(eV_pv=eV_name, pmps_run_pv=pmps_run_name, **ioc_options)
    run(ioc.pvdb, **run_options)
    image_mean = pvproperty(value=0.0, precision=3)

    @image.startup  #this fubction will be executed on instantiaton
    async def image(self, instance, async_lib):
        while True:
            new_arr = random.randint(256, size=(3, 100, 100)).flatten()
            await self.image.write(value=new_arr)
            await self.image_mean.write(value=new_arr.mean())
            # Let the async library wait for the next iteration
            await async_lib.library.sleep(1)


if __name__ == '__main__':
    # The Record Name is specified by prefix
    prefix = 'TEST.'
    from pdb import pm
    from tempfile import gettempdir
    import logging
    print(gettempdir() + '/{}.log'.format(prefix))
    logging.basicConfig(filename=gettempdir() + '/{}.log'.format(prefix),
                        level=logging.DEBUG,
                        format="%(asctime)s %(levelname)s: %(message)s")

    ioc_options, run_options = ioc_arg_parser(default_prefix=prefix,
                                              desc='description')

    io_server = Server(**ioc_options)

    #start async caproto server IO
    run(io_server.pvdb, **run_options)