def run_ps(): # global ps ps = ps2000a.PS2000a() channelRange = ps.setChannel('A', 'DC', 2.0, 0.0, enabled=True, BWLimited=False) channelRange = ps.setChannel('B', 'DC', 10.0, 0.0, enabled=True, BWLimited=False) # print("Chosen channel range = %d" % channelRange) ps.setSimpleTrigger('B', -4.0, 'Falling', delay=0, timeout_ms=100, enabled=True) return ps
def __init__(self, OscilloscopeType="A", printFunction=print): printFunction("Attempting to open Picoscope 2000...") if oscilloscopeType == "A": self.ps = ps2000a.PS2000a( ) # Uncomment this line to use with the 2000a/2000b series elif oscilloscopeType == "B": self.ps = ps2000.PS2000() else: printFunction("You must choose proper communication type") if oscilloscopeType == "A" or oscilloscopeType == "B": printFunction("Found the following picoscope:") printFunction(self.ps.getAllUnitInfo()) self.ranges = [2.0, 1.0, 0.5, 0.2, 0.1, 0.05 ] # oscilloscope ranges available form measurement self.connected = True self.samplesPerObservation = 16384 self.currentRange = self.ranges[0] self.nSamples = 0
def init(self): global SAMPLERATE, VRANGE_PRIMARY, ANALOG_OFFSET print("ps2000: initializing self.scope") self.ps = None self.ps = ps2000a.PS2000a() # print("ps2000: could not initialize scope") # return self.ps.setChannel('A', 'DC', VRange=VRANGE_PRIMARY, VOffset=ANALOG_OFFSET, enabled=True, BWLimited=False) self.ps.setChannel('B', 'DC', VRange=7.0, VOffset=0.0, enabled=True, BWLimited=False) nSamples = self.config["samplecount"] (freq, maxSamples) = self.ps.setSamplingFrequency(SAMPLE_RATE, nSamples) print("ps2000: got frequency %d Hz" % freq)
def __init__(self, device_string, fom_num): """ Set up the picoscope for data acquisition. Determine the channel to read from, how to trigger the device, how many samples to read, etc. to acquire data properly. Parameters ---------- device_string : str A string naming which daq device to use. fom_num : int An int denoting which figure of merit this daq device will be using. """ super().__init__(device_string, fom_num) # call the daq_device __init__ function self.channels = ('A', 'B' ) # the only possible channels are 'A' and 'B' ps = ps2000a.PS2000a( ) # create an instance of the picoscope 2000a class channelA_coupling = self.initialize_array[0] # DC or AC coupling channelA_voltage_range = float( self.initialize_array[1] ) # The voltage range is [-voltage_range, +voltage_range] (excluding offset) channelA_offset = float( self.initialize_array[2] ) # This is an offset that the scope will add to your signal. channelA_enabled = self.initialize_array[ 3] == "True" # determine if the channel is enabled channelA_bandwidth_limited = self.initialize_array[ 4] == "True" # determine if the channel should use bandwidth limiting channelB_coupling = self.initialize_array[5] # DC or AC coupling channelB_voltage_range = float( self.initialize_array[6] ) # The voltage range is [-voltage_range, +voltage_range] (excluding offset) channelB_offset = float( self.initialize_array[7] ) # This is an offset that the scope will add to your signal. channelB_enabled = self.initialize_array[ 8] == "True" # determine if the channel is enabled channelB_bandwidth_limited = self.initialize_array[ 9] == "True" # determine if the channel should use bandwidth limiting # Initialize channel A with all of the desired parameters channelARange = ps.setChannel(self.channels[0], channelA_coupling, channelA_voltage_range, channelA_offset, channelA_enabled, channelA_bandwidth_limited, probeAttenuation=1.0) print("Channel A range is ", channelARange) # Initialize channel B with all of the desired parameters channelBRange = ps.setChannel(self.channels[1], channelB_coupling, channelB_voltage_range, channelB_offset, channelB_enabled, channelB_bandwidth_limited, probeAttenuation=1.0) print("Channel B range is ", channelBRange) trigger_channel = self.initialize_array[10] # the trigger channel trigger_threshold = float(self.initialize_array[11] ) # threshold in volts to activate trigger trigger_direction = self.initialize_array[ 12] # "Rising" or "Falling" trigger trigger_delay = int( self.initialize_array[13] ) # number of clock cycles to wait from trigger conditions met until we actually trigger capture trigger_timeout = int( self.initialize_array[14] ) # time to wait in mS for the trigger to occur. If no trigger occurs it gives up & auto-triggers. trigger_enabled = self.initialize_array[ 15] == "True" # determine whether triggering is enabled # Set up the trigger according to the input parameters ps.setSimpleTrigger(trigger_channel, trigger_threshold, trigger_direction, trigger_delay, trigger_timeout, trigger_enabled) self.signal_channel = self.initialize_array[ 16] # the channel which will be the signal acquisition_window_duration = float( self.initialize_array[17] ) # the duration of the signal acquisition window # idk what or why they do this, Jinpu said to do this because it was done this way in the pico-python example obs_duration = 3 * acquisition_window_duration sampling_interval = obs_duration / 4096 # set up the sampling interval (actualSamplingInterval, self.nSamples, maxSamples) = ps.setSamplingInterval(sampling_interval, obs_duration) print("Sampling interval:", actualSamplingInterval, "\nNumber of samples:", nSamples) self.ps = ps # save the picoscope object
def scope_volts2adc( range, x ) : return ( float( x ) * float( scope_adc_max ) ) / range; if ( __name__ == '__main__' ) : # Phase 1 follows Section 2.7.1.1 of the 2206B programming guide, producing # a 1-shot block mode acquisition process: it configures the 2206B to # # - wait for a trigger signal (a positive edge exceeding 2 V) on channel A, # - sample from both channel A and B, using appropriate voltage ranges and # for an appropriate amount of time (i.e., ~2 ms), # - store the resulting data in buffers with no post-processing (e.g., with # no downsampling). try : # Section 3.32, Page 60; Step 1: open the oscilloscope scope = ps2000a.PS2000a() # Section 3.28, Page 56 scope_adc_min = scope.getMinValue() # Section 3.30, Page 58 scope_adc_max = scope.getMaxValue() # Section 3.39, Page 69; Step 2: configure channels scope.setChannel( channel = 'A', enabled = True, coupling = 'DC', VRange = 5.0E-0 ) scope_range_chan_a = 5.0e-0 scope.setChannel( channel = 'B', enabled = True, coupling = 'DC', VRange = 500.0E-3 ) scope_range_chan_b = 500.0e-3 # Section 3.13, Page 36; Step 3: configure timebase ( _, samples, samples_max ) = scope.setSamplingInterval( 4.0E-9, 2.0E-3 )
next_rand = [random.randint(0, 255) for _ in range(16)] next_autn = [random.randint(0, 255) for _ in range(16)] str_rand = "".join(["%02x" % _ for _ in next_rand]) str_autn = "".join(["%02x" % _ for _ in next_autn]) print("%s:%s" % (str_rand, str_autn)) # /configure?io=412&clk=13255. # /configure?io=412&clk=170000 (for "close" to first round) sc.french_apdu(next_rand, next_autn, debug=True) sys.exit(0) else: print(" >> Initializing numpy bullshit") traces = np.zeros((CONFIG_TRACECOUNT, CONFIG_SAMPLECOUNT), np.float32) data = np.zeros((CONFIG_TRACECOUNT, 16), np.uint8) # RAND data_out = np.zeros((CONFIG_TRACECOUNT, 16), np.uint8) # AUTN print(" >> Initializing picoscope") ps = ps2000a.PS2000a() ps.setChannel('A', 'AC', VRange=VRANGE_PRIMARY, VOffset=CONFIG_ANALOGOFFSET, enabled=True, BWLimited=False) ps.setChannel('B', 'DC', VRange=7.0, VOffset=0.0, enabled=True, BWLimited=False) nSamples = CONFIG_SAMPLECOUNT (freq, maxSamples) = ps.setSamplingFrequency(CONFIG_SAMPLERATE, nSamples)
def canvasClick(self, event): global CONFIG_VRANGE, CONFIG_SAMPLERATE, CONFIG_SAMPLECOUNT, CONFIG_FPREFIX, CONFIG_THRESHOLD, CONFIG_CAPTURES, CONFIG_BACKOFF, CONFIG_DONOTSAVE, CONFIG_SPECGRAM, CONFIG_DISPLAY_SAMPLES try: ps = ps2000a.PS2000a() self.canvas.mpl_disconnect(self.cid) print("Committing capture...") except: print("Failed to commit scope") return ps.setChannel('A', 'DC', VRange=CONFIG_VRANGE, VOffset=0.0, enabled=True, BWLimited=False, probeAttenuation=10.0) (freq, maxSamples) = ps.setSamplingFrequency(CONFIG_SAMPLERATE, CONFIG_SAMPLECOUNT) print(" > Asked for %d Hz, got %d Hz" % (CONFIG_SAMPLERATE, freq)) if CONFIG_FPREFIX is not None: print(" > Configured in training mode with prefix %s" % CONFIG_FPREFIX) ps.setSimpleTrigger('A', CONFIG_THRESHOLD, 'Rising', enabled=True) i = 0 nCount = 0 nMax = CONFIG_CAPTURES print("Capture is committed...") while True: if nMax == nCount: break ps.runBlock(pretrig=0.2) ps.waitReady() dataA = ps.getDataV("A", CONFIG_SAMPLECOUNT, returnOverflow=False) # print(len(dataA)) SLICE_START = int(CONFIG_SAMPLECOUNT * 0.2) SLICE_END = SLICE_START + 500 if float(max( dataA[SLICE_START:SLICE_END])) < float(CONFIG_THRESHOLD): # print("failed capture") continue if CONFIG_DONOTSAVE is False: if CONFIG_FPREFIX is None: print("Saving training capture...") np.save("floss/%d.npy" % nCount, dataA) else: print("Saving real capture...") np.save("toothpicks/%s-%d.npy" % (CONFIG_FPREFIX, nCount), dataA) else: print("No save mode specified, discarding save") self.mainPlot.clear() data_DISPLAY = dataA[SLICE_START - 5000:SLICE_START + 5000] if CONFIG_SPECGRAM: self.mainPlot.specgram(data_DISPLAY, NFFT=1024, Fs=CONFIG_SAMPLERATE, noverlap=900) else: self.mainPlot.plot( support.block_preprocess_function(data_DISPLAY)) self.canvas.draw() self.canvas.flush_events() time.sleep(CONFIG_BACKOFF) nCount += 1 print("Captured %d slices" % nCount)
def btn_def(self): self.picoinfo.insert("insert", "Attempting to open Picoscope 2000..." '\n') self.ps = ps2000a.PS2000a() self.picoinfo.insert("insert", "Found the following picoscope:" '\n') s = self.ps.getAllUnitInfo() self.picoinfo.insert("insert", s) self.picoinfo.insert("insert", '\n') # 从输入框中读取fs和VRange i = 0 var = self.entry.get() size = len(var) fs_var = "" VR_var = "" VR_varB = "" VR_varA = "" dura_var = "" ph_var1 = "" ph_var2 = "" while i < size - 1: if var[i:i + 2] == 'fs': i = i + 3 for j in range(i, size): if var[j] != ' ': fs_var = ''.join([fs_var, var[j]]) else: i = i + 1 break i = i + 1 elif var[i:i + 7] == 'VRangeA': i = i + 8 for j in range(i, size): if var[j] != ' ': VR_varA = ''.join([VR_varA, var[j]]) else: i = i + 1 break i = i + 1 elif var[i:i + 7] == 'VRangeB': i = i + 8 for j in range(i, size): if var[j] != ' ': VR_varB = ''.join([VR_varB, var[j]]) else: i = i + 1 break i = i + 1 elif var[i:i + 6] == 'VRange': i = i + 7 for j in range(i, size): if var[j] != ' ': VR_var = ''.join([VR_var, var[j]]) else: i = i + 1 break i = i + 1 elif var[i:i + 6] == 'TRange': i = i + 7 for j in range(i, size): if var[j] != ' ': dura_var = ''.join([dura_var, var[j]]) else: i = i + 1 break i = i + 1 elif var[i:i + 5] == 'phase': i = i + 6 for j in range(i, size): if (var[j] != ' ') & (var[j] != '-'): ph_var1 = ''.join([ph_var1, var[j]]) else: i = i + 1 break i = i + 1 for j in range(i, size): if (var[j] != ' '): ph_var2 = ''.join([ph_var2, var[j]]) else: i = i + 1 break i = i + 1 else: print("错误命令!") self.text.insert("insert", "错误命令!") self.text.insert("insert", '\n') break if fs_var != '': self.fs = int(fs_var) if VR_var != '': self.VRangeA = float(VR_var) self.VRangeB = float(VR_var) if VR_varA != '': self.VRangeA = float(VR_varA) if VR_varB != '': self.VRangeB = float(VR_varB) if dura_var != '': self.duration = float(dura_var) if (ph_var1 != '') & (ph_var2 != ''): self.phase = (float(ph_var1), float(ph_var2)) self.samplingSet(self.fs, self.VRangeA, self.VRangeB, self.duration) self.read2txt() self.update_txt() self.show_pic() self.newfig() self.ps.stop() self.ps.close()
def get_traces(numTraces): try: scope = ps2000a.PS2000a() global scope_adc_max, scope_adc_min scope_adc_min = scope.getMinValue() scope_adc_max = scope.getMaxValue() scope.setChannel(channel='A', enabled=True, coupling='DC', VRange=5.0E-0) scope_range_chan_a = 5.0e-0 scope.setChannel(channel='B', enabled=True, coupling='DC', VRange=500.0E-3) scope_range_chan_b = 500.0e-3 (_, samples, samples_max) = scope.setSamplingInterval(4.0E-9, 4.0E-4) scope.setSimpleTrigger('A', threshold_V=2.0E-0, direction='Rising', timeout_ms=0) traces = numTraces M = np.zeros((traces, 16), dtype=np.uint8) C = np.zeros((traces, 16), dtype=np.uint8) T = np.zeros((traces, samples), dtype=np.int16) fd = board_open() print("Acquiring traces") for i in range(traces): scope.runBlock() plaintext = "10:" + os.urandom(16).encode("hex") board_wrln(fd, "01:01") board_wrln(fd, plaintext) board_wrln(fd, "10:0000000000000000") ciphertext = board_rdln(fd) while (not scope.isReady()): time.sleep(1) truncatedPlaintext = plaintext[3:] truncatedCiphertext = ciphertext[3:] for j in range(0, 32, 2): M[i, j / 2] = int( truncatedPlaintext[j] + truncatedPlaintext[j + 1], 16) C[i, j / 2] = int( truncatedCiphertext[j] + truncatedCiphertext[j + 1], 16) (B, _, _) = scope.getDataRaw(channel='B', numSamples=samples, downSampleMode=PS2000A_RATIO_MODE_NONE) T[i] = B scope.stop() board_close(fd) scope.close() return traces, samples, M, C, T except Exception as e: raise e
def get_traces(ntraces): # Section 3.32, Page 60; Step 1: open the oscilloscope scope = ps2000a.PS2000a() fd = board_open() t = ntraces s = 10000 T = numpy.zeros((t, s)) M = numpy.zeros((t, 16), dtype=np.uint8) C = numpy.zeros((t, 16), dtype=np.uint8) time.sleep(1) # # Section 3.28, Page 56 scope_adc_min = scope.getMinValue() # # Section 3.30, Page 58 scope_adc_max = scope.getMaxValue() # # Section 3.39, Page 69; Step 2: configure channels scope.setChannel(channel='A', enabled=True, coupling='DC', VRange=5.0E-0) scope_range_chan_a = 5.0e-0 scope.setChannel(channel='B', enabled=True, coupling='DC', VRange=500.0E-3) scope_range_chan_b = 500.0e-3 sample_interval = 4.0e-9 # Section 3.13, Page 36; Step 3: configure timebase (_, samples, samples_max) = scope.setSamplingInterval(4.0e-9, 2 * s * sample_interval) # # # Section 3. 56, Page 93; Step 4: configure trigger scope.setSimpleTrigger('A', threshold_V=2.0E-0, direction='Rising', timeout_ms=0) board_wrln(fd, '01:00') board_rdln(fd) board_rdln(fd) rnd_size = str2seq(octetstr2str(board_rdln(fd)))[0] for i in range(t): print("Getting Trace", i) m = np.random.randint(256, size=16) r = np.random.randint(256, size=rnd_size) # Section 3.37, Page 65; Step 5: start acquisition scope.runBlock() board_wrln(fd, '01:01') board_wrln(fd, str2octetstr(seq2str(m))) board_wrln(fd, str2octetstr(seq2str(r))) # Section 3.26, Page 54; Step 6: wait for acquisition to complete while (not scope.isReady()): time.sleep(0.1) c = str2seq(octetstr2str(board_rdln(fd))) M[i] = m C[i] = c # Section 3.40, Page 71; Step 7: configure buffers # Section 3.18, Page 43; Step 8; transfer buffers (A, _, _) = scope.getDataRaw(channel='A', numSamples=samples, downSampleMode=PS2000A_RATIO_MODE_NONE) (B, _, _) = scope.getDataRaw(channel='B', numSamples=samples, downSampleMode=PS2000A_RATIO_MODE_NONE) # # Section 3.2, Page 25; Step 10: stop acquisition scope.stop() T[i] = B[:s] scope.close() board_close(fd) # Section 3.2, Page 25; Step 13: close the oscilloscope return t, s, M, C, T