@@ -77,6 +77,8 @@ def __init__(
7777 self .motion_suffix = "CS:MOT:MOVING"
7878 self .pre_post_cmd_manager = PrePostCmdManager ()
7979 self .logger = GenieLogger ()
80+ self ._sample_par_names_cache = None
81+ self ._beamline_par_names_cache = None
8082
8183 if environment_details is None :
8284 self ._environment_details = EnvironmentDetails ()
@@ -680,19 +682,21 @@ def set_sample_par(self, name: str, value: "PVValue") -> None:
680682 name: the name of the parameter to change
681683 value: the new value
682684 """
685+
683686 assert self .blockserver is not None
684- names = self . blockserver . get_sample_par_names ()
685- if (
686- names is not None
687- and isinstance ( names , list )
688- and all ( isinstance ( elem , str ) for elem in names )
689- ):
687+ try :
688+ names = self . blockserver . get_sample_par_names ()
689+ self . _sample_par_names_cache = names
690+ except Exception :
691+ names = self . _sample_par_names_cache
692+ if names is not None and isinstance ( names , list ):
690693 for n in names :
691- m = re .match (".+:SAMPLE:%s" % name .upper (), n )
692- if m is not None :
693- # Found it!
694- self .set_pv_value (self .prefix_pv_name (n ), value )
695- return
694+ if isinstance (n , str ):
695+ m = re .match (".+:SAMPLE:%s" % name .upper (), n )
696+ if m is not None :
697+ # Found it!
698+ self .set_pv_value (self .prefix_pv_name (n ), value )
699+ return
696700 raise Exception ("Sample parameter %s does not exist" % name )
697701
698702 def get_beamline_pars (self ) -> "_GetbeamlineparsReturn" :
@@ -712,8 +716,14 @@ def set_beamline_par(self, name: str, value: "PVValue") -> None:
712716 name: the name of the parameter to change
713717 value: the new value
714718 """
719+
715720 assert self .blockserver is not None
716- names = self .blockserver .get_beamline_par_names ()
721+ try :
722+ names = self .blockserver .get_beamline_par_names ()
723+ self ._beamline_par_names_cache = names
724+ except Exception :
725+ names = self ._beamline_par_names_cache
726+
717727 if names is not None :
718728 for n in names :
719729 m = re .match (".+:BL:%s" % name .upper (), n )
0 commit comments