Skip to content

Commit

Permalink
Added CAActionPart
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Aug 12, 2016
1 parent f1993c2 commit 1a9e6db
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions malcolm/parts/ca/caactionpart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import cothread
from cothread import catools

from malcolm.core import Part, method_takes, REQUIRED, MethodMeta
from malcolm.core.vmetas import StringMeta, NumberMeta
from malcolm.controllers import DefaultController


@method_takes(
"name", StringMeta("name of the created method"), REQUIRED,
"description", StringMeta("desc of created method"), REQUIRED,
"pv", StringMeta("full pv to write to when method called"), REQUIRED,
"value", NumberMeta("int32", "value to write to pv when method called"), 1)
class CAActionPart(Part):
method = None

def create_methods(self):
# MethodMeta instance
self.method = MethodMeta(self.params.description)
yield self.params.name, self.method, self.caput

@DefaultController.Resetting
def connect_pvs(self, _):
# make the connection in cothread's thread
v = cothread.CallbackResult(catools.caget, self.params.pv)
# check connection is ok
assert v.ok, "CA connect failed with %s" % v.state_strings[v.state]

def caput(self, value):
cothread.CallbackResult(
catools.caput, self.pv, value, wait=True, timeout=None,
datatype=self.get_datatype())

0 comments on commit 1a9e6db

Please sign in to comment.