File Exchange

image thumbnail


version (4.26 KB) by M. A. Hopcroft
serialDataStream shows you how to capture continuous data streams from USB devices and serial ports.


Updated 20 Mar 2012

View Version History

View License

SERIALDATASTREAM is a design pattern for a function to receive and process a continuous stream of data from a device connected to a USB or serial port. This function does not execute as written; it includes explanations and examples for all of the steps required to capture data which is transmitted continuously over a USB or serial interface which use a "virtual COM port". It uses some advanced features of the MATLAB serial port functions and has been successfully used for capturing data at rates up to 1.5 MB/sec. Examples for Windows, Mac OS X, and Linux are included. The MATLAB Instrument Control Toolbox is not required.

This code does not execute as it is written; it is a design pattern with explanations and examples in the comments. You can read it and modify it for your needs.

WARNING: This is code is intended for advanced users who need to capture a high-speed, continuous data stream from a USB/serial port. You must have detailed information about the configuration and operation of your serial device. If you do not need high-speed continuous data capture, then you should look at other code which is easier to understand and use.

Cite As

M. A. Hopcroft (2021). serialDataStream (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

jon erickson

This is a helpful start. However, I found the function to be quite buggy:

1. need to exchange steps 3 and 4. Have to set up all properties of obj before opening.

2. The callback function should only have 2 input args (obj, event), unless arg1 is previously defined.

3. The callback function should be moved to separate .m file (or it might not be recognized)

3. The plotting window seems to hang, not sure why--could be my particular device & application.

All up, very helpful to get oriented, and understand this is to be modified, but could use some smoothing of the speed bumps...

mei mei

This Function (and the comments) were very useful. For my application I need to store the data coming in over the serial buffer (so that I can analyze later). I am having issues with record function. In particular it seems to add 1 to the MSb of each of the values that are read on the serial. I was wondering if you have ever used the record function or if you have ever had to store the values for further analyzing and if you might have any tips. Thanks


Nabeel Abbood

Dhaneesh Chandran

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!