How can I increase the rate that data is brought into MATLAB when performing Serial I/O in MATLAB?

1 view (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
The serial port object has a property called, ReadAsyncMode, that defines when the object queries the instrument for data. If the ReadAsyncMode property is continuous (the default value), the object will start querying the instrument for data after FOPEN is called. It will stop querying the instrument when FCLOSE is called. Note that the instrument is queried every 50ms for data. This is not user modifiable.
If data is available from the instrument, the data will be placed into the object's input buffer. The amount of data available in the input buffer is returned by the BytesAvailable property. The data can be pulled from the input buffer into MATLAB using one of the synchronous read methods such as FREAD or FSCANF.
If ReadAsyncMode is manual, then the object will query the instrument for data only when the user requests data with one of the sychronous read methods or with READASYNC. If READASYNC is called, the data is placed into the input buffer but not returned to the user. In general, this setting should not be used unless the instrument is constantly streaming data and you only want to capture data at a certain moment in time.
Try running your example through the MATLAB profiler, using the PROFILE function. For more information about this, type
help profile
or
doc profile
at the MATLAB command prompt. The profile will report to you how much time is being spent in different sections of your code.
Some error checking in the MATLAB Code will take time; there is also time spent converting the Java object to a MATLAB object. There is time spent reading the data from the instrument.
However, if the data is already in the input buffer and BytesAvailable is greater than the amount requested from FREAD, it is probable that most of the time spent occurs from MATLAB performing error checking and not reading from the instrument.
In any case, running your example through the profiler will show this to you in greater detail.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!