fread
Read binary data from instrument
Syntax
Description
A = fread(obj) and A
= fread(obj,size) read binary data from the instrument connected to
obj, and returns the data to A. The
maximum number of values to read is specified by size. If
size is not specified, the maximum number of values to read
is determined by the object's InputBufferSize property. Valid
options for size are:
n— Read at mostnvalues into a column vector.[m,n]— Read at most m-by-n values filling an m-by-n matrix in column order.
size cannot be inf, and an error is returned
if the specified number of values cannot be stored in the input buffer. You specify
the size, in bytes, of the input buffer with the
InputBufferSize property. A value is defined as a byte
multiplied by the precision argument (see below).
If obj is a UDP object and
DatagramTerminateMode is off, the
size value is honored. If size is less
than the length of the datagram, only size values are read. If
size is greater than the length of the datagram, a warning is
issued stating that a complete datagram was read before size
values was reached.
A = fread(obj,size,precision) reads
binary data with precision specified by precision.
precision controls the number of bits read for each value and
the interpretation of those bits as integer, floating-point, or character values. If
precision is not specified, uchar (an
8-bit unsigned character) is used. By default, numeric values are returned in
double-precision arrays. The supported values for precision are
listed below in Tips.
[A,count] = fread(___)
returns the number of values read to count.
[A,count,msg] = fread(___)
returns a warning message to msg if the read operation was
unsuccessful.
[A,count,msg,datagramaddress] = fread(obj,___)
returns the datagram address to datagramaddress if
obj is a UDP object. If more than one datagram is read,
datagramaddress is ''.
[A,count,msg,datagramaddress,datagramport]
= fread(obj,___) returns the datagram port to
datagramport if obj is a UDP object. If
more than one datagram is read, datagramport is
[].
Input Arguments
| An interface object. |
| The number of values to read. |
| The number of bits read for each value, and the interpretation of the bits as character, integer, or floating-point values. |
Output Arguments
| Binary data returned from the instrument. |
| The number of values read. |
| A message indicating if the read operation was unsuccessful. |
| The address of the datagram sender. |
| The port of the datagram sender. |
Tips
Before you can read data from the instrument, it must be connected to
objwith thefopenfunction. A connected interface object has aStatusproperty value ofopen. An error is returned if you attempt to perform a read operation whileobjis not connected to the instrument.If
msgis not included as an output argument and the read operation was not successful, then a warning message is returned to the command line.The
ValuesReceivedproperty value is increased by the number of values read, each timefreadis issued.Rules for Completing a Binary Read Operation
A read operation with
freadblocks access to the MATLAB® Command Window untilThe specified number of values is read. For UDP objects,
DatagramTerminateModemust beoff.The time specified by the
Timeoutproperty passes.A datagram is received (for UDP objects only when
DatagramTerminateModeison).The input buffer is filled.
The EOI line is asserted (GPIB and VXI instruments only).
The
EOSCharCodeis received (GPIB and VXI instruments only).
More About the GPIB and VXI Terminator
The
EOSCharCodeproperty value is recognized only when theEOSModeproperty is configured toreadorread&write. For example, ifEOSModeis configured toreadandEOSCharCodeis configured toLF, then one of the ways that the read operation terminates is when the line feed character is received.If
EOSModeisnoneorwrite, then there is no terminator defined for read operations. In this case,freadwill complete execution and return control to the command when another criterion, such as a timeout, is met.Supported Precisions
The supported values for the
precisionargument are listed below.Data Type
Precision
Interpretation
Character
uchar8-bit unsigned character
schar8-bit signed character
char8-bit signed or unsigned character
Integer
int88-bit integer
int1616-bit integer
int3232-bit integer
uint88-bit unsigned integer
uint1616-bit unsigned integer
uint3232-bit unsigned integer
short16-bit integer
int32-bit integer
long32- or 64-bit integer
ushort16-bit unsigned integer
uint32-bit unsigned integer
ulong32- or 64-bit unsigned integer
Floating-point
single32-bit floating point
float3232-bit floating point
float32-bit floating point
double64-bit floating point
float6464-bit floating point