I been trying to save input data to a csv file, I managed to save some data but not enough because the program crashes, aborted.
how I can get to keep a csv file while capturing it?
the visualization features of the signal is not important, it is important to keep the saved data.
in qt.py file it is where he became the only pair to save the data change in csv file.
class OpenADCQt(QObject):
dataUpdated = Signal(list, int)
def __init__(self, MainWindow=None, includePreview=True, setupLayout=True, includeParameters=True, console=None, showScriptParameter=None):
super(OpenADCQt, self).__init__()
self.console = console
self.offset = 0.5
self.ser = None
self.sc = None
self.datapoints = []
self.preview = None
self.adc_settings = None
self.timerStatusRefresh = QTimer(self)
self.timerStatusRefresh.timeout.connect(self.statusRefresh)
self.showScriptParameter = showScriptParameter
if setupLayout:
self.setupLayout(MainWindow, includePreview, includeParameters)
def setEnabled(self, enabled):
print("self.oa.arm-set Enabled")
pass
def statusRefresh(self):
print("self.oa.arm-statusRefresh")
pass
def setupLayout(self, MainWindow, includePreview=True, includeParameters=True):
print("self.oa.arm-setupLayout")
vlayout = QVBoxLayout()
self.tb = QToolBox()
vlayout.addWidget(self.tb)
###### Graphical Preview Window
if includePreview:
self.preview = previewWindow()
self.preview.addDock(MainWindow)
vlayout.addWidget(self.preview.getSetupWidget())
if includeParameters:
self.setupParameterTree()
self.paramDock = QDockWidget("Settings")
self.paramDock.setAllowedAreas(Qt.BottomDockWidgetArea | Qt.RightDockWidgetArea|
Qt.LeftDockWidgetArea)
self.paramDock.setWidget(self.paramTree)
MainWindow.addDockWidget(Qt.LeftDockWidgetArea, self.paramDock)
self.masterLayout = vlayout
self.setEnabled(False)
def getLayout(self):
print("self.oa.arm-getLayout")
return self.masterLayout
def paramTreeChanged(self, param, changes):
print("self.oa.arm-paramTreeChanged")
if self.showScriptParameter is not None:
self.showScriptParameter(param, changes, self.params)
def setupParameterTree(self, makeTree=True):
print("self.oa.arm-setupParameterTree")
if self.adc_settings is None:
self.adc_settings = openadc.OpenADCSettings(self.console)
self.params = Parameter.create(name='OpenADC', type='group', children=self.adc_settings.parameters(doUpdate=False))
#ExtendedParameter.setupExtended(self.params)
ep = ExtendedParameter()
ep.setupExtended(self.params, self)
#todo: this is a somewhat insane way to cut through the layers
self.adc_settings.setFindParam(self.findParam)
if makeTree:
self.paramTree = ParameterTree()
self.paramTree.setParameters(self.params, showTop=False)
def reloadParameterTree(self):
print("self.oa.arm-reloadParameterTree")
self.adc_settings.setInterface(self.sc)
self.params.blockTreeChangeSignal()
self.params.getAllParameters()
self.params.unblockTreeChangeSignal()
def processData(self, data):
print("self.oa.arm-processData")
fpData = []
for b in data:
#lastpt = -100;
if data[0] != 0xAC:
self.showMessage("Unexpected sync byte: 0x%x"%data[0])
return None
for i in range(2, len(data)-1, 2):
if (0x80 & data[i + 1]) or ((0x80 & data[i + 0]) == 0):
self.statusBar().showMessage("Error at byte %d"%i)
print("Bytes: %x %x"%(data[i], data[i+1]))
return None
#Convert
intpt = data[i + 1] | ((data[i+0] & 0x07) << 7)
#input validation test: uncomment following and use
#ramp input on FPGA
##if (intpt != lastpt + 1) and (lastpt != 0x3ff):
## print "intpt: %x lstpt %x\n"%(intpt, lastpt)
##lastpt = intpt;
fpData.append(float(intpt) / 1024.0 - self.offset)
return fpData
def arm(self):
print("self.oa.arm-arm")
self.sc.arm()
def read(self, update=True, NumberPoints=None):
print("ya llego a la lectura---new")
print("self.oa.arm-read")
if NumberPoints == None:
NumberPoints = self.adc_settings.parm_trigger.maxSamples()
progress = QProgressDialog("Reading", "Abort", 0, 100)
progress.setWindowModality(Qt.WindowModal)
progress.setMinimumDuration(1000)
try:
self.datapoints = self.sc.readData(NumberPoints, progress)
##################################################################
longitud=len(self.datapoints)
counter=0
while(counter<longitud):
f=open("data.csv",'a')
writer=csv.writer(f,delimiter=',')
writer.writerow([counter,self.datapoints[counter]])
f.close
counter=counter+1
#################################################################
except IndexError, e:
raise IOError("Error reading data: %s"%str(e))
except Exception as f:
print f
self.dataUpdated.emit(self.datapoints, -self.adc_settings.parm_trigger.presamples(True))