How to use the pyvisa.errors.InvalidBinaryFormat function in PyVISA

To help you get started, we’ve selected a few PyVISA examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyvisa / pyvisa / pyvisa / legacy / visa.py View on Github external
raise InvalidBinaryFormat
        if fmt & 0x04 == big_endian:
            endianess = ">"
        else:
            endianess = "<"
        try:
            if fmt & 0x03 == single:
                result = list(struct.unpack((endianess +
                                             str(data_length // 4) + "f").encode('ascii'), data))
            elif fmt & 0x03 == double:
                result = list(struct.unpack(endianess +
                                            str(data_length // 8) + "d", data))
            else:
                raise ValueError("unknown data values fmt requested")
        except struct.error:
            raise InvalidBinaryFormat("binary data itself was malformed")
        return result
github pyvisa / pyvisa / pyvisa / testsuite / test_errors.py View on Github external
def test_InvalidBinaryFormat(self):
        self._test_pickle_unpickle(errors.InvalidBinaryFormat())
github pyvisa / pyvisa / pyvisa / resources / messagebased.py View on Github external
return util.from_ascii_block(self.read())

        data = self._read_raw()

        try:
            if fmt & 0x03 == 1:  # single
                is_single = True
            elif fmt & 0x03 == 3:  # double:
                is_single = False
            else:
                raise ValueError("unknown data values fmt requested")

            is_big_endian = fmt & 0x04  # big endian
            return util.parse_binary(data, is_big_endian, is_single)
        except ValueError as e:
            raise errors.InvalidBinaryFormat(e.args)
github pyvisa / pyvisa / pyvisa / errors.py View on Github external
def __init__(self, description=""):
        if description:
            description = ": " + description
        super(InvalidBinaryFormat, self).__init__("Unrecognized binary data format" + description)
        self.description = description
github pyvisa / pyvisa / pyvisa / resources / messagebased.py View on Github external
'1.10, use read_ascii_values or read_binary_values '
                      'instead.', FutureWarning)
        if not fmt:
            vf = self.values_format
            if not vf.is_binary:
                return util.from_ascii_block(self.read(), container)
            data = self._read_raw()
            try:
                return util.parse_binary(data, vf.is_big_endian,
                                         vf.datatype == 'f')
            except ValueError as e:
                try:
                    msg = e.args[0]
                except IndexError:
                    msg = ''
                raise errors.InvalidBinaryFormat(msg)

        if fmt & 0x01 == 0:  # ascii
            return util.from_ascii_block(self.read())

        data = self._read_raw()

        try:
            if fmt & 0x03 == 1:  # single
                is_single = True
            elif fmt & 0x03 == 3:  # double:
                is_single = False
            else:
                raise ValueError("unknown data values fmt requested")

            is_big_endian = fmt & 0x04  # big endian
            return util.parse_binary(data, is_big_endian, is_single)
github pyvisa / pyvisa / pyvisa / resources / messagebased.py View on Github external
'bytes and pass it using the `data_length` keyword.')
            warnings.warn(msg, FutureWarning)
            # Do not keep reading since we may have already read everything

            # Set the datalength to None to infer it from the block length
            data_length = None


        try:
            # Do not reparse the headers since it was already done and since
            # this allows for custom data length
            return util.from_binary_block(block, offset, data_length,
                                          datatype, is_big_endian,
                                          container)
        except ValueError as e:
            raise errors.InvalidBinaryFormat(e.args)
github pyvisa / pyvisa / pyvisa / errors.py View on Github external
def __reduce__(self):
        return (InvalidBinaryFormat, (self.description,))