3.3 Reading binary data

 

Some instruments allow for sending the measured data in binary form. This has the advantage that the data transfer is much smaller and takes less time. PyVISA currently supports three forms of transfers:

ascii
This is the default mode. It assumes a normal string with comma- or whitespace-separated values.
single
The values are expected as a binary sequence of IEEE floating point values with single precision (i.e. four bytes each).2
double
The same as single, but with values of double precision (eight bytes each).

You can set the form of transfer with the property values_format, either with the generation of the object,

my_instrument = instrument("GPIB::12", values_format = single)
or later by setting the property directly:
my_instrument.values_format = single
Setting this option affects the methods read_values() and ask_for_values(). In particular, you must assure separately that the device actually sends in this format.

In some cases it may be necessary to set the byte order, also known as endianness. PyVISA assumes little-endian as default. Some instruments call this ``swapped'' byte order. However, there is also big-endian byte order. In this case you have to append "| big_endian" to your values format:

my_instrument = instrument("GPIB::12", values_format = single | big_endian)



Footnotes

... each).2
All flavours of binary data streams defined in IEEE488.2 are supported, i.e. those beginning with ``$\langle$header$\rangle$ #$\langle$digit$\rangle$'', where $\langle$header$\rangle$ is optional, and $\langle$digit$\rangle$ may also be ``0''.


Subsections