def initScope(self): self.status["openunit"] = ps.ps5000aOpenUnit(ctypes.byref( self.chandle), None, self.resolution) #sets the chandle try: assert_pico_ok(self.status["openunit"]) except: # PicoNotOkError: powerStatus = self.status["openunit"] if powerStatus == 286: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( self.chandle, powerStatus) elif powerStatus == 282: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( self.chandle, powerStatus) else: raise assert_pico_ok(self.status["changePowerSource"]) #find out the ADC range for this resolution self.status["maximumValue"] = ps.ps5000aMaximumValue( self.chandle, ctypes.byref(self.maxADC)) assert_pico_ok(self.status["maximumValue"])
def setup_device(self, resolution): # Open 5000 series PicoScope # Returns handle to chandle for use in future API functions device_resolution = ps.PS5000A_DEVICE_RESOLUTION[resolution] self.status["openunit"] = ps.ps5000aOpenUnit(ctypes.byref(self.chandle), None, device_resolution) try: assert_pico_ok(self.status["openunit"]) # Check if the openstatus is ok (=0) except: # PicoNotOkError: self.change_powersupply(self.status["openunit"]) #assert_pico_ok(self.status["maximumValue"]) # find maximum ADC count value # handle = self.chandle # pointer to value = ctypes.byref(maxADC) self.maxADC = ctypes.c_int16()
def __open__(self): # set resolution res = ps.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_"+self.settings['resolution']] # Returns handle to chandle for use in future API functions self.status["openunit"] = ps.ps5000aOpenUnit(ctypes.byref(self.chandle), None, res) try: assert_pico_ok(self.status["openunit"]) except: # PicoNotOkError: powerStatus = self.status["openunit"] if powerStatus == 286: self.status["changePowerSource"] = ps.ps5000aChangePowerSource(self.chandle, powerStatus) elif powerStatus == 282: self.status["changePowerSource"] = ps.ps5000aChangePowerSource(self.chandle, powerStatus) else: raise assert_pico_ok(self.status["changePowerSource"])
def __init__(self, workingDirectory=r'D:\temp', SN='GX150/0053'): self.chandle = c_int16() self.status = {} self.resolution = ps.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_14BIT"] self.status["openunit"] = ps.ps5000aOpenUnit(byref(self.chandle), \ SN.encode('utf-8'), self.resolution) assert_pico_ok(self.status["openunit"]) self.chs = {'A':ch('A', self.chandle), 'B':ch('B', self.chandle),\ 'C':ch('C', self.chandle), 'D':ch('D', self.chandle)} self.workingDirectory = workingDirectory + '\\' self.psVoltageRange = {0 : 10, 1 : 20, 2 : 50, 3 : 100, 4 : 200, \ 5 : 500, 6 : 1000, 7 : 2000, 8 : 5000, 9 : 10000, 10 : 20000} self.timebase = int(6000) self.timeInternalns = c_float() self.maxSamples = 10000 self.t = None self.f = None
def makeConnection(self): self.status["openunit"] = ps.ps5000aOpenUnit( ctypes.byref(self.chandle), None, self.resolution) try: assert_pico_ok(self.status["openunit"]) except: # PicoNotOkError: self.powerStatus = self.status["openunit"] if self.powerStatus == 286: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( self.chandle, self.powerStatus) elif self.powerStatus == 282: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( self.chandle, self.powerStatus) else: raise assert_pico_ok(self.status["changePowerSource"])
def openDevice(self): self.resolution = '8BIT' _resolution = ps.PS5000A_DEVICE_RESOLUTION['PS5000A_DR_' + self.resolution.upper()] self.status['openunit'] = ps.ps5000aOpenUnit( ctypes.byref(self.chandle), None, _resolution) try: assert_pico_ok(self.status['openunit']) return 0 except: powerStatus = self.status["openunit"] if powerStatus == 286: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( chandle, powerStatus) elif powerStatus == 282: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( chandle, powerStatus) else: # raise return -1
def open(self, serial=None, resolution_bits=12): """Open the device. :param serial: (optional) Serial number of the device :param resolution_bits: vertical resolution in number of bits """ handle = ctypes.c_int16() resolution = _get_resolution_from_bits(resolution_bits) status = ps.ps5000aOpenUnit(ctypes.byref(handle), serial, resolution) status_msg = PICO_STATUS_LOOKUP[status] if status_msg == "PICO_OK": self._handle = handle elif status_msg == 'PICO_NOT_FOUND': raise DeviceNotFoundError() else: raise PicoSDKError(f"PicoSDK returned {status_msg}") self.set_channel('A', is_enabled=False) self.set_channel('B', is_enabled=False)
# This example demonstrates how to use the PicoScope 5000 Series (ps5000a) driver API functions to set up the signal generator to do the following: # # 1. Output a sine wave # 2. Output a square wave # 3. Output a sweep of a square wave signal import ctypes from picosdk.ps5000a import ps5000a as ps import time from picosdk.functions import assert_pico_ok status = {} chandle = ctypes.c_int16() # Open the device status["openUnit"] = ps.ps5000aOpenUnit(ctypes.byref(chandle), None, 1) try: assert_pico_ok(status["openUnit"]) except: # PicoNotOkError: powerStatus = status["openUnit"] if powerStatus == 286: status["changePowerSource"] = ps.ps5000aChangePowerSource( chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps5000aChangePowerSource( chandle, powerStatus) else: raise
# Setup a digital port # Collect a block of data # Plot data import ctypes from picosdk.ps5000a import ps5000a as ps from picosdk.functions import splitMSODataFast, assert_pico_ok import numpy as np import matplotlib.pyplot as plt # Gives the device a handle status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps5000aOpenUnit(ctypes.byref(chandle), None, ps.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_8BIT"]) try: assert_pico_ok(status["openunit"]) except: # powerstate becomes the status number of openunit powerstate = status["openunit"] # If powerstate is the same as 282 then it will run this if statement if powerstate == 282: # Changes the power input to "PICO_POWER_SUPPLY_NOT_CONNECTED" status["ChangePowerSource"] = ps.ps5000aChangePowerSource(chandle, 282) # If the powerstate is the same as 286 then it will run this if statement elif powerstate == 286: # Changes the power input to "PICO_USB3_0_DEVICE_NON_USB3_0_PORT" status["ChangePowerSource"] = ps.ps5000aChangePowerSource(chandle, 286)
import ctypes import numpy as np from picosdk.ps5000a import ps5000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 5000 series PicoScope # Resolution set to 12 Bit resolution = ps.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_12BIT"] # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps5000aOpenUnit(ctypes.byref(chandle), None, resolution) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps5000aChangePowerSource( chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps5000aChangePowerSource( chandle, powerStatus) else: raise
class BuildModel_M3_Single(object): if __name__ == "__main__": # Serial port communication: look this up in 'device manager' port = '/dev/ttyUSB0' # Serial port step = 1000 # Number of traces N = 5000 * 23 # Number of samples samples = 1000 # 2ns, sampling rate= 500MSa/s(p22 2.7 Timebase) timebase = 1 # post-trigger or before-trigger post_trigger = True # trigger threshold(mV) threshold = 2000 # trigger direction posedge_trigger = True # vertical offset vertical_offset = 0.1 #delay delay = 0 plain_len = 32 # byte length of the plaintext cipher_len = 32 # byte length of the ciphertext # Intiliazed random generator random.seed() # Open serial port ser = serial.Serial(port) # Wait for 200ms time.sleep(0.2) if (post_trigger): preTriggerSamples = 0 postTriggerSamples = samples else: preTriggerSamples = samples postTriggerSamples = 0 # Connect the scope chandle = ctypes.c_int16() status = ps.ps5000aOpenUnit( ctypes.byref(chandle), None, ps.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_8BIT"]) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) # Set up channel A status = ps.ps5000aSetChannel(chandle, ps.PICO_CHANNEL["A"], 1, ps.PICO_COUPLING['DC'], ps.PS5000A_RANGE["PS5000A_1V"], vertical_offset) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) # Set up channel B status = ps.ps5000aSetChannel(chandle, ps.PICO_CHANNEL["B"], 1, ps.PICO_COUPLING['DC'], ps.PS5000A_RANGE["PS5000A_5V"], 0) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) # Set up trigger if (posedge_trigger): status = ps.ps5000aSetSimpleTrigger( chandle, 1, ps.PICO_CHANNEL["B"], mV2adc(threshold, ps.PS5000A_RANGE["PS5000A_5V"], ctypes.c_int16(32512)), ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], delay, 0) else: status = ps.ps5000aSetSimpleTrigger( chandle, 1, ps.PICO_CHANNEL["B"], mV2adc(threshold, ps.PS5000A_RANGE["PS5000A_5V"], ctypes.c_int16(32512)), ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_FALLING"], delay, 0) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) # Create buffers ready for assigning pointers for data collection Databuffer = (ctypes.c_int16 * samples)() status = ps.ps5000aSetDataBuffers(chandle, 0, ctypes.byref(Databuffer), None, samples, 0, 0) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) trs = TRS_TraceSet.TRS_TraceSet("BuildModel_M3_Single_1000Samples.trs") trs.write_header(N, samples, True, plain_len + cipher_len, 2E-9, 1 / 65536) for i in range(0, N): # Generate plaintext & mask plaintext = bytearray( [secrets.randbits(8) for j in range(0, plain_len)]) plaintext[28] = int(i / 5000) + 1 # Start status = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) # Send plaintext ser.write(plaintext) # Read out ciphertext ciphertext = bytearray(ser.read(cipher_len)) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Create overflow location overflow = ctypes.c_int16() # create converted type totalSamples cTotalSamples = ctypes.c_int32(samples) # Retried data from scope to buffers assigned above status = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 0, 0, 0, ctypes.byref(overflow)) if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format( PICO_STATUS_LOOKUP[status])) if (overflow.value != 0): print("overflow!") # Write trace trs.write_trace(plaintext, ciphertext, np.array(Databuffer), True) # print to screen if i % step == 0 and i > 0: print("i=" + str(i)) print("Instr=" + str(plaintext[28])) print("plain=") PrintHexData(plaintext) print("cipher=") PrintHexData(ciphertext) trs.close()
def __init__(self): self.status = {} # Exmpty dictionary self.status['running'] = False self.status['status'] = {} # Empty dictionary to hold status results self.chandle = ctypes.c_int16() # Stores handle for the Picotech HW self.maxADC = ctypes.c_int16() # Stores a reference to the max ADC self.resolution = None self.resolutionString = '' self.possibleResValues = { "8-bit": "PS5000A_DR_8BIT", "12-bit": "PS5000A_DR_12BIT", "14-bit": "PS5000A_DR_14BIT", "15-bit": "PS5000A_DR_15BIT", "16-bit": "PS5000A_DR_16BIT" } # MS (2020.10.22): set the possible sampling modes self.samplingMode = None self.possibleSamplingModes = {'Rapid Block Mode': 'rapid_block'} # MS (2020.10.22): set the possible voltage scale self.rangeScale = None self.possibleRanges = { '10 mV': { 'psRANGE': 'PS5000A_10MV', 'intRange': 10 }, '20 mV': { 'psRANGE': 'PS5000A_20MV', 'intRange': 20 }, '50 mV': { 'psRANGE': 'PS5000A_50MV', 'intRange': 50 }, '100 mV': { 'psRANGE': 'PS5000A_100MV', 'intRange': 100 }, '200 mV': { 'psRANGE': 'PS5000A_200MV', 'intRange': 200 }, '500 mV': { 'psRANGE': 'PS5000A_500MV', 'intRange': 500 }, '1 V': { 'psRANGE': 'PS5000A_1V', 'intRange': 1000 }, '2 V': { 'psRANGE': 'PS5000A_2V', 'intRange': 2000 }, '5 V': { 'psRANGE': 'PS5000A_5V', 'intRange': 5000 }, '10 V': { 'psRANGE': 'PS5000A_10V', 'intRange': 10000 }, '20 V': { 'psRANGE': 'PS5000A_20V', 'intRange': 20000 }, } self.possibleWaveforms = { '1': 1, '2': 2, '3': 3, '10': 10, '30': 30, } # channelInputRanges = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000] self.downsampling = False self.downsamplingRatio = 1 # Create chandle and status ready for use self.status["openunit"] = ps.ps5000aOpenUnit( ctypes.byref(self.chandle), None, 1) try: assert_pico_ok(self.status["openunit"]) except: # PicoNotOkError: powerStatus = self.status["openunit"] if self.powerStatus == 286: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( self.chandle, powerStatus) elif self.powerStatus == 282: self.status["changePowerSource"] = ps.ps5000aChangePowerSource( self.chandle, powerStatus) else: raise assert_pico_ok(self.status["changePowerSource"])