diff --git a/siriuspy/siriuspy/pwrsupply/beaglebone.py b/siriuspy/siriuspy/pwrsupply/beaglebone.py index 185c7e88e..77299945a 100644 --- a/siriuspy/siriuspy/pwrsupply/beaglebone.py +++ b/siriuspy/siriuspy/pwrsupply/beaglebone.py @@ -251,7 +251,7 @@ def create(bbbname=None): scanning=False, freq=freq) - connections, devices_ids = dict(), dict() + psname2dev = dict() fields, functions = dict(), dict() for device in devices: @@ -276,16 +276,15 @@ def create(bbbname=None): fields.update(_fields) functions.update(_functions) - # build connections and device_ids dicts - devices_ids[psname] = dev_id - connections[psname] = Connection(dev_id, pru_controller) + # build device_ids dict + psname2dev[psname] = dev_id # add database to dictionary databases[psname] = database # build controller controller = psmodel.controller( - fields, functions, connections, pru_controller, devices_ids) + fields, functions, pru_controller, psname2dev) # add controller to dictionary for device in devices: @@ -414,16 +413,3 @@ def _check_ioc_online(devices_dict): pvname=pvname, use_prefix=False, timeout=0.5) if running: raise ValueError('Another IOC is already running !') - - -class Connection: - """Object that checks if a device is connected.""" - - def __init__(self, device_id, pru_controller): - """Init.""" - self._device_id = device_id - self._pru_controller = pru_controller - - def connected(self): - """Return wether device is connected.""" - return self._pru_controller.check_connected(self._device_id) diff --git a/siriuspy/siriuspy/pwrsupply/controller.py b/siriuspy/siriuspy/pwrsupply/controller.py index 841753bfd..8bc564a89 100644 --- a/siriuspy/siriuspy/pwrsupply/controller.py +++ b/siriuspy/siriuspy/pwrsupply/controller.py @@ -1,5 +1,7 @@ """E2SController.""" +from siriuspy.namesys import SiriusPVName as _PVName + class PSController: """Class used to communicate with PS controller. @@ -15,12 +17,13 @@ class PSController: 'KL-SP', 'KL-RB', 'KLRef-Mon', 'KL-Mon', 'SL-SP', 'SL-RB', 'SLRef-Mon', 'SL-Mon'} - def __init__(self, readers, functions, connections, pru_controller): + def __init__(self, readers, functions, + pru_controller, psname2dev): """Create class properties.""" self._readers = readers self._functions = functions - self._connections = connections self._pru_controller = pru_controller + self._psname2dev = psname2dev self._fields = set() for name in self._readers: @@ -71,7 +74,8 @@ def write(self, device_name, field, value): def check_connected(self, device_name): """Check if device is connected.""" - return self._connections[device_name].connected() + dev_id = self._psname2dev[device_name] + return self._pru_controller.check_connected(dev_id) def _init_setpoints(self): for key, reader in self._readers.items(): @@ -81,7 +85,11 @@ def _init_setpoints(self): continue if key.endswith(('-Sel', '-SP')): rb_field = PSController._get_readback_field(key) + + # NOTE: to be updated + # rb_field = _PVName.from_sp2rb(key) rdr = self._readers[rb_field] + if rdr is None: raise AttributeError( 'Could not find reader for "{}"'.format(rb_field)) @@ -93,7 +101,7 @@ def _init_setpoints(self): @staticmethod def _get_readback_field(field): - # TODO: check if siriuspvname already has a function for this + # NOTE: to be updated return field.replace('-Sel', '-Sts').replace('-SP', '-RB') @@ -109,12 +117,6 @@ class StandardPSController(PSController): 'CycleAuxParam-SP', # start index of auxparams ] - def __init__(self, readers, functions, connections, pru_controller, - devices): - """Call super.""" - super().__init__(readers, functions, connections, pru_controller) - self._devices = devices - def write(self, device_name, field, value): """Override write method.""" pvname = device_name + ':' + field diff --git a/siriuspy/siriuspy/pwrsupply/pru.py b/siriuspy/siriuspy/pwrsupply/pru.py index 5b5e916ca..5acd7bf4f 100644 --- a/siriuspy/siriuspy/pwrsupply/pru.py +++ b/siriuspy/siriuspy/pwrsupply/pru.py @@ -8,7 +8,7 @@ # check PRUserial485 package version -__version_eth_required__ = '2.4.0' # eth-PRUserial485 +__version_eth_required__ = '2.5.0' # eth-PRUserial485 __version_eth_implmntd__ = _PRUserial485.__version__ if __version_eth_implmntd__ != __version_eth_required__: _ERR_MSG = 'Incompatible PRUserial485 library versions: {} != {}'.format( @@ -85,7 +85,8 @@ def __init__(self, bbbname=None, ip_address=None): print('IP_ADDRESS: ', ip_address) # start communication threads - self._ethbrigde = _EthBrigdeClient(ip_address=ip_address) + self._ethbrigde = _EthBrigdeClient( + ip_address=ip_address, use_general=False) self._ethbrigde.threads_start() # print prulib version @@ -97,13 +98,16 @@ def __init__(self, bbbname=None, ip_address=None): # init PRUserial485 interface PRUInterface.__init__(self) + # NOTE: open is done automatically by eth-brigde server + # and cannot be used when use_general = False + # # start PRU library and set PRU to sync off - baud_rate = 6 - mode = b"M" # "S": slave | "M": master - ret = self._ethbrigde.open(baud_rate, mode) - if ret != PRUInterface.OK: - raise ValueError(('Error {} returned in ' - 'PRUserial485_open').format(ret)) + # baud_rate = 6 + # mode = b"M" # "S": slave | "M": master + # ret = self._ethbrigde.open(baud_rate, mode) + # if ret != PRUInterface.OK: + # raise ValueError(('Error {} returned in ' + # 'PRUserial485_open').format(ret)) def _UART_write(self, stream, timeout): # this method send streams through UART to the RS-485 line. @@ -116,5 +120,5 @@ def _UART_read(self): return value def _close(self): - self._ethbrigde.close() + # self._ethbrigde.close() return None diff --git a/siriuspy/siriuspy/pwrsupply/prucontroller.py b/siriuspy/siriuspy/pwrsupply/prucontroller.py index fd9ed098f..dae601f49 100644 --- a/siriuspy/siriuspy/pwrsupply/prucontroller.py +++ b/siriuspy/siriuspy/pwrsupply/prucontroller.py @@ -31,6 +31,7 @@ class PRUController: of the Beaglebone computer connected through a serial line to power supply controllers. """ + # NOTE: All private methods starting with '_bsmp' string make a direct # write to the serial line. diff --git a/siriuspy/siriuspy/pwrsupply/psmodel.py b/siriuspy/siriuspy/pwrsupply/psmodel.py index 69c55429a..1516a4132 100644 --- a/siriuspy/siriuspy/pwrsupply/psmodel.py +++ b/siriuspy/siriuspy/pwrsupply/psmodel.py @@ -174,8 +174,7 @@ def function(self, device_ids, epics_field, pru_controller, setpoints): """Return function.""" raise NotImplementedError - def controller(self, readers, writers, connections, - pru_controller, devices): + def controller(self, readers, writers, pru_controller, devices): """Return controller.""" raise NotImplementedError @@ -306,11 +305,10 @@ def function(self, device_ids, epics_field, pru_controller, setpoints): else: return _functions.BSMPFunctionNull() - def controller(self, readers, writers, connections, - pru_controller, devices): + def controller(self, readers, writers, pru_controller, devices): """Return controller.""" return _controller.StandardPSController( - readers, writers, connections, pru_controller, devices) + readers, writers, pru_controller, devices) class PSModelFBP_FOFB(PSModelFBP): @@ -784,11 +782,10 @@ def function(self, device_ids, epics_field, pru_controller, setpoints): else: return _functions.BSMPFunctionNull() - def controller(self, readers, writers, connections, - pru_controller, devices): + def controller(self, readers, writers, pru_controller, devices): """Return controller.""" return _controller.PSController( - readers, writers, connections, pru_controller) + readers, writers, pru_controller, devices) class PSModelFAC_2S_ACDC(_PSModel): @@ -848,11 +845,10 @@ def function(self, device_ids, epics_field, pru_controller, setpoints): else: return _functions.BSMPFunctionNull() - def controller(self, readers, writers, connections, - pru_controller, devices): + def controller(self, readers, writers, pru_controller, devices): """Return controller.""" return _controller.PSController( - readers, writers, connections, pru_controller) + readers, writers, pru_controller, devices) class PSModelFAC_2P4S_ACDC(PSModelFAC_2S_ACDC): diff --git a/siriuspy/siriuspy/pwrsupply/siggen.py b/siriuspy/siriuspy/pwrsupply/siggen.py index 0eb2b9d4e..9f8797dfd 100644 --- a/siriuspy/siriuspy/pwrsupply/siggen.py +++ b/siriuspy/siriuspy/pwrsupply/siggen.py @@ -2,7 +2,7 @@ import time as _t import math as _math -# import numpy as _np + DEFAULT_SIGGEN_CONFIG = ( 0, # type [0:Sine]