-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |