fscanf
(To be removed) Read data from instrument, and format as text
This serial
, Bluetooth
, tcpip
,
udp
, visa
, and gpib
object
function will be removed in a future release. Use serialport
, bluetooth
,
tcpclient
,
tcpserver
,
udpport
,
and visadev
object functions instead. For more information on updating your code, see Version History.
Syntax
Description
A = fscanf(obj)
reads data from the
instrument connected to obj
, and returns it to
A
. The data is converted to text using the
%c
format.
A = fscanf(obj,format)
reads data and
converts it according to format
.
format
is a C language conversion specification. Conversion
specifications involve the %
character and the conversion
characters d, i, o, u, x, X, f, e, E, g, G, c, and s. Refer to the sscanf
file I/O format specifications or a C manual for more
information.
A = fscanf(obj,format,size)
reads the
number of values specified by size
.
size
cannot be inf
, and an error is returned
if the specified number of values cannot be stored in the input buffer. If
size
is not of the form [m,n]
, and a
character conversion is specified, then A
is returned as a row
vector. You specify the size, in bytes, of the input buffer with the
InputBufferSize
property. An ASCII value is one
byte.
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,count] = fscanf(___)
returns the number of values read to count
.
[A,count,msg] = fscanf(___)
returns a warning message to msg
if the read operation did not
complete successfully.
[A,count,msg,datagramaddress] = fscanf(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]
= fscanf(obj,___)
returns the datagram port to
datagramport
if obj
is a UDP object. If
more than one datagram is read, datagramport
is [ ].
Examples
Input Arguments
| An interface object. |
| C language conversion specification. |
| The number of values to read. Valid options for
|
Output Arguments
| Data read from the instrument and formatted as text. |
| 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
obj
with thefopen
function. A connected interface object has aStatus
property value ofopen
. An error is returned if you attempt to perform a read operation whileobj
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 — including the terminator — each timefscanf
is issued.Rules for Completing a Read Operation with fscanf
A read operation with
fscanf
blocks access to the MATLAB® command line untilThe terminator is read. For serial port, TCPIP, UDP, and VISA-serial objects, the terminator is given by the
Terminator
property. IfTerminator
is empty,fscanf
will complete execution and return control when another criterion is met. For UDP objects,DatagramTerminateMode
must beoff
.For all other interface objects, the terminator is given by the
EOSCharCode
property.The time specified by the
Timeout
property passes.The number of values specified by
size
is read. For UDP objects,DatagramTerminateMode
must beoff
.A datagram is received (for UDP objects only when
DatagramTerminateMode
ison
).The input buffer is filled.
The EOI line is asserted (GPIB and VXI instruments only).
More About the GPIB and VXI Terminator
The
EOSCharCode
property value is recognized only when theEOSMode
property is configured toread
orread&write
. For example, ifEOSMode
is configured toread
andEOSCharCode
is configured toLF
, then one of the ways that the read operation terminates is when the line feed character is received.If
EOSMode
isnone
orwrite
, then there is no terminator defined for read operations. In this case,fscanf
will complete execution and return control to the command when another criterion, such as a timeout, is met.