User`s manual

8 Serial Port I/O
8-38
The Input Buffer and Data Flow
The input buffer is computer memory allocated by the serial port object to store
data that is to be read from the device. When reading data from your device,
the data flow follows these two steps:
1 The data read from the device is stored in the input buffer.
2 The data in the input buffer is returned to the MATLAB variable specified
by the read function.
The
InputBufferSize property specifies the maximum number of bytes that
you can store in the input buffer. The
BytesAvailable property indicates the
number of bytes currently available to be read from the input buffer. The
default values for these properties are given below.
s = serial('COM1');
get(s,{'InputBufferSize','BytesAvailable'})
ans =
[512] [0]
If you attempt to read more data than can fit in the input buffer, an error is
returned and no data is read.
For example, suppose you use the
fscanf function to read the text-based
response of the
*IDN? command previously written to the TDS 210 oscilloscope.
As shown below, the text data is first read into to the input buffer via the serial
port.
COM1
...
Input Buffer
Bytes used during read
Bytes unused during read
Serial Port I/O HardwareInstrument
data