def write(self, cmd): if self.closed: raise RuntimeError("Trying to write to a closed instrument") num = float(cmd.split(':')[-1]) self.state = num if num < 0: raise ValueError('be more positive!') if num == 0: raise visa.VisaIOError(visa.constants.VI_ERROR_TMO) return len(cmd)
def check_error(self, ret_code: int) -> None: """ Default error checking, raises an error if return code ``!=0``. Does not differentiate between warnings or specific error messages. Override this function in your driver if you want to add specific error messages. Args: ret_code: A Visa error code. See eg: https://github.com/hgrecco/pyvisa/blob/master/pyvisa/errors.py Raises: visa.VisaIOError: if ``ret_code`` indicates a communication problem. """ if ret_code != 0: raise visa.VisaIOError(ret_code)