Info

This question is closed. Reopen it to edit or answer.

How can I know how long data has been sitting in a serial buffer?

1 view (last 30 days)
I'm sending data from an Arduino (which measures 3D orientation) to a PC via Bluetooth (serial port on PC). I want to know precisely (+/- 5 ms) when events occur on the Arduino. I read in the data with MATLAB more or less continuously with fread, but I don't know how long it took to go from the Arduino writing to the serial buffer to MATLAB reading from the serial buffer. This delay seems to be variable +/- 30ms or so. Is there some way of knowing how long the data has been sitting in the buffer?
I'd like to be able to do some calculation like (current PC time) - (time sitting in buffer) = (time when event occurred). Is there any way to do this or at least cut down the variability?

Answers (1)

Walter Roberson
Walter Roberson on 28 Feb 2014
If you are using a true serial port or if you are using a USB virtual serial port or if you are using a Bluetooth virtual serial port, then none of those timestamp the inputs. To timestamp you need a data acquisition device such as one made by National Instruments.

Community Treasure Hunt

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

Start Hunting!