1717import os
1818import time
1919import subprocess
20+ from typing import Literal
2021
2122import numpy as np
2223from 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
0 commit comments