Skip to content

Commit

Permalink
Merge pull request #994 from slaclab/variable_wait
Browse files Browse the repository at this point in the history
Update variable wait to allow for triggering on any update
  • Loading branch information
bengineerd authored Mar 26, 2024
2 parents f2280de + 30e158f commit a2687d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/src/interfaces/clients/virtual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ The VariableWait helper function can also be used.
.. code-block:: python
# Wait for the uptime to be greater than 1000 seconds
VariableWait(root.AxiVersion.UpTime, lambda varValues: varValues['root.UpTime'].value > 1000)
VariableWait([root.AxiVersion.UpTime], lambda varValues: varValues[0].value > 1000)
The VirtualClient maintains a connection to the Rogue core. The status of this connection
can be directly accessed through the linked attribute. Additionally a callback function
Expand Down
7 changes: 2 additions & 5 deletions python/pyrogue/_Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ def __init__(self, *, argVariable=None, returnVariable=None, function=None, **kw
value = 1,
description = "Total number of loops steps for the process"))

@self.command(hidden=True)
def Advance(arg):
self._incrementSteps(1)

# Add arg variable if not already added
if self._argVar is not None and self._argVar not in self:
self.add(self._argVar)
Expand Down Expand Up @@ -169,10 +165,11 @@ def _process(self):
# No function run example process
else:
self.Message.setDisp("Started")
self.TotalSteps.set(100)
for i in range(101):
if self._runEn is False:
break
time.sleep(1)
self.Progress.set(i/100)
self._setSteps(i+1)
self.Message.setDisp(f"Running for {i} seconds.")
self.Message.setDisp("Done")
26 changes: 14 additions & 12 deletions python/pyrogue/_Variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ def VariableWait(varList, testFunction, timeout=0):
"""
Wait for a number of variable conditions to be true.
Pass a variable or list of variables, and a test function.
The test function is passed a dictionary containing the current
variableValue state index by variable path
The test function is passed a list containing the current
variableValue state indexed by position as passed in the wait list.
Each variableValue entry has an additional field updated which indicates
if the variable has refreshed while waiting. This can be used to trigger
on any update to the variable, regardless of value.
i.e. w = VariableWait([root.device.var1,root.device.var2],
lambda varValues: varValues[0].value >= 10 and \
varValues[1].value >= 20)
i.e. w = VariableWait([root.device.var1,root.device.var2],
lambda varValues: varValues['root.device.var1'].value >= 10 and \
varValues['root.device.var1'].value >= 20)
lambda varValues: varValues[0].updated and \
varValues[1].updated)
Parameters
----------
Expand All @@ -53,13 +61,6 @@ def VariableWait(varList, testFunction, timeout=0):

# Container class
class varStates(object):
"""
"""

def __init__(self):
self.vlist = odict()
self.cv = threading.Condition()
Expand All @@ -68,7 +69,6 @@ def __init__(self):
def varUpdate(self,path,varValue):
"""
Parameters
----------
path :
Expand All @@ -84,6 +84,7 @@ def varUpdate(self,path,varValue):
with self.cv:
if path in self.vlist:
self.vlist[path] = varValue
self.vlist[path].updated = True
self.cv.notify()

# Convert single variable to a list
Expand All @@ -98,6 +99,7 @@ def varUpdate(self,path,varValue):
for v in varList:
v.addListener(states.varUpdate)
states.vlist[v.path] = v.getVariableValue(read=False)
states.vlist[v.path].updated = False

# Go into wait loop
ret = False
Expand Down

0 comments on commit a2687d0

Please sign in to comment.