Instrument Control Toolbox | ![]() ![]() |
Read binary data from the instrument
Syntax
A = fread(obj,size)
A = fread(obj,size,'precision
')
[A,count] = fread(...)
[A,count,msg] = fread(...)
[A,count,msg,datagramaddress] = fread(obj,...)
[A,count,msg,datagramaddress,datagramport] = fread(obj,...)
Arguments
Description
A = fread(obj,size)
reads 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
. Valid options for size
are
n |
Read at most n values 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
(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,'
reads binary data with precision specified by precision
')
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 Remarks.
[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 [ ].
Remarks
Before you can read data from the instrument, it must be connected to obj
with the fopen
function. A connected instrument object has a Status
property value of open
. An error is returned if you attempt to perform a read operation while obj
is not connected to the instrument.
If msg
is not included as an output argument and the read operation was not successful, then a warning message is returned to the command line.
The ValuesReceived
property value is increased by the number of values read, each time fread
is issued.
Rules for Completing a Binary Read Operation
A read operation with fread
blocks access to the MATLAB command line until
DatagramTerminateMode
must be off
.
Timeout
property passes.
DatagramTerminateMode
is on
).
EOSCharCode
is received (GPIB and VXI instruments only).
More About the GPIB and VXI Terminator
The EOSCharCode
property value is recognized only when the EOSMode
property is configured to read
or read&write
. For example, if EOSMode
is configured to read
and EOSCharCode
is configured to LF
, then one of the ways that the read operation terminates is when the line feed character is received.
If EOSMode
is none
or write
, then there is no terminator defined for read operations. In this case, fread
will complete execution and return control to the command when another criterion, such as a timeout, is met.
Supported Precisions
The supported values for precision
are listed below.
Functions
fgetl
, fgets
, fopen
, fscanf
, instrhelp
Properties
BytesAvailable
, InputBufferSize
, Status
, ValuesReceived
![]() | fprintf | freeserial | ![]() |