def test_async(self): def written_to(**kwargs): logger.debug('written_to-> %s' % kwargs) pv_name = get_pvname() pvs = PyPV(pv_name, 0.0, server=server, written_cb=written_to) pvc = client_pv(pv_name) caget(pvc) pvc.put(10.0) caget(pvc) def written_to_async(timestamp=None, value=None, status=None, severity=None): raise AsyncCompletion() def finished(**kwargs): logger.debug('caput completed', kwargs) pvs._written_cb = written_to_async pvc.put(12, wait=False, use_complete=True, callback=finished) time.sleep(0.05) # Indicate completion to client pvs.async_done() caget(pvc)
def _add_builtin(self, name, value, cb=None): """ Does setup for the built-in PVs, which are all basically the same. """ rbv = PyPV(name + '_RBV', value=value, server=self.server) if cb is None: def cb(**kwargs): pass def callback(value=None, rbv=rbv, cb=cb, **kwargs): rbv.put(value) cb(value=value, **kwargs) setter = PyPV(name, value=value, server=self.server, written_cb=callback) self.ad_directory[rbv.name] = rbv self.ad_directory[setter.name] = setter
def test_numpy(self): pv_name = get_pvname() arr = np.arange(10) pvs = PyPV(pv_name, arr, server=server) pvc = client_pv(pv_name) pvs[1:4] = 4 result = [0, 4, 4, 4, 4, 5, 6, 7, 8, 9] assert_array_equal(caget(pvc), result) assert_array_equal(pvs[1:4], [4, 4, 4]) if 0: # TODO pyepics doesn't play well with resizing pvc.disconnect() pvc.connect() pvs.resize(20) pvs[10:] = result pvc._args['count'] = 20 assert_array_equal(caget(pvc), result * 2)
def test_float(self, pv_name='testing'): pv_name = get_pvname() limits = Limits(lolo=0.1, low=0.2, high=0.4, hihi=0.5) # pvs = server, pvc = client pvs = PyPV(pv_name, 0.0, limits=limits, units='test', server=server) pvc = client_pv(pv_name) logger.info('client put, client get') for i in range(6): value = 0.1 * i pvc.put(0.1 * i) self.assertEquals(caget(pvc), value) logger.info('server put, client get') for i in range(6): value = 0.1 * i pvs.value = value self.assertEquals(caget(pvc), value) return pvc
def initialize_pvs(self, name, value): """ Given valid arguments from __init__, create the pvs dictionary for this function. """ if isinstance(value, dict): pvs = {} for key, start_value in value.items(): pvs.update(self.initialize_pvs(key, start_value)) return pvs else: return {name: PyPV(name, value, server=self.pvserver)}
def test(): config.setup_logging([__name__, 'pypvserver.pv']) server = config.get_server() logger.info('Creating PV "pv1", a floating-point type') python_pv = PyPV('pv1', 123.0, server=server) # full_pvname includes the server prefix pvname = python_pv.full_pvname logger.info('... which is %s including the server prefix', pvname) signal = epics.PV(pvname) signal.add_callback(updated) time.sleep(0.1) for value in range(10): logger.info('Updating the value on the server-side to: %s', value) python_pv.value = value time.sleep(0.05) logger.info('Done')
def test_string(self): pv_name = get_pvname() pvs = PyPV(pv_name, 'test', units='test') server.add_pv(pvs) pvc = client_pv(pv_name) logger.info(pvc.info) value = '"string pv"' pvc.put(value) get_value = pvc.get(use_monitor=False) logger.info('string pv: %s' % get_value) self.assertEquals(value, get_value)
def test_enum(self): pv_name = get_pvname() pvs = PyPV(pv_name, ['a', 'b', 'c'], units='test', minor_states=['a'], major_states=['c']) server.add_pv(pvs) pvc = client_pv(pv_name) self.assertEquals(caget(pvc, as_string=True), 'a') pvc.put('b') self.assertEquals(caget(pvc, as_string=True), 'b') pvc.put('c') self.assertEquals(caget(pvc, as_string=True), 'c')
import logging import time # import ophyd from pypvserver import (PypvServer, PyPV, logger as server_logger) logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) server_logger.setLevel(logging.DEBUG) logging.basicConfig() server = PypvServer(prefix='test_prefix:') logger.info('Creating PV "pv1", a floating-point type') python_pv = PyPV('pv1', 123.0, server=server) # full_pvname includes the server prefix pvname = python_pv.full_pvname logger.info('... which is %s including the server prefix', pvname) time.sleep(0.1) for value in range(10): logger.info('Updating the value on the server-side to: %s', value) python_pv.value = value time.sleep(0.05) logger.info('Done') try: while True:
# import ophyd from pypvserver import (PypvServer, PyPV, logger as server_logger) logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) server_logger.setLevel(logging.DEBUG) logging.basicConfig() server = PypvServer(prefix='test_prefix:') logger.info('Creating PV "pv1", a floating-point type') python_pv = PyPV('pv1', 123.0, server=server) # full_pvname includes the server prefix pvname = python_pv.full_pvname logger.info('... which is %s including the server prefix', pvname) time.sleep(0.1) for value in range(10): logger.info('Updating the value on the server-side to: %s', value) python_pv.value = value time.sleep(0.05) logger.info('Done') try: