Skip to content

Commit

Permalink
Merge pull request #204 from dls-controls/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
coretl committed Mar 9, 2017
2 parents 74af88e + c61a57a commit 5c9c392
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
2 changes: 2 additions & 0 deletions examples/P45-MALC02.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
- blocks.ADCore.SimDetectorManager:
pvPrefix: BL45P-EA-XSP-01
mriPrefix: P45-XSP01
configDir: /tmp

- blocks.demo.TestRigSimManager:
mri: P45-SCAN02
sim: P45-XSP01
configDir: /tmp

- comms.pva.PvaServerComms:

6 changes: 1 addition & 5 deletions malcolm/comms/pva/pvaservercomms.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,7 @@ def update(self, changes):
# TODO: hasField() shouldn't be called if not path, but
# the code below might still need to be executed...
if path and self._pv_structure.hasField(path):
new_value = change[1]
if isinstance(new_value, OrderedDict):
new_value = self._server.strip_type_id(new_value)
else:
new_value = self._server.normalize(new_value)
new_value = self._server.value_for_pva_set(change[1])
self._pv_structure[path] = new_value
self.log_debug("PV updated structure: %s", self._pv_structure)
self._update_required = True
Expand Down
43 changes: 22 additions & 21 deletions malcolm/comms/pva/pvautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,32 @@ class PvaUtil(object):
def dict_to_pv_object(self, dict_in, empty_allowed=True):
structure = self.pva_structure_from_value(dict_in, empty_allowed)
if structure:
set_value = self.prepare_dict_set(dict_in)
set_value = self.value_for_pva_set(dict_in)
logging.debug("Set %s to %r", structure, set_value)
structure.set(set_value)
return structure

def prepare_dict_set(self, dict_in):
set_value = OrderedDict()
for key, value in dict_in.items():
# Turn it into something that pvaccess can just set
if isinstance(value, StringArray):
set_value[key] = list(value)
elif isinstance(value, (np.number, np.ndarray)):
set_value[key] = value.tolist()
elif isinstance(value, dict):
dict_set = self.prepare_dict_set(value)
if dict_set:
set_value[key] = dict_set
elif isinstance(value, list):
if [x for x in value if isinstance(x, dict)]:
set_value[key] = [self.dict_to_pv_object(v) for v in value]
else:
set_value[key] = value
elif key != "typeid":
set_value[key] = value
return set_value
def value_for_pva_set(self, value):
# Turn it into something that pvaccess can just set
if isinstance(value, StringArray):
value = list(value)
elif isinstance(value, (np.number, np.ndarray)):
value = value.tolist()
elif isinstance(value, dict):
dict_set = OrderedDict()
for k, v in value.items():
if k != "typeid":
v = self.value_for_pva_set(v)
if v is not None:
dict_set[k] = v
if dict_set:
value = dict_set
else:
value = None
elif isinstance(value, list):
if [x for x in value if isinstance(x, dict)]:
value = [self.dict_to_pv_object(v) for v in value]
return value

def pva_structure_from_value(self, value, empty_allowed=False):
# Create pv structure
Expand Down

0 comments on commit 5c9c392

Please sign in to comment.