On Wed, 15 May 2019 08:17:50 -0700 (PDT), Sean Landerkin
<firstname.lastname@example.org> declaimed the
NOTE: if you KNOW the data will be in "records" of 7 values (and you
never have an "odd" record) you could...
CHNK_SAMPLES = 64
Change that to 7 (it will mean more reads in the main loop, but...)
rdr = struct.Struct("H")
Change to "HHHHHHH" -- will interpret all 7 values in one call to the
i = 0 #sets up the index for looping over our array
Probably don't need this phase
chnk = fin.read(2*CHNK_SAMPLES) #gathers data from
the output file in chunks
if not chnk: break
With above changes, "chnk" should contain exactly 7 samples (14 bytes),
smpls = rdr.unpack(chnk)
should be a tuple or list (I haven't opened the help file to check) of all
datarr[i] = smpl*1.8/4095 #converts the
raw data into voltge form and stores it in the ith entry
datarr = [smpl * 1.8 / 4095 for smpl in smpls]
should do the conversion (you probably don't need the array initializer
either since this flat out creates a regular list of values).
if(i == 6): #if we have filled the array
And since we know it is 7 values at a time, no need to test...
I think just
would then suffice -- why index each element of the list, only to wrap them
back into a list.
#writes the data values to the csv
i = 0 #resets the index and the
array values to 0
... and not needed since the read/chunk and unpack is now working 7 values
at a time.