def wait_until_stopped(self, max_seconds=20, warn=True):
'''Queries for the running status of run-control until the osci is in state stopped.
Does this for a maximum number of seconds, afterwards it leaves the function to not query
forever.
:param max_seconds: define how long to wait max, defaults to 20
:type max_seconds: int or str, optional
:param warn: decide, if a warning shall be logged after time is over, defaults to True
:type warn: bool
:return: if it stopped after condition change or after maximum number of seconds
:rtype: bool
'''
# Wait a maximum number of seconds to prevent looping forever
for i in range(int(max_seconds)):
try:
operation_register = int(self.query_raw(':OPERegister:CONDition?'))
except VisaIOError:
time.sleep(1)
continue
# We need the value from bit 3 of operation register
# It tells us if the oscilloscope is running (not stopped)
running = bool((operation_register >> 3) & 1)
if not running:
logger.info(f'Osci: Stopped after {i} seconds.')
return True
time.sleep(1)
if warn:
logger.warn(f'Osci: Waited {max_seconds}s to switch to status "stop", did not work.')
return False
Consider adding a function to wait until osci stopped its measurement: