Read data asynchronously from device
readasync(obj)
readasync(obj,size)
readasync(obj)
initiates
an asynchronous read operation on the serial port object, obj
.
readasync(obj,size)
asynchronously
reads, at most, the number of bytes given by size
.
If size
is greater than the difference between
the InputBufferSize
property value and the BytesAvailable
property
value, an error is returned.
This example creates the serial port object s
on
a Windows® platform. It connects s
to a Tektronix® TDS
210 oscilloscope, configures s
to read data asynchronously
only if readasync
is issued, and configures the
instrument to return the peak-to-peak value of the signal on channel
1.
s = serial('COM1'); fopen(s) s.ReadAsyncMode = 'manual'; fprintf(s,'Measurement:Meas1:Source CH1') fprintf(s,'Measurement:Meas1:Type Pk2Pk') fprintf(s,'Measurement:Meas1:Value?')
Begin reading data asynchronously from the instrument using readasync
.
When the read operation is complete, return the data to the MATLAB® workspace
using fscanf
.
readasync(s) s.BytesAvailable
ans = 15
out = fscanf(s)
out = 2.0399999619E0
fclose(s)
BytesAvailable
| BytesAvailableFcn
| fopen
| ReadAsyncMode
| Status
| stopasync
| TransferStatus