Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
if self._scope and self._writer:
self._writer.setKnownKey(self.key)
for channelNum in channelNumbers:
self._writer.addTrace(self._scope.channels[channelNum].getTrace(), self.textin, self.textout,
self.key, channelNum=channelNum)
previous_ok = True
except ValueError as e:
logging.warning('Exception caught in adding trace %d, trace skipped.' % self.currentTrace)
logging.debug(str(e))
previous_ok = False
self.sigTraceDone.emit()
self.currentTrace += 1
else:
previous_ok = False
util.updateUI() # Check if it was aborted
if progressBar is not None:
if progressBar.wasAborted():
break
if self._aux_dict is not None:
for func in self._aux_dict['after_capture']:
func(self._scope, self._target, self._writer)
if self._writer and self._writer.numTraces() > 0:
# Don't clear trace as we re-use the buffer
self._writer.config.setAttr("scopeSampleRate", self._scope.channels[channelNumbers[0]].getSampleRate())
self._writer.closeAll(clearTrace=False)
if tracesDestination:
tracesDestination.appendSegment(self._writer)
def capture(self):
# Wait?
while self.visaInst.ask("*OPC?\n") != "1":
time.sleep(0.1)
util.updateUI()
logging.info('2Waiting...')
# print command
self.visaInst.write(":WAVeform:DATA?")
data = self.visaInst.read_raw()
# Find '#' which is start of frame
start = data.find('#')
if start < 0:
raise IOError('Error in header')
start += 1
hdrlen = data[start]
hdrlen = int(hdrlen)
if tmp == 0:
raise Warning('X Axis of type "Time" in "%s" can\'t have "Sample Rate" with value=0. '
'Change it to its actual value in the Trace Manager.' % self.getName())
xaxis = [v/tmp for v in xaxis]
for i, tnum in enumerate(plotlist):
trace = self._traceSource.getTrace(tnum)
if trace is not None:
if yaxisScaleFactor != 1.0 or yaxisOffsetFactor != 0.0:
trace = [yaxisOffsetFactor + x * yaxisScaleFactor for x in trace]
#TODO - Not sure if should add _traceSource.offset() or not?
traceclr = plotinfo[i]['color']
self.passTrace(trace[pstart:pend+1], pstart + self._traceSource.offset(), idString = str(tnum), xaxis=xaxis, dsmode=dsmode, color = traceclr)
if self.findParam('Redraw after Each').getValue():
util.updateUI()
if tstat_enabled:
ttrace = [0] * (pend - pstart + 1)
tstat_leakage = self.findParam(['tstat', 'type']).getValue()
if tstat_leakage == 'Text In':
b_list = np.array([self._traceSource.getTextin(tnum)[0] for tnum in range(ttstart, ttend+1)])
elif tstat_leakage == 'Text Out':
b_list = np.array([self._traceSource.getTextout(tnum)[0] for tnum in range(ttstart, ttend + 1)])
elif tstat_leakage == 'Key':
b_list = np.array([self._traceSource.getKnownKey(tnum)[0] for tnum in range(ttstart, ttend + 1)])
else:
raise NotImplementedError("Can't calculate t-statistics against input type %s" % tstat_leakage)
x_list = np.array([bin(x).count('1') for x in b_list])
s_x = np.sum(x_list)
mu_x = s_x / len(x_list)
f = IntelHex(filename)
maxsize = self._chip.memtypes[memtype]["size"]
fsize = f.maxaddr() - f.minaddr()
if fsize > maxsize:
raise IOError(
"File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize))
logfunc("AVR Programming %s..." % memtype)
util.updateUI()
fdata = f.tobinarray(start=0)
self.writeMemory(0, fdata, memtype)
logfunc("AVR Reading %s..." % memtype)
util.updateUI()
# Do verify run
rdata = self.readMemory(0, len(fdata)) # memtype ?
for i in range(0, len(fdata)):
if fdata[i] != rdata[i]:
raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i]))
logfunc("Verified %s OK, %d bytes" % (memtype, fsize))
# Wait for a trigger, letting the UI run when it can
while ((status & STATUS_ARM_MASK) == STATUS_ARM_MASK) | ((status & STATUS_FIFO_MASK) == 0):
status = self.getStatus()
# Wait for a moment before re-running the loop
time.sleep(0.05)
diff = datetime.datetime.now() - starttime
# If we've timed out, don't wait any longer for a trigger
if (diff.total_seconds() > self._timeout):
logging.warning('Timeout in OpenADC capture(), trigger FORCED')
timeout = True
self.triggerNow()
# Give the UI a chance to update (does nothing if not using UI)
util.updateUI()
self.arm(False)
# If using large offsets, system doesn't know we are delaying api
nosampletimeout = 100
while (self.getBytesInFifo() == 0) and nosampletimeout:
time.sleep(0.05)
nosampletimeout -= 1
if nosampletimeout == 0:
logging.warning('No samples received. Either very long offset, or no ADC clock (try "Reset ADC DCM"). '
'If you need such a long offset, manually update "nosampletimeout" limit in source code.')
return timeout
def nonBlockingDelay(delay_ms):
DC = _DelayCallback()
Timer().singleShot(delay_ms, DC.done)
while DC.running:
#time.sleep(0.01)
util.updateUI()
def write(self, s):
self._output.write(s)
updateUI()
def program(self, filename, memtype="flash", verify=True, logfunc=print_fun, waitfunc=None):
f = IntelHex(filename)
maxsize = self._chip.memtypes[memtype]["size"]
fsize = f.maxaddr() - f.minaddr()
if fsize > maxsize:
raise IOError(
"File %s appears to be %d bytes, larger than %s size of %d" % (filename, fsize, memtype, maxsize))
logfunc("AVR Programming %s..." % memtype)
util.updateUI()
fdata = f.tobinarray(start=0)
self.writeMemory(0, fdata, memtype)
logfunc("AVR Reading %s..." % memtype)
util.updateUI()
# Do verify run
rdata = self.readMemory(0, len(fdata)) # memtype ?
for i in range(0, len(fdata)):
if fdata[i] != rdata[i]:
raise IOError("Verify failed at 0x%04x, %x != %x" % (i, fdata[i], rdata[i]))
logfunc("Verified %s OK, %d bytes" % (memtype, fsize))