Skip to content

Commit 379998e

Browse files
committed
fix(SmurfCommand.save_state): Use the new process class.
In rogue 6, long running commands will time out. Use the process implementation and instead and monitor for completion.
1 parent d8a3eb2 commit 379998e

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

python/pysmurf/client/command/smurf_command.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import time
1919
import subprocess
20+
from typing import Literal
2021

2122
import numpy as np
2223
from packaging import version
@@ -1199,7 +1200,38 @@ def sel_ext_ref(self, bay, **kwargs):
11991200

12001201
# name changed in Rogue 4 from WriteState to SaveState. Keeping
12011202
# the write_state function for backwards compatibilty.
1202-
_save_state_reg = "AMCc.SaveState"
1203+
# In rogue 6 this has moved to a process to avoid timing out
1204+
# on a long-running command
1205+
_save_state_reg = "AMCc.SaveConfigProcess"
1206+
1207+
def _save_state_or_config(
1208+
self, fname : str, mode : Literal["Config", "Status"], timeout : float = 180.0,
1209+
**kwargs
1210+
):
1211+
# write out to a file
1212+
self._caput(self._save_state_reg + ".SaveMode", "File", **kwargs)
1213+
self._caput(self._save_state_reg + ".ConfigFile", fname, **kwargs)
1214+
1215+
# select state or config
1216+
self._caput(self._save_state_reg + ".DataType", mode, **kwargs)
1217+
1218+
# start the process
1219+
self._caput(self._save_state_reg + ".Start", 1, **kwargs)
1220+
1221+
# wait for process to complete
1222+
start = time.time()
1223+
1224+
def keep_waiting():
1225+
if (timeout == 0) or ((time.time() - start) <= timeout):
1226+
return True
1227+
raise TimeoutError(f"SaveConfigProcess timed out after {timeout}s.")
1228+
1229+
while self._caget(self._save_state_reg + ".Running") and keep_waiting():
1230+
time.sleep(0.1)
1231+
# Check the return value from 'LoadConfig'.
1232+
msg = self._caget(self._save_state_reg + ".Message")
1233+
if msg != "Done":
1234+
raise RuntimeError(f"SaveConfigProcess failed with '{msg}'")
12031235

12041236
def save_state(self, val, **kwargs):
12051237
"""
@@ -1210,15 +1242,13 @@ def save_state(self, val, **kwargs):
12101242
val : str
12111243
The path (including file name) to write the yml file to.
12121244
"""
1213-
self._caput(self._save_state_reg, val, **kwargs)
1245+
self._save_state_or_config(val, "Status", **kwargs)
12141246

12151247
# alias older rogue 3 write_state function to save_state
12161248
write_state = save_state
12171249

12181250
# name changed in Rogue 4 from WriteConfig to SaveConfig. Keeping
12191251
# the write_config function for backwards compatibilty.
1220-
_save_config_reg = "AMCc.SaveConfig"
1221-
12221252
def save_config(self, val, **kwargs):
12231253
"""
12241254
Writes the current (un-masked) PyRogue settings to a yml file.
@@ -1228,7 +1258,7 @@ def save_config(self, val, **kwargs):
12281258
val : str
12291259
The path (including file name) to write the yml file to.
12301260
"""
1231-
self._caput(self._save_config_reg, val, **kwargs)
1261+
self._save_state_or_config(val, "Config", **kwargs)
12321262

12331263
# alias older rogue 3 write_config function to save_config
12341264
write_config = save_config

python/pysmurf/core/roots/Common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def __init__(self, *,
153153
pyrogue.streamConnect(self._ddr_streams[i], self._stream_fifos[i])
154154

155155

156+
# Note that these are no longer exposed in the SmurfCommand interface.
157+
# Instead, the SaveConfigProcess is called, which WILL read before saving.
156158
# Update SaveState to not read before saving
157159
self.SaveState.replaceFunction(lambda arg: self.saveYaml(name=arg,
158160
readFirst=False,

0 commit comments

Comments
 (0)