I'm streaming data from an analog photocell (as in http://labjack.com/s...ingle-ended-AIN ) and need to apply timestamps to the resulting samples. So I have code like:
import u3, time freq = 10000 d = u3.U3() d.configU3() d.getCalibrationData() d.configAnalog(u3.FIO0) d.streamConfig( NumChannels = 1, PChannels = [ 0 ], NChannels = [ 31 ], Resolution = 1, ScanFrequency = freq ) d.streamStart() for r in d.streamData(): now = time.time() if r is not None: data = r['AIN0'] times = [ now - t*1.0/freq for t in reversed(range(len(data))) ]
That is, my first attempt was to get the time that python is done getting the sample, then interpolate backwards to ascertain the time of each sample. However, I'm occasionally getting results such that the last entry from a sample has a later timestamp (up to 2ms) than the first entry from the next sample, which obviously shouldn't happen. I'm guessing that there is variability in the time it takes for control to return to python when getting sample data, meaning my use of time.time() to guess the time of the final entry in a given sample is inappropriate. Can anyone recommend a better method?