Пример #1
0
    def _format_binary_values(self,
                              values,
                              datatype='f',
                              is_big_endian=False,
                              header_fmt="ieee"):
        """Format values in binary format, used internally in :meth:`.write_binary_values`.

        :param values: data to be written to the device.
        :param datatype: the format string for a single element. See struct module.
        :param is_big_endian: boolean indicating endianess.
        :param header_fmt: Format of the header prefixing the data ("ieee", "hp", "empty").
        :return: binary string.
        :rtype: bytes
        """

        if header_fmt == "ieee":
            block = to_ieee_block(values, datatype, is_big_endian)
        elif header_fmt == "hp":
            block = to_hp_block(values, datatype, is_big_endian)
        elif header_fmt == "empty":
            block = to_binary_block(values, b"", datatype, is_big_endian)
        else:
            raise ValueError("Unsupported header_fmt: %s" % header_fmt)

        return block
Пример #2
0
 def test_ieee_noninteger(self):
     values = [val + 0.5 for val in range(100)]
     containers = (list, tuple) #+ ((np.asarray,) if np else ())
     for fmt in 'fd':
         for endi in (True, False):
             for cont in containers:
                 conv = cont(values)
                 block = util.to_ieee_block(conv, fmt, endi)
                 parsed = util.from_ieee_block(block, fmt, endi, cont)
                 self.assertEqual(conv, parsed)
Пример #3
0
    def test_ieee_noninteger(self):
        values = [val + 0.5 for val in range(100)]
        containers = (list, tuple) #+ ((np.asarray,) if np else ())
        for fmt in 'fd':
            for endi in (True, False):
                for cont in containers:
                    conv = cont(values)
                    msg = 'fmt=%s, endianness=%s, container=%s' % (fmt, endi, cont.__name__)
                    try:
                        block = util.to_ieee_block(conv, fmt, endi)
                        parsed = util.from_ieee_block(block, fmt, endi, cont)
                    except Exception as e:
                        raise Exception(msg + '\n' + repr(e))

                    self.assertEqual(conv, parsed, msg)
Пример #4
0
    def test_ieee_noninteger(self):
        values = [val + 0.5 for val in range(99)]
        containers = (list, tuple) #+ ((np.asarray,) if np else ())
        for fmt in 'fd':
            for endi in (True, False):
                for cont in containers:
                    conv = cont(values)
                    msg = 'fmt=%s, endianness=%s, container=%s' % (fmt, endi, cont.__name__)
                    try:
                        block = util.to_ieee_block(conv, fmt, endi)
                        parsed = util.from_ieee_block(block, fmt, endi, cont)
                    except Exception as e:
                        raise Exception(msg + '\n' + repr(e))

                    self.assertEqual(conv, parsed, msg)
Пример #5
0
    def write_binary_values(self,
                            command,
                            values,
                            datatype='f',
                            is_big_endian=False):
        """Write a string message to device followed by values in binary IEEE
        format using a pyvisa utility function.)

        Args:
            command: String command sent to instrument.
            values: Data to be sent to instrument.
            datatype: Format string for single element.
            is_big_endian: Bool indicating endianness.
        Returns:
            Number of bytes written to instrument.
        """
        data = to_ieee_block(values,
                             datatype=datatype,
                             is_big_endian=is_big_endian)
        return self.write_raw(command.encode() + data)