Skip to content

Commit

Permalink
Merge pull request #360 from lnls-sirius/PR-improve-ps-ioc-no-general…
Browse files Browse the repository at this point in the history
…-channel

Improve PRU: avoid creating "general" ethbridge channel/thread
  • Loading branch information
xresende authored Feb 3, 2020
2 parents ce2f431 + 204a836 commit ecfc185
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 49 deletions.
22 changes: 4 additions & 18 deletions siriuspy/siriuspy/pwrsupply/beaglebone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
22 changes: 12 additions & 10 deletions siriuspy/siriuspy/pwrsupply/controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""E2SController."""

from siriuspy.namesys import SiriusPVName as _PVName


class PSController:
"""Class used to communicate with PS controller.
Expand All @@ -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:
Expand Down Expand Up @@ -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():
Expand All @@ -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))
Expand All @@ -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')


Expand All @@ -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
Expand Down
22 changes: 13 additions & 9 deletions siriuspy/siriuspy/pwrsupply/pru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -116,5 +120,5 @@ def _UART_read(self):
return value

def _close(self):
self._ethbrigde.close()
# self._ethbrigde.close()
return None
1 change: 1 addition & 0 deletions siriuspy/siriuspy/pwrsupply/prucontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
18 changes: 7 additions & 11 deletions siriuspy/siriuspy/pwrsupply/psmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/pwrsupply/siggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import time as _t
import math as _math
# import numpy as _np


DEFAULT_SIGGEN_CONFIG = (
0, # type [0:Sine]
Expand Down

0 comments on commit ecfc185

Please sign in to comment.