User`s manual
8 Serial Port I/O
8-40
You can verify the number of values read from the device – including the
terminator – with the
ValuesReceived property.
s.ValuesReceived
ans =
56
Synchronous Versus Asynchronous Read Operations.
You specify whether read
operations are synchronous or asynchronous with the
ReadAsyncMode property.
You can configure
ReadAsyncMode to continuous or manual.
If
ReadAsyncMode is continuous (the default value), the serial port object
continuously queries the device to determine if data is available to be read. If
data is available, it is asynchronously stored in the input buffer. To transfer the
data from the input buffer to MATLAB, you use one of the synchronous
(blocking) read functions such as
fgetl or fscanf. If data is available in the
input buffer, these functions will return quickly.
s.ReadAsyncMode = 'continuous';
fprintf(s,'*IDN?')
s.BytesAvailable
ans =
56
out = fscanf(s);
If ReadAsyncMode is manual, the serial port object does not continuously query
the device to determine if data is available to be read. To read data
asynchronously, you use the
readasync function.You then use one of the
synchronous read functions to transfer data from the input buffer to MATLAB.
s.ReadAsyncMode = 'manual';
fprintf(s,'*IDN?')
s.BytesAvailable
ans =
0
readasync(s)
s.BytesAvailable
ans =
56
out = fscanf(s);