1 from __future__
import division, absolute_import
4 from twistedActor
import ActorDevice, log, expandUserCmd
6 __all__ = [
"MirrorDevice"]
37 """!Construct a MirrorDevice
39 @param[in] name mirror name, one of "prim", "sec" or "tert"
40 @param[in] host mirror controller host
41 @param[in] port mirror controller port
42 @param[in] modelName name of mirror controller keyword dictionary; usually "mirror"
44 ActorDevice.__init__(self,
51 def init(self, userCmd=None, timeLim=2, getStatus=True):
52 """!Initialize the device and cancel all pending commands
54 @param[in] userCmd user command that tracks this command, if any
55 @param[in] timeLim maximum time before command expires, in sec; None for no limit
56 @param[in] getStatus IGNORED (status is automatically output sometime after stop)
57 @return userCmd (a new one if the provided userCmd is None)
59 userCmd = expandUserCmd(userCmd)
60 self.
startCmd(cmdStr=
"stop", userCmd=userCmd, timeLim=timeLim)
64 """!Method to begin keyword forwarding for keywords of interest,
65 if self.writeToUsers has been added by the actor.
67 def forwardKW(value, isCurrent, keyVar):
68 """!KeyVar callback on KeyVar objects that the TCC cares about
69 simply forwards on the keyword with a mirror name prepended
72 msgCode = keyVar.reply.header.code
if keyVar.reply
else "i"
73 if keyVar.name.lower() ==
"text":
75 if msgCode
in [
"e",
"w"]:
77 keyVarNameUp = keyVar.name
78 msgStr =
"Text=" +
"\"" + str(keyVar.valueList[0]) +
"\""
85 mirNameUp = self.name[0].capitalize() + self.name[1:]
86 keyVarNameUp = keyVar.name[0].capitalize() + keyVar.name[1:]
89 for value
in keyVar.valueList:
90 strValList.append(str(value)
if value!=
None else "NaN")
92 msgStr =
'%s=%s' % (
''.join([mirNameUp, keyVarNameUp]),
','.join(strValList))
93 self.writeToUsers(msgCode=msgCode, msgStr=msgStr)
96 getattr(self.dispatcher.model, kw).addValueCallback(forwardKW, callNow =
True)
99 """!Called each time a reply comes through the line
102 log.info(
"%s read %r" % (self, reply))
106 """!Return a tuple containing the time limit keyvar and index for use in setting automatically
109 return (self.dispatcher.model.state, 4)
116 timeLimKeyVar =
None,
122 """!Queue or start a new command.
124 If timeLimKeyVar not specified, use the state keyword.
126 @param[in] cmdStr the command; no terminating \n wanted
127 @param[in] callFunc callback function: function to call when command succeeds or fails, or None;
128 if specified it receives one argument: an opscore.actor.CmdVar object
129 @param[in] userCmd user command that tracks this command, if any
130 @param[in] callFunc a callback function; it receives one argument: a CmdVar object
131 @param[in] userCmd user command that tracks this command, if any
132 @param[in] timeLim maximum time before command expires, in sec; 0 for no limit
133 @param[in] timeLimKeyVar a KeyVar specifying a delta-time by which the command must finish
134 this KeyVar must be registered with the message dispatcher.
135 @param[in] timeLimKeyInd the index of the time limit value in timeLimKeyVar; defaults to 0;
136 ignored if timeLimKeyVar is None.
137 @param[in] abortCmdStr a command string that will abort the command.
138 Sent to the actor if abort is called and if the command is executing.
139 @param[in] keyVars a sequence of 0 or more keyword variables to monitor for this command.
140 Any data for those variables that arrives IN RESPONSE TO THIS COMMAND is saved
141 and can be retrieved using cmdVar.getKeyVarData or cmdVar.getLastKeyVarData.
142 @param[in] showReplies show all replies as plain text?
144 @return devCmd: the device command that was started (and may already have failed)
146 @note: if callFunc and userCmd are both specified callFunc is called before userCmd is updated.
148 if not timeLimKeyVar:
149 timeLimKeyVar, timeLimKeyInd = self.model.state, 3
150 return ActorDevice.startCmd(self,
155 timeLimKeyVar = timeLimKeyVar,
156 timeLimKeyInd = timeLimKeyInd,
157 abortCmdStr = abortCmdStr,
159 showReplies = showReplies,
def handleReply
Called each time a reply comes through the line.
def startKWForwarding
Method to begin keyword forwarding for keywords of interest, if self.writeToUsers has been added by t...
def init
Initialize the device and cancel all pending commands.
def __init__
Construct a MirrorDevice.
def startCmd
Queue or start a new command.
def timeLimKeyVar
Return a tuple containing the time limit keyvar and index for use in setting automatically updating t...