Skip to content

Commit

Permalink
Use FORMAT_CTRL for initial caget to get properties, then use FORMAT_…
Browse files Browse the repository at this point in the history
…TIME
  • Loading branch information
coretl committed Dec 2, 2016
1 parent 5515a3a commit ceabec8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
7 changes: 3 additions & 4 deletions malcolm/parts/ca/cachoicepart.py
Expand Up @@ -11,10 +11,9 @@ def create_meta(self, description, tags):
def get_datatype(self):
return self.catools.DBR_ENUM

def update_value(self, value):
if hasattr(value, 'enums') and value.ok:
self.attr.meta.set_choices(value.enums)
super(CAChoicePart, self).update_value(value)
def set_initial_value(self, value):
self.attr.meta.set_choices(value.enums)
super(CAChoicePart, self).set_initial_value(value)

def caput(self, value):
try:
Expand Down
13 changes: 8 additions & 5 deletions malcolm/parts/ca/capart.py
Expand Up @@ -22,7 +22,7 @@ class CAPart(Part):
def __init__(self, process, params):
self.cothread, self.catools = CothreadImporter.get_cothread(process)
# Format for all caputs
self.ca_format = self.catools.FORMAT_CTRL
self.ca_format = self.catools.FORMAT_TIME
super(CAPart, self).__init__(process, params)

def create_attributes(self):
Expand Down Expand Up @@ -64,6 +64,9 @@ def create_meta(self, description, tags):
def get_datatype(self):
raise NotImplementedError

def set_initial_value(self, value):
self.update_value(value)

@DefaultController.Reset
def reset(self, task=None):
# release old monitor
Expand All @@ -74,16 +77,16 @@ def reset(self, task=None):
pvs.append(self.params.pv)
ca_values = self.cothread.CallbackResult(
self.catools.caget, pvs,
format=self.ca_format, datatype=self.get_datatype())
format=self.catools.FORMAT_CTRL, datatype=self.get_datatype())
# check connection is ok
for i, v in enumerate(ca_values):
assert v.ok, "CA connect failed with %s" % v.state_strings[v.state]
self.update_value(ca_values[0])
self.set_initial_value(ca_values[0])
self.log_debug("ca values connected %s", ca_values)
# now setup monitor on rbv
self.monitor = self.cothread.CallbackResult(
self.catools.camonitor, self.params.rbv, self.update_value,
format=self.ca_format, datatype=self.get_datatype(),
format=self.catools.FORMAT_TIME, datatype=self.get_datatype(),
notify_disconnect=True, all_updates=True)

@DefaultController.Disable
Expand All @@ -104,7 +107,7 @@ def caput(self, value):
# now do a caget
value = self.cothread.CallbackResult(
self.catools.caget, self.params.rbv,
format=self.ca_format, datatype=self.get_datatype())
format=self.catools.FORMAT_TIME, datatype=self.get_datatype())
self.update_value(value)

def update_value(self, value):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parts/test_ca/test_capart.py
Expand Up @@ -80,7 +80,7 @@ def test_reset(self):
["pv2", "pv"],
format=p.catools.FORMAT_CTRL, datatype=p.get_datatype())
p.catools.camonitor.assert_called_once_with(
"pv2", p.update_value, format=p.catools.FORMAT_CTRL,
"pv2", p.update_value, format=p.catools.FORMAT_TIME,
datatype=p.get_datatype(), notify_disconnect=True, all_updates=True)
self.assertEqual(p.attr.value, 4)
self.assertEqual(p.monitor, p.catools.camonitor())
Expand All @@ -95,7 +95,7 @@ def test_caput(self):
p.catools.caput.assert_called_once_with(
"pv", 32, wait=True, timeout=None, datatype=datatype)
p.catools.caget.assert_called_once_with(
"pv2", format=p.catools.FORMAT_CTRL, datatype=datatype)
"pv2", format=p.catools.FORMAT_TIME, datatype=datatype)
self.assertEqual(p.attr.value, 3)

def test_close_monitor(self):
Expand Down

0 comments on commit ceabec8

Please sign in to comment.