msoon / PyMonsoon

Monsoon Power Monitor Python Library
MIT License
55 stars 23 forks source link

Sample aggregator does not look right #14

Closed luiscruz closed 6 years ago

luiscruz commented 7 years ago

I've made a few experiments using the Monsoon.sampleEngine:

>>> import Monsoon.LVPM as LVPM
>>> import Monsoon.sampleEngine as sampleEngine
>>> import Monsoon.Operations as op
>>> Mon = LVPM.Monsoon()
>>> Mon.setup_usb()
>>> Mon.setVout(4.0)
>>> engine = sampleEngine.SampleEngine(Mon)
>>> engine.ConsoleOutput(False)
>>> engine.startSampling(50000)
>>> samples = engine.getSamples()
>>> len(samples[0])
49867
>>> engine.startSampling(50000, 10)
>>> samples = engine.getSamples()
>>> len(samples[0])
9662
>>> engine.startSampling(50000, 20)
>>> samples = engine.getSamples()
>>> len(samples[0])
4772

Here's the issue: I am calling the method startSampling with different granularity values. Since I'm collecting 50000 samples, when granularity is 10 I would expect to have about 5000 tuples. However, I am getting around 10000.

The same is verified when I use granularity 20000, I would expect to have 2500 samples and I get 5000.

Mbrinker commented 7 years ago

Should be fixed by d37254a0b59f102df8fc3fcb4f24be058527ea6d

The protocol returns up to three measurements with every call to BulkRead(), depending on how fast the host computer is requesting samples. Granularity code was assuming each packet returned only contained a single packet, so in the worst-case scenario the returned samplecount would be about 3x the expected count. The 2x count you're seeing was probably due to a mix of 1, 2, and 3-sample packets being received.

The final output array will still not be exactly what is expected, since calibration samples are included in the total sample count, but are not included in the final output array.

Mbrinker commented 6 years ago

Fully resolved in a2c6139382e6adbd10233d05f0896e69079d0571