Thank you @TJF and @Dennis for your help, I figured out everything I needed
to and probably wouldn't have without your help! I modified the code
suggested by Dennis to be able to loop over the multiple output.x files
generated, and had it write the values to a .csv to be easily readable!
Here is the code for anyone who wants to use it:
import struct
import csv
import array
#Note this file assumes you are using 7 outputs in rb_file.py and assumes
that you have
#not changed the file naming convention. You must use command Python3 to
run this file!
CHNK_SAMPLES = 64
rdr = struct.Struct("H")
write = open("data.csv" , "w") #Opens a csv file called data.csv in write
mode
csvwriter = csv.writer(write, delimiter = ',', quotechar = '"', quoting =
csv.QUOTE_MINIMAL) #sets up the csv writer where a , seperates data entries
and '' is used for quotation
counter = 0 #sets up a counter used to iterate over the various data output
files
fileName = "output.%u" #follows the same naming format as used in
rb_file.py
datarr = array.array('f',[0,0,0,0,0,0,0]) #sets up an array of length 7
that will contain floats
i = 0 #sets up the index for looping over our array
while True:
try:
fin = open(fileName % counter,"rb") #opens the output file
corresponding to the counter value in read binary mode
print("Now Reading: " + fileName % counter) #updates the
user on the current file being read
while True:
chnk = fin.read(2*CHNK_SAMPLES) #gathers data from
the output file in chunks
if not chnk: break
for smpl in rdr.iter_unpack(chnk): #iterates over
the values found in the chunk
datarr[i] = smpl[0]*1.8/4095 #converts the
raw data into voltge form and stores it in the ith entry
if(i == 6): #if we have filled the array
csvwriter.writerow([datarr[0],datarr[1],datarr[2],datarr[3],datarr[4],datarr[5],datarr[6]])
#writes the data values to the csv
i = 0 #resets the index and the
array values to 0
datarr[0]=0
datarr[1]=0
datarr[2]=0
datarr[3]=0
datarr[4]=0
datarr[5]=0
datarr[6]=0
else:
i= i+1
counter = counter + 1 #raises the counter so we can move
onto the next file
fin.close() #closes the previous file
except IOError: #this will trigger when you run out of data files
to loop over
print("No file called: " + fileName % counter + " found.
This may be because you ran out of data.")
write.close() #closes the csv file
break
Any suggestions on modifications are welcome
On Wednesday, May 1, 2019 at 5:07:02 PM UTC-4, TJF wrote:
>
> @Sean Landerkin
>
> I found a bug: the p1 pointer computation is wrong. Only the first and all
> odd chunks contain valid data. The even chunks contain garbage.
>
> In order to get valid data you'll have to replace the line
>
> p1 = cast(byref(p0, half), POINTER(c_ushort))
>
> by
>
> p1 = cast(byref(p0.contents, (half << 1)), POINTER(c_ushort))
>
> (Computing simple pointers is pretty complicated in Python.)
>
> Am Dienstag, 30. April 2019 03:20:45 UTC+2 schrieb Sean Landerkin:
>>
>> Okay, do you understand how the data is written in C, and how in C I
>> could convert the data to readable data? I think I understand how to
>> transport that from C to python but I don't understand the initial
>> translation from the written form to a human-readable form.
>>
>
> The code from Dennis works reading the data (needs python3). In order to
> scale to [mV] multiply the raw data (=samp[0]) by factor 1800/4095, or use
> 1.8/4095 for [V].
>
> Regards
>
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/eaf6a450-d6fc-4252-8885-3e1743588be9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.