Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a function to wait until osci finished the momentary measurement #8

Open
ediordna opened this issue Apr 25, 2024 · 0 comments
Open

Comments

@ediordna
Copy link

Consider adding a function to wait until osci stopped its measurement:

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant