def set_trigger(self, scope, **kwargs): # Set up single trigger settings = {} for key, current_value in self.settings.items(): settings[key] = kwargs[key] if key in kwargs else current_value check_kwargs_scope(**kwargs) possible_sources = ['A', 'B'] possible_sources.append('Ext') assert settings[ 'source'] in possible_sources, 'the trigger source channel should be enabled' source = scope.channels[settings['source']] if 'timeIntervalSeconds' in settings: delay = int(settings['delay_s'] / scope.settings['timeIntervalSeconds']) else: delay = 0 _source = ctypes.c_int16( ps.PS2000_CHANNEL[channel_index[settings['source']]]) _chRange = ps.PS2000_VOLTAGE_RANGE[range_index[ source.settings['chRange']]] _threshold = ctypes.c_int16( int(mV2adc(1e3 * settings['threshold'], _chRange, scope._maxADC))) _direction = ctypes.c_int16(int( direction_index[settings['direction']])) _delay = ctypes.c_int16(delay) _autoTrigger_ms = ctypes.c_int16(settings['auto_trigger_ms']) # direction = PS5000A_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms self.status["trigger"] = ps.ps2000_set_trigger(self.chandle, _source, _threshold, _direction, _delay, _autoTrigger_ms) assert_pico2000_ok(self.status["trigger"]) self.settings = settings
def close(self): # Close unit Disconnect the scope # Stop the scope # handle = chandle self.status["stop"] = ps.ps2000_stop(self.chandle) assert_pico2000_ok(self.status["stop"]) # Close unitDisconnect the scope # handle = chandle self.status["close"] = ps.ps2000_close_unit(self.chandle) assert_pico2000_ok(self.status["close"]) # display status returns print('The scope was successfully closed')
def info(self): ''' returns a dictionary containing driver_version, usb_version, hardware_version, variant_info, batch_and_serial, cal_date, error_code and kernel_driver_version ''' info_out = {} _string = (ctypes.c_char * 100)() #info output buffer _stringLength = ctypes.c_int16(100) #max info buffer length for key, value in info_index.items(): _line = ctypes.c_int16(value) status = ps.ps2000_get_unit_info(self.chandle, _string, _stringLength, _line) assert_pico2000_ok(status) info_out[key] = _string.value.decode('utf-8') return info_out
def runBlock(self, scope, **kwargs): settings = {} for key, current_value in self.settings.items(): settings[key] = kwargs[key] if key in kwargs else current_value check_kwargs_scope(**kwargs) _noSamples = int(scope.settings['noSamples']) _timebase = scope.settings['timebase'] _timeIndisposeMs = ctypes.c_int32() _oversample = ctypes.c_int16(scope.settings['oversample']) #additional callback options here, use isready instead self.status["runBlock"] = ps.ps2000_run_block( self.chandle, _noSamples, _timebase, _oversample, ctypes.byref(_timeIndisposeMs)) assert_pico2000_ok(self.status["runBlock"]) self.settings = settings
def read(self, **kwargs): ''' reads the scope results: arguments: none keyword arguments: none the results (in V) are returned in a dictionary: time: the time (in s) A (V): channel A voltage (in V) B (V): channel B voltage (in V) ''' #handles default values settings = {} for key, current_value in self.settings.items(): settings[key] = kwargs[key] if key in kwargs else current_value check_kwargs_scope(**kwargs) # Create buffers ready for data _bufferA = (ctypes.c_int16 * self.settings['noSamples'])() _bufferB = (ctypes.c_int16 * self.settings['noSamples'])() #_bufferC = None #_bufferD = None # create overflow loaction _overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(self.settings['noSamples']) self.status["getValues"] = ps.ps2000_get_values( self.chandle, ctypes.byref(_bufferA), ctypes.byref(_bufferB), None, None, ctypes.byref(_overflow), cmaxSamples) assert_pico2000_ok(self.status["getValues"]) self.settings = settings # Create time data time = np.linspace(0, (cmaxSamples.value) * self.settings['timeIntervalSeconds'], cmaxSamples.value) results = {'time (s)': time} # convert ADC counts data to mV adc2mVChA = adc2mV(_bufferA, self.channels['A']._chRange.value, self._maxADC) adc2mVChB = adc2mV(_bufferB, self.channels['B']._chRange.value, self._maxADC) results['A (V)'] = 1e-3 * np.array(adc2mVChA).reshape(-1, 1) results['B (V)'] = 1e-3 * np.array(adc2mVChB).reshape(-1, 1) return results
def _timeBase(self, settings, timebase): assert type(timebase) is int _timeInterval = ctypes.c_int32() _timeUnits = ctypes.c_int32() _oversample = ctypes.c_int16(settings['oversample']) _maxSamples = ctypes.c_int32() self.status["getTimebase"] = ps.ps2000_get_timebase( self.chandle, timebase, settings['noSamples'], ctypes.byref(_timeInterval), ctypes.byref(_timeUnits), _oversample, ctypes.byref(_maxSamples)) assert_pico2000_ok(self.status["getTimebase"]) timeIntervalSeconds = 1e-9 * _timeInterval.value out = { 'sampleRate': 1. / timeIntervalSeconds, 'noSamples': _maxSamples.value, 'timeIntervalSeconds': timeIntervalSeconds, '_timeUnits': _timeUnits } return out
def set_builtin(self, **kwargs): ''' sets the scope built-in arbitrary generator: arguments: none keyword arguments: offsetVoltage: (in V) pkToPk: (in V) waveType: sine/square/triangle/dc_voltage freq: start and stop frequencies, for sweep (List, in Hz) from 100 mHz up to 100 kHz ---Advanced---- increment: frequency increment (in Hz) dwellTime: frequency increment rate (in Hz/s) sweepType: up/down/updown/downup the type of frequency sweep sweeps: number of sweeps to output ''' #handles default values settings = {} for key, current_value in self.settings.items(): settings[key] = kwargs[key] if key in kwargs else current_value check_kwargs_scope(**kwargs) assert settings['pkToPk'] <= 2.0, 'max pkToPk is 2 Vpp' assert settings['offsetVoltage'] <= 2.0, 'max offset is 2 V' assert (min(settings['freq']) > 100e-3 and max(settings['freq']) < 100e3 ), 'freq can range from 100 mHz up to 100 kHz' _offsetVoltage = ctypes.c_int32(int(settings['offsetVoltage'] * 1e6)) _pkToPk = ctypes.c_uint32(int(settings['pkToPk'] * 1e6)) _waveType = ctypes.c_int32(wave_index[settings['waveType']]) _freqMin = ctypes.c_float(settings['freq'][0]) _freqMax = ctypes.c_float(settings['freq'][-1]) _increment = ctypes.c_float(settings['increment']) _dwellTime = ctypes.c_float(settings['dwellTime']) _sweepType = ctypes.c_int32(sweep_type_index[settings['sweepType']]) _sweeps = ctypes.c_uint32(settings['sweeps']) self.status["setSigGenBuiltIn"] = ps.ps2000_set_sig_gen_built_in( self.chandle, _offsetVoltage, _pkToPk, _waveType, _freqMin, _freqMax, _increment, _dwellTime, _sweepType, _sweeps) assert_pico2000_ok(self.status["setSigGenBuiltIn"]) self.settings = settings
def set_channel(self, **kwargs): # Set up channel settings = {} #in case of failure, settings is updated only at the end for key, current_value in self.settings.items(): settings[key] = kwargs[key] if key in kwargs else current_value #checks check_kwargs_scope(**kwargs) # handle = chandle _channel = ctypes.c_int16( ps.PS2000_CHANNEL[channel_index[self.source]]) _coupling_type = ctypes.c_int16( ps.PICO_COUPLING[coupling_type_index[settings['coupling_type']]]) _chRange = ctypes.c_int16( ps.PS2000_VOLTAGE_RANGE[range_index[settings['chRange']]]) self.status["setCh"] = ps.ps2000_set_channel(self.chandle, _channel, 1, _coupling_type, _chRange) assert_pico2000_ok(self.status["setCh"]) self.settings = settings self._chRange = _chRange
def __init__(self): # Create status ready for use self.status = {} self.settings = { 'timebase': 8, 'noSamples': 2000, 'segmentIndex': 0, 'oversample': 1 } self.channels = {} self._maxADC = ctypes.c_int16(32767) # Open 2000 series PicoScope # Returns handle to chandle for use in future API functions self.status["openUnit"] = ps.ps2000_open_unit() assert_pico2000_ok(self.status["openUnit"]) # Create chandle for use self.chandle = ctypes.c_int16(self.status["openUnit"]) self.add_channel(source='A') self.add_channel(source='B') self.trigger = Trigger(self) self.set_timeBase() self.awg = Function_generator(self)
# Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # TC-08 SINGLE MODE EXAMPLE import ctypes import numpy as np from picosdk.usbtc08 import usbtc08 as tc08 from picosdk.functions import assert_pico2000_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open unit status["open_unit"] = tc08.usb_tc08_open_unit() assert_pico2000_ok(status["open_unit"]) chandle = status["open_unit"] # set mains rejection to 50 Hz status["set_mains"] = tc08.usb_tc08_set_mains(chandle, 0) assert_pico2000_ok(status["set_mains"]) # set up channel # therocouples types and int8 equivalent # B=66 , E=69 , J=74 , K=75 , N=78 , R=82 , S=83 , T=84 , ' '=32 , X=88 typeK = ctypes.c_int8(75) status["set_channel"] = tc08.usb_tc08_set_channel(chandle, 1, typeK) assert_pico2000_ok(status["set_channel"]) # get minimum sampling interval in ms status["get_minimum_interval_ms"] = tc08.usb_tc08_get_minimum_interval_ms(
# Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # PICOHRDL SINGLE MODE EXAMPLE import ctypes import numpy as np from picosdk.picohrdl import picohrdl as hrdl from picosdk.functions import assert_pico2000_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open unit status["openUnit"] = hrdl.HRDLOpenUnit() assert_pico2000_ok(status["openUnit"]) chandle = status["openUnit"] # set mains noise rejection # reject 50 Hz mains noise status["mainsRejection"] = hrdl.HRDLSetMains(chandle, 0) assert_pico2000_ok(status["mainsRejection"]) # set single reading range = hrdl.HRDL_VOLTAGERANGE["HRDL_2500_MV"] conversionTime = hrdl.HRDL_CONVERSIONTIME["HRDL_100MS"] overflow = ctypes.c_int16(0) value = ctypes.c_int32() status["getSingleValue"] = hrdl.HRDLGetSingleValue(chandle, 5, range, conversionTime, 1, ctypes.byref(overflow),
# This example opens a 2000 driver device, sets up two channels and a trigger then collects a block of data. # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps2000 import ps2000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico2000_ok # Create status ready for use status = {} # Open 2000 series PicoScope # Returns handle to chandle for use in future API functions status["openUnit"] = ps.ps2000_open_unit() assert_pico2000_ok(status["openUnit"]) # Create chandle for use chandle = ctypes.c_int16(status["openUnit"]) # Set up channel A # handle = chandle # channel = PS2000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS2000_DC = 1 # range = PS2000_2V = 7 # analogue offset = 0 V chARange = 7 status["setChA"] = ps.ps2000_set_channel(chandle, 0, 1, 1, chARange) assert_pico2000_ok(status["setChA"])
# TC-08 STREAMING MODE EXAMPLE import ctypes import numpy as np import time from picosdk.usbtc08 import usbtc08 as tc08 from picosdk.functions import assert_pico2000_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open unit status["open_unit"] = tc08.usb_tc08_open_unit() assert_pico2000_ok(status["open_unit"]) chandle = status["open_unit"] # set mains rejection to 50 Hz status["set_mains"] = tc08.usb_tc08_set_mains(chandle,0) assert_pico2000_ok(status["set_mains"]) # set up channel # therocouples types and int8 equivalent # B=66 , E=69 , J=74 , K=75 , N=78 , R=82 , S=83 , T=84 , ' '=32 , X=88 typeK = ctypes.c_int8(75) status["set_channel"] = tc08.usb_tc08_set_channel(chandle, 1, typeK) assert_pico2000_ok(status["set_channel"]) # get minimum sampling interval in ms status["get_minimum_interval_ms"] = tc08.usb_tc08_get_minimum_interval_ms(chandle)
def monitor_temperatures(cadence): """ Monitor temperatures thread :param cadence: Time between measurements """ global stop_acquisition # Initialise picologger device import ctypes from picosdk.usbtc08 import usbtc08 as tc08 from picosdk.functions import assert_pico2000_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open unit chandle = None try: ret = tc08.usb_tc08_open_unit() assert_pico2000_ok(ret) chandle = ret except: logging.error( "Could not initialised picologger. Not getting temperatures") return try: # Set mains rejection to 50 Hz status["set_mains"] = tc08.usb_tc08_set_mains(chandle, 0) assert_pico2000_ok(status["set_mains"]) # Set up channels (all type K, cold junction needs to be C) typeC = ctypes.c_int8(67) assert_pico2000_ok(tc08.usb_tc08_set_channel(chandle, 0, typeC)) typeK = ctypes.c_int8(75) for channel in range(1, 9): assert_pico2000_ok( tc08.usb_tc08_set_channel(chandle, channel, typeK)) except: logging.error( "Error while setting up picologger. Not getting temperatures") tc08.usb_tc08_close_unit(chandle) return temp = (ctypes.c_float * 9)() overflow = ctypes.c_int16(0) units = tc08.USBTC08_UNITS["USBTC08_UNITS_CENTIGRADE"] # Read temperatures till told to stop while not stop_acquisition: # Read temperatures try: assert_pico2000_ok( tc08.usb_tc08_get_single(chandle, ctypes.byref(temp), ctypes.byref(overflow), units)) except: logging.error( "Error while getting temperatures, not reading temperatures anymore" ) tc08.usb_tc08_close_unit(chandle) return # Get timestamp timestamp = time.time() # Add RMS to file add_temperatures_to_file(np.array(temp), timestamp) # Sleep for required time time.sleep(cadence)