Sep-03-2020, 04:06 AM
Hi, I want to print the sample values to a csv file.
The code below does create a file and prints to it.
Though I want the "value" part of the writerow to an actual sample value.
Blank1, DateTime, Blank2, SampleValue1
Blank1, DateTime, Blank2, SampleValue2
Blank1, DateTime, Blank2, SampleValue3 etc till end of sample value's
Would I use an array or list and step through a for loop.
Thanks,
The code below does create a file and prints to it.
Though I want the "value" part of the writerow to an actual sample value.
Blank1, DateTime, Blank2, SampleValue1
Blank1, DateTime, Blank2, SampleValue2
Blank1, DateTime, Blank2, SampleValue3 etc till end of sample value's
Would I use an array or list and step through a for loop.
Thanks,
import struct import time import csv # Get Data out of Binary File def readdata(filename): '''Read data from a file. Data count is in the header''' with open(filename, "rb") as file: buffer = file.read(20) size, variation, objectType, pointIndex, startTime, sampleRate, count = struct.unpack('>IBBHiII', buffer) print(size, variation, objectType, startTime, sampleRate, count) buffer = file.read(4 * count) values = struct.unpack(f'={count}I', buffer) return values print(readdata('XXXXXXXXXXX')) # Create and Write to CSV File with open('XXXXXXXXXXX.csv', 'w', newline='') as file: writer = csv.writer(file) writer.writerow(["Blank1", "DateTime", "Blank2", "Value"])