Repository: picotech/picosdk-python-wrappers Branch: master Commit: 046520b07e5b Files: 142 Total size: 1.0 MB Directory structure: gitextract_5m9lzjjf/ ├── .github/ │ ├── CODE_OF_CONDUCT.md │ ├── CONTRIBUTING.md │ ├── PULL_REQUEST_TEMPLATE.md │ └── issue_template.md ├── .gitignore ├── LICENSE.md ├── README.md ├── discontinuedExamples/ │ └── anyScopeExamples/ │ └── block.py ├── picohrdlExamples/ │ ├── picohrdlSingleModeExample.py │ └── picohrdlStreamingModeExample.py ├── picosdk/ │ ├── PicoConnectProbes.py │ ├── PicoDeviceEnums.py │ ├── PicoDeviceStructs.py │ ├── __init__.py │ ├── constants.py │ ├── ctypes_wrapper.py │ ├── device.py │ ├── discover.py │ ├── errors.py │ ├── functions.py │ ├── functionsExhibitions.py │ ├── library.py │ ├── picoMeasurements.py │ ├── picohrdl.py │ ├── picosynth.py │ ├── pl1000.py │ ├── ps2000.py │ ├── ps2000a.py │ ├── ps3000.py │ ├── ps3000a.py │ ├── ps4000.py │ ├── ps4000a.py │ ├── ps5000.py │ ├── ps5000a.py │ ├── ps6000.py │ ├── ps6000a.py │ ├── psospa.py │ ├── psospaBlockExample.py │ ├── usbDrDaq.py │ ├── usbPT104.py │ └── usbtc08.py ├── picosynthExamples/ │ └── picosynthFrequencySweepExample.py ├── pl1000Examples/ │ ├── pl1000SingleModeExample.py │ ├── pl1000StreamingModeExample.py │ └── pl1000StreamingModeMultiChannelExample.py ├── ps2000Examples/ │ ├── advanced triggers/ │ │ ├── trigger_read_dropout.py │ │ ├── trigger_read_interval.py │ │ ├── trigger_read_pwq.py │ │ ├── trigger_read_runt.py │ │ ├── trigger_read_window.py │ │ └── trigger_read_wpwq.py │ ├── block_read.py │ ├── device_info.py │ ├── gen_sq_wave.py │ ├── ps2000BlockExample.py │ ├── ps2000ETSBlockExample.py │ ├── ps2000SigGen.py │ └── streaming_mode/ │ ├── streaming_mode.py │ ├── streaming_mode_gathering.py │ ├── streaming_mode_polling.py │ └── streaming_mode_threaded.py ├── ps2000aExamples/ │ ├── ps2000aBlockAdvancedEdgeExample.py │ ├── ps2000aBlockExample.py │ ├── ps2000aBlockExampleCallbackMethod.py │ ├── ps2000aMSOBlockExample.py │ ├── ps2000aRapidBlockExample.py │ ├── ps2000aSigGen.py │ └── ps2000aStreamingExample.py ├── ps3000EExamples/ │ ├── ps3000EBlockExample.py │ ├── ps3000ERapidBlockExample.py │ └── ps3000EStreamingModeExample.py ├── ps3000aExamples/ │ ├── ps3000aBlockAdvancedTriggerExample.py │ ├── ps3000aBlockExample.py │ ├── ps3000aBlockMSOExample.py │ ├── ps3000aRapidBlockExample.py │ ├── ps3000aSigGen.py │ └── ps3000aStreamingExample.py ├── ps4000Examples/ │ ├── ps4000BlockExample.py │ └── ps4000StreamingExample.py ├── ps4000aExamples/ │ ├── ps4000 Ch4 AND logic triggering.py │ ├── ps4000aBlockAdvancedEdgeTriggerExample.py │ ├── ps4000aBlockDropoutTriggerExample.py │ ├── ps4000aBlockFrequencyCounterExample.py │ ├── ps4000aRapidBlockExample.py │ ├── ps4000aRapidBlockWaveformAveragingExample.py │ ├── ps4000aSigGen.py │ ├── ps4000aStreamingExample.py │ ├── ps4000a_Runt_trigger.py │ ├── ps4444BlockExample.py │ ├── ps4444BlockPicoConnectProbesExample.py │ └── ps4824BlockExample.py ├── ps5000Examples/ │ ├── ps5000BlockExample.py │ ├── ps5000RapidBlockExample.py │ └── ps5000StreamingExample.py ├── ps5000aExamples/ │ ├── ps5000aBlockAdvancedTriggerExample.py │ ├── ps5000aBlockCallbackExample.py │ ├── ps5000aBlockExample.py │ ├── ps5000aBlockLevelPulseWidthAdvancedTriggerExample.py │ ├── ps5000aBlockMSOExample.py │ ├── ps5000aBlockMSOTriggerExample.py │ ├── ps5000aBlockWindowPulseWidthAdvancedTriggerExample.py │ ├── ps5000aRapidBlockExample.py │ ├── ps5000aSigGen.py │ └── ps5000aStreamingExample.py ├── ps6000Examples/ │ ├── ps6000BlockAdvancedTriggerExample.py │ ├── ps6000BlockExample.py │ ├── ps6000GetInfoExample.py │ ├── ps6000RapidBlockExample.py │ ├── ps6000RapidBlockTriggerTimestampExample.py │ ├── ps6000SigGen.py │ └── ps6000StreamingExample.py ├── ps6000aExamples/ │ ├── ps6000aBlockAdvancedTriggerExample.py │ ├── ps6000aBlockExample.py │ ├── ps6000aBlockExampleExtClk.py │ ├── ps6000aBlockExampleTrigTimes.py │ ├── ps6000aBlockMSODigitalTriggerExample.py │ ├── ps6000aBlockMSOExample.py │ ├── ps6000aBlock_both_MSOExample.py │ ├── ps6000aGetUnitInfo.py │ ├── ps6000aRapidBlockExample.py │ ├── ps6000aSigGenExample.py │ └── ps6000aStreamingModeExample.py ├── pt104Examples/ │ ├── pt104DirectEthernet.py │ ├── pt104EnumerateTestsExample.py │ └── pt104Example.py ├── requirements-for-examples.txt ├── requirements.txt ├── setup.py ├── setupPicosynth.py ├── test/ │ ├── __init__.py │ ├── run_examples.sh │ ├── test_discover.py │ ├── test_get_unit_info.py │ ├── test_helpers.py │ ├── test_open_close_unit.py │ ├── test_set_channel.py │ └── test_timebase.py ├── usbdrdaqExamples/ │ ├── usbdrdaqPhBlockExample.py │ └── usbdrdaqScopeBlockExample.py └── usbtc08Examples/ ├── tc08SingleModeExample.py ├── tc08StreamingModeExample.py └── tc08StreamingModeMultiChExample.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@picotech.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ ================================================ FILE: .github/CONTRIBUTING.md ================================================ # Contributing We welcome contributions to the picosdk-python-examples repository. By contributing to this repository, you agree to abide by our [code of conduct](CODE_OF_CONDUCT.md). ## Steps to contribute 1. Fork, then clone the repository: ``` git clone https://github.com/YOUR-USERNAME/picosdk-python-wrappers.git ``` 2. Create a new branch - specify a name in lowercase, using hyphens to link words e.g. `fft-example` 3. Push to the new branch on your fork, and then submit a pull request. We will then review the pull request. ## Pull request guidelines * Follow the conventions in the other file headers if adding a new file, or changing an existing file * If contributing a new file, ensure that it is in the appropriate location in the repository directory structure * [Commit messages](https://chris.beams.io/posts/git-commit/#seven-rules) should clearly communicate the reason for the change ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ Fixes #. Changes proposed in this pull request: * * * ================================================ FILE: .github/issue_template.md ================================================ ### Setup * Example filename: * Version of Python: * Pico Technology device model: * Driver name, version number and platform (32- or 64-bit): * Operating system: * USB port type (e.g. 2.0): ### Description #### Steps to reproduce the issue Use one of two methods to describe the issue: 1. A list of steps to reproduce the issue. 1. A natural language description of what you were doing when the issue occurred if you are unable to work out what the steps are. #### Actual Result #### Expected Result ### Notes Include any other information here. ================================================ FILE: .gitignore ================================================ # .gitignore file for picosdk-ps6000a-matlab-instrument-driver # Untracked files/folders to ignore. # Windows platforms **/*.obj **/*.lib **/*.exp **/*.bak # All platforms **/*.h # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # Distribution / packaging build/ dist/ *.egg-info/ *.egg ================================================ FILE: LICENSE.md ================================================ Copyright © 2019 Pico Technology Ltd. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ================================================ FILE: README.md ================================================ # picosdk-python-wrappers Welcome to the PicoSDK for Python. It allows you to control PicoScope devices in your own Python programs. ## Getting started To use this code you will need to install the PicoSDK C libraries. ### Microsoft Windows Please visit [our Downloads page](https://www.picotech.com/downloads) to download the 32-bit or 64-bit PicoSDK C Libraries for Windows. Please take care to match the "bitness" of your python to the PicoSDK. ### Linux Follow the instructions from our [Linux Software & Drivers for Oscilloscopes and Data Loggers page](https://www.picotech.com/downloads/linux) to install the required driver packages for your product. ### macOS Please visit [our Downloads page](https://www.picotech.com/downloads) to download the PicoSDK C Libraries for MacOS. ## Installing the python driver bindings A `distutils` installer is provided. After you have installed the PicoSDK driver package (see above), the Python package can be installed using the following command in the top-level directory: pip install . If you are not using a virtualenv or are not elevated, use: python setup.py install ======= For using the AS108 you will need to use the following as well: python setupPicosynth.py install On macOS and Linux you will either need to use `sudo` with this command, to install into the system folders, or to install for the current user only you can use: pip install . --user Within python, the library for `import` is called `picosdk`. ## Compatibility This code is written to be compatible with both Python 2.7 and Python 3 (any version). If you find a compatibility problem please raise an [Issue](https://www.picotech.com/tech-support), listing all the versions you can find (python, numpy, picosdk commit hash, etc.) and your error message(s). ## C interface You can access C driver functions directly (ctypes calls) by their original C name, following the [Programmer's Guides](https://github.com/picotech/picosdk-python-wrappers#programmers-guides) exactly. Examples are provided in the folders like `psX000[a]Examples/`. ### Programmer's Guides You can download Programmer's Guides providing a description of the API functions for the relevant PicoScope or PicoLog driver from our [Documentation page](https://www.picotech.com/library/documentation). ## Python interface We are in the process of adding Pythonic wrappers around the C functions. If we haven't got to your feature yet or your device is listed as one of the [unsupported models](https://github.com/picotech/picosdk-python-wrappers#unsupported-models), let us know that you're waiting in an [Issue](https://www.picotech.com/tech-support) ### Unsupported models The following drivers and devices are not yet supported: * `plcm3` - PicoLog CM3 Current Data Logger * `ps3000` - PicoScope 3204, 3205, 3206, 3223, 3224, 3423 & 3423 ### Dependencies As well as depending on the C libraries, the Python wrappers use some Python libraries like `numpy`. Many of the examples scripts also use the `matplotlib` plotting library. You can install these dependencies with pip as follows: pip install -r requirements.txt pip install -r requirements-for-examples.txt ### Driver-agnostic examples The `anyScopeExamples` folder contains examples in pure python which do the same thing as the C-style examples, but in a driver-generic way. These examples are currently not being developed further but are still avaliable to use and develop futher yourself. ### Python Classes #### Library `picosdk.library.Library` contains a base class for each of the driver classes. It does the job of translating python types into C ones, and back again, and some unit conversions to get rid of nano, micro and milli-style prefixes. It also handles any differences in programming API between PicoScope driver versions. #### Device `picosdk.device.Device` contains the concrete class which represents a PicoScope with a valid handle. It caches some information about the device state, like the currently selected voltage ranges of the channels. It is implemented in terms of the Library class' public interface, and deals almost entirely with python types. The main exception is its handling of numpy arrays - it (knowing the voltage ranges) is responsible for converting the raw ADC counts that the driver uses for amplitude into physical units. ## Testing this code Check which device driver your device uses, and check the constants at the top of test/test_helpers.py to enable the relevant drivers for connected-device tests. (most tests use this). To check which driver your device uses, you can use `picosdk.discover`: from picosdk.discover import find_all_units scopes = find_all_units() for scope in scopes: print(scope.info) scope.close() You should then configure test/test_helpers.py's list of connected devices, so it can run all the tests we have on your device. To run the unit tests, you will need to install nose (e.g. `pip install nose`.) Then, run `nosetests` in the root of the repo. ## Obtaining support Please visit our [Support page](https://www.picotech.com/tech-support) to contact us directly or visit our [Test and Measurement Forum](https://www.picotech.com/support/forum17.html) to post questions. ## Copyright and licensing See [LICENSE.md](LICENSE.md) for license terms. *PicoScope*, *PicoLog* and *PicoSDK* are registered trademarks of Pico Technology Ltd. *Windows* is a registered trademark of Microsoft Corporation. *macOS* is a registered trademark of Apple Inc. *Linux* is the registered trademark of Linus Torvalds in the U.S. and other countries. Copyright © 2018-2019 Pico Technology Ltd. All rights reserved. ================================================ FILE: discontinuedExamples/anyScopeExamples/block.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # from __future__ import print_function from picosdk.discover import find_unit from picosdk.device import ChannelConfig, TimebaseOptions import matplotlib.pyplot as plt with find_unit() as device: print("found PicoScope: %s" % (device.info,)) channel_configs = [ChannelConfig('A', True, 'DC', 5.)] microsecond = 1.e-6 # the entry-level scopes only have about 8k-samples of memory onboard for block mode, so only ask for 6k samples. timebase_options = TimebaseOptions(microsecond, None, 6000 * microsecond) times, voltages, overflow_warnings = device.capture_block(timebase_options, channel_configs) for channel, data in voltages.items(): label = "Channel %s" % channel if channel in overflow_warnings: label += " (over range)" plt.plot(times, data, label=label) plt.xlabel('Time / s') plt.ylabel('Amplitude / V') plt.legend() plt.show() ================================================ FILE: picohrdlExamples/picohrdlSingleModeExample.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # PICOLOG HIGH RESOLUTION DATA LOGGER SINGLE MODE EXAMPLE # # This example demonstrates how to capture a single value from an ADC-20 or ADC-24 Precision Data Logger. 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), ctypes.byref(value)) assert_pico2000_ok(status["getSingleValue"]) # Display value print(value.value) # Close unit status["closeUnit"] = hrdl.HRDLCloseUnit(chandle) assert_pico2000_ok(status["closeUnit"]) # Print status print(status) ================================================ FILE: picohrdlExamples/picohrdlStreamingModeExample.py ================================================ # # Copyright (C) 2025 Pico Technology Ltd. See LICENSE file for terms. # # PICOLOG HIGH RESOLUTION DATA LOGGER STREAMING MODE EXAMPLE # # This example demonstrates how to capture data streaming from an ADC-20 or ADC-24 Precision Data Logger. import ctypes import numpy as np from picosdk.picohrdl import picohrdl as hrdl from picosdk.functions import assert_pico2000_ok import matplotlib.pyplot as plt import time # Create chandle and status ready for use chandle = ctypes.c_int16(16384) status = {} maxSamples = 200 #1_000 status["closeUnit"] = hrdl.HRDLCloseUnit(chandle) # 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"]) # Setup Channel(s) range = ctypes.c_int16(0) range = hrdl.HRDL_VOLTAGERANGE["HRDL_2500_MV"] overflow = ctypes.c_int16(0) value = ctypes.c_int32() channel = ctypes.c_int16(1) # (Ch number) ADC-20: Ch1 to Ch8 , ADC-24: Ch1 to Ch16 enabled = ctypes.c_int16(1) singleEnded = ctypes.c_int16(1) # 0: differential, Not 0: for single ended status["SetAnalogInChannel"] = hrdl.HRDLSetAnalogInChannel(chandle, channel, enabled, range, singleEnded) assert_pico2000_ok(status["SetAnalogInChannel"]) # Streaming # sampleInterval_ms = conversionTime x NumberOfChannels + 20ms # 20ms = 1/3 of the fastest sample time for one channel sampleInterval_ms = ctypes.c_int32(100 * 1 + 20) conversionTime = hrdl.HRDL_CONVERSIONTIME["HRDL_100MS"] status["SetInterval"] = hrdl.HRDLSetInterval(chandle, sampleInterval_ms, conversionTime) assert_pico2000_ok(status["SetInterval"]) nValues = ctypes.c_int32(20) method = ctypes.c_int16(2) # BM_STREAM (2) status["Run"] = hrdl.HRDLRun(chandle, nValues, method) assert_pico2000_ok(status["Run"]) TotalValues = 0 # Buffers TempBuffer = (ctypes.c_int32 * 100)() BufValues = [] myready = ctypes.c_int16(0) check = ctypes.c_int16(0) # Check for data collection while TotalValues < maxSamples: while myready.value == check.value: myready.value = hrdl.HRDLReady(chandle) time.sleep(0.02) # 20ms = 1/3 of the fastest sample time for one channel # print("ready = ", myready) # DEBUG noOfValues = ctypes.c_int32(20) # Ask for 20 samples noOfValues = hrdl.HRDLGetValues(chandle, ctypes.byref(TempBuffer), ctypes.byref(overflow), noOfValues) TotalValues = TotalValues + int(noOfValues) print("TotalValues = ",TotalValues ,", noOfValues = ", int(noOfValues) ) # DEBUG #sleep (sampleInterval_ms - 20ms /1000) time.sleep( ((100 * 1 + 20) - 20) /1000) #for i in range(noOfValues): ####TempBuffer[i] = adc2mV(TempBuffer[i], channelRange, maxADC) #BufValues.append(float(TempBuffer[i])) #if(noOfValues != 0): # BufValues.append(float(TempBuffer[0])) # Convert to mV and Append values App Buffer loop = noOfValues while (loop != 0): loop = loop -1 # TempBuffer[loop] = adc2mVpl1000(TempBuffer[loop], 2500, 8388607) # adc2mVpl1000(value, Max range in mV, Max ADC count) #TempBuffer[loop] = (TempBuffer[loop] * 2500) / 8388607 BufValues.append(float((TempBuffer[loop] * 2500) / 8388607)) # Stop data collection hrdl.HRDLStop(chandle) # Create time data timeMs = np.linspace(0, (len(BufValues) -1) * 0.1, len(BufValues)) # plot data plt.plot(timeMs, BufValues[:]) plt.xlabel('Time (s)') plt.ylabel('Voltage (mV)') plt.show() # Close unit status["closeUnit"] = hrdl.HRDLCloseUnit(chandle) assert_pico2000_ok(status["closeUnit"]) # Print status print(status) ================================================ FILE: picosdk/PicoConnectProbes.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the enumerations from the PicoConnectProbes.h C header file for use with various PicoScope oscilloscopes driver API functions. """ from ctypes import * from picosdk.constants import make_enum from picosdk.library import Library class PicoConnectProbeslib(Library): def __init__(self): super(PicoConnectProbeslib, self).__init__("picoConnectProbes") picoConnectProbes = PicoConnectProbeslib() def _define_pico_probe_range_info(): PICO_PROBE_NONE_NV = 0 PICO_X1_PROBE_NV = 1 PICO_X10_PROBE_NV = 10 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoConnectProbes.PICO_PROBE_RANGE_INFO = _define_pico_probe_range_info ================================================ FILE: picosdk/PicoDeviceEnums.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the enumerations from the PicoDeviceEnums.h C header file for use with PicoScope 6000 A Series oscilloscopes using the ps6000a driver API functions. """ from ctypes import * from picosdk.constants import make_enum from picosdk.library import Library class PicoEnumlib(Library): def __init__(self): super(PicoEnumlib, self).__init__("ps6000a") picoEnum = PicoEnumlib() def _define_ratio_mode(): PICO_RATIO_MODE_AGGREGATE = 1 PICO_RATIO_MODE_DECIMATE = 2 PICO_RATIO_MODE_AVERAGE = 4 PICO_RATIO_MODE_DISTRIBUTION = 8 PICO_RATIO_MODE_SUM = 16 PICO_RATIO_MODE_TRIGGER_DATA_FOR_TIME_CALCUATION = 0x10000000 PICO_RATIO_MODE_SEGMENT_HEADER = 0x20000000 PICO_RATIO_MODE_TRIGGER = 0x40000000 PICO_RATIO_MODE_RAW = 0x80000000 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_RATIO_MODE = _define_ratio_mode() def _define_channel(): PICO_CHANNEL_A = 0 PICO_CHANNEL_B = 1 PICO_CHANNEL_C = 2 PICO_CHANNEL_D = 3 PICO_CHANNEL_E = 4 PICO_CHANNEL_F = 5 PICO_CHANNEL_G = 6 PICO_CHANNEL_H = 7 PICO_PORT0 = 128 PICO_PORT1 = 129 PICO_PORT2 = 130 PICO_PORT3 = 131 PICO_EXTERNAL = 1000 PICO_TRIGGER_AUX = 1001 PICO_PULSE_WIDTH_SOURCE = 0x10000000 PICO_DIGITAL_SOURCE = 0x10000001 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_CHANNEL = _define_channel() def _define_channel_flags(): PICO_CHANNEL_A_FLAGS = 1 PICO_CHANNEL_B_FLAGS = 2 PICO_CHANNEL_C_FLAGS = 4 PICO_CHANNEL_D_FLAGS = 8 PICO_CHANNEL_E_FLAGS = 16 PICO_CHANNEL_F_FLAGS = 32 PICO_CHANNEL_G_FLAGS = 64 PICO_CHANNEL_H_FLAGS = 128 PICO_PORT0_FLAGS = 65536 PICO_PORT1_FLAGS = 131072 PICO_PORT2_FLAGS = 262144 PICO_PORT3_FLAGS = 524288 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_CHANNEL_FLAGS = _define_channel_flags() picoEnum.PICO_PORT_DIGITAL_CHANNEL = make_enum([ "PICO_PORT_DIGITAL_CHANNEL0", "PICO_PORT_DIGITAL_CHANNEL1", "PICO_PORT_DIGITAL_CHANNEL2", "PICO_PORT_DIGITAL_CHANNEL3", "PICO_PORT_DIGITAL_CHANNEL4", "PICO_PORT_DIGITAL_CHANNEL5", "PICO_PORT_DIGITAL_CHANNEL6", "PICO_PORT_DIGITAL_CHANNEL7", ]) picoEnum.PICO_DATA_TYPE = make_enum([ "PICO_INT8_T", "PICO_INT16_T", "PICO_INT32_T", "PICO_UINT32_T", "PICO_INT64_T", ]) def _define_coupling(): PICO_AC = 0 PICO_DC = 1 PICO_DC_50OHM = 50 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_COUPLING = _define_coupling() # PicoBandwitdthLimiterFlags # needs implementing still def _define_bandwidth_limiter(): PICO_BW_FULL = 0 PICO_BW_100KHZ = 100000 PICO_BW_20KHZ = 20000 PICO_BW_1MHZ = 1000000 PICO_BW_20MHZ = 20000000 PICO_BW_25MHZ = 25000000 PICO_BW_50MHZ = 50000000 PICO_BW_200HMZ = 200000000 PICO_BW_250MHZ = 250000000 PICO_BW_500MHZ = 500000000 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_BANDWIDTH_LIMITER = _define_bandwidth_limiter() picoEnum.PICO_PULSE_WIDTH_TYPE = make_enum([ "PICO_PW_TYPE_NONE", "PICO_PW_TYPE_LESS_THAN", "PICO_PW_TYPE_GREATER_THAN", "PICO_PW_IN_RANGE", "PICO_PW_TYPE_OUT_OF_RANGE" ]) picoEnum.PICO_SWEEP_TYPE = make_enum([ "PICO_UP", "PICO_DOWN", "PICO_UPDOWN", "PICO_DOWNUP" ]) def _define_wave_type(): PICO_SINE = 0x00000011 PICO_SQUARE = 0x00000012 PICO_TRIANGLE = 0x00000013 PICO_RAMP_UP = 0x00000014 PICO_RAMP_DOWN = 0x00000015 PICO_SINC = 0x00000016 PICO_GAUSSIAN = 0x00000017 PICO_HALF_SINE = 0x00000018 PICO_DC_VOLTAGE = 0x00000400 PICO_PWM = 0x00001000 PICO_WHITENOISE = 0x00002001 PICO_PRBS = 0x00002002 PICO_ARBITRARY = 0x10000000 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_WAVE_TYPE = _define_wave_type() picoEnum.PICO_SIGGEN_TRIG_TYPE = make_enum([ "PICO_SIGGEN_RISING", "PICO_SIGGEN_FALLING", "PICO_SIGGEN_GATE_HIGH", "PICO_SIGGEN_GATE_LOW" ]) picoEnum.PICO_SIGGEN_TRIG_SOURCE = make_enum([ "PICO_SIGGEN_NONE", "PICO_SIGGEN_SCOPE_TRIG", "PICO_SGGEN_AUX_IN", "PICO_SIGGEN_EXT_IN", "PICO_SIGGEN_SOFT_TRIG", "PICO_SIGGEN_TRIGGER_RAW" ]) picoEnum.PICO_SIGGEN_FILTER_STATE = make_enum([ "PICO_SIGGEN_FILTER_AUTO", "PICO_SIGGEN_FILTER_OFF", "PICO_SIGGEN_FILTER_ON" ]) picoEnum.PICO_SIGGEN_PARAMETER = make_enum([ "PICO_SIGGEN_PARAM_OUTPUT_VOLTS", "PICO_SIGGEN_PARAM_SAMPLE", "PICO_SIGGEN_BUFFER_LENGTH" ]) picoEnum.PICO_TIME_UNITS = make_enum([ "PICO_FS", "PICO_PS", "PICO_NS", "PICO_US", "PICO_MS", "PICO_S" ]) def _define_threshold_direction(): PICO_ABOVE = PICO_INSIDE = 0 PICO_BELOW = PICO_OUTSIDE = 1 PICO_RISING = PICO_ENTER = PICO_NONE = 2 PICO_FALLING = PICO_EXIT = 3 PICO_RISING_OR_FALLING = PICO_ENTER_OR_EXIT = 4 PICO_ABOVE_LOWER = 5 PICO_BELOW_LOWER = 6 PICO_RISING_LOWER = 7 PICO_FALLING_LOWER = 8 PICO_POSITIVE_RUNT = 9 PICO_NEGATIVE_RUNT = 10 PICO_LOGIC_LOWER = 1000 PICO_LOGIC_UPPER = 1001 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_THRESHOLD_DIRECTION = _define_threshold_direction() picoEnum.PICO_THRESHOLD_MODE = make_enum([ "PICO_LEVEL", "PICO_WINDOW" ]) picoEnum.PICO_ETS_MODE = make_enum([ "PICO_ETS_OFF", "PICO_ETS_FAST", "PICO_ETS_SLOW" ]) picoEnum.PICO_INDEX_MODE = make_enum([ "PICO_SINGLE", "PICO_DUAL", "PICO_QUAD" ]) def _define_action(): PICO_CLEAR_ALL = 0x00000001 PICO_ADD = 0x00000002 PICO_CLEAR_THIS_DATA_BUFFER = 0x00001000 PICO_CLEAR_WAVEFORM_DATA_BUFFERS = 0x00002000 PICO_CLEAR_WAVEFORM_READ_DATA_BUFFERS = 0x00004000 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_ACTION = _define_action() picoEnum.PICO_TRIGGER_STATE = make_enum([ "PICO_CONDITION_DONT_CARE", "PICO_CONDITION_TRUE", "PICO_CONDITION_FALSE" ]) def _define_resolution(): PICO_DR_8BIT = 0 PICO_DR_12BIT = 1 PICO_DR_14BIT = 2 PICO_DR_15BIT = 3 PICO_DR_16BIT = 4 PICO_DR_10BIT = 10 PICO_DR_10BIT_TURBO = 0x1A return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_DEVICE_RESOLUTION = _define_resolution() picoEnum.PICO_READ_SELECTION = make_enum([ "PICO_READSELECTION_NONE", "PICO_TRIGGER_READ", "PICO_DATA_READ1", "PICO_DATA_READ2", "PICO_DATA_READ3" ]) picoEnum.PICO_TRIM_ACTION = make_enum([ "PICO_OLDEST", "PICO_RECENT" ]) picoEnum.PICO_DIGITAL_PORT_HYSTERESIS = make_enum([ "PICO_VERY_HIGH_400MV", "PICO_HIGH_200MV", "PICO_NORMAL_100MV", "PICO_LOW_50MV" ]) picoEnum.PICO_DIGITAL_DIRECTION = make_enum([ "PICO_DIGITAL_DONT_CARE", "PICO_DIGITAL_DIRECTION_LOW", "PICO_DIGITAL_DIRECTION_HIGH", "PICO_DIGITAL_DIRECTION_RISING", "PICO_DIGITAL_DIRECTION_FALLING", "PICO_DIGITAL_DIRECTION_RISING_OR_FALLING", "PICO_DIGITAL_DIRECTION_MAX_DIRECTION" ]) def _define_conditions_info(): PICO_CLEAR_CONDITIONS = 0x00000001 PICO_ADD_CONDITIONS = 0x00000002 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_CONDITIONS_INFO = _define_conditions_info() picoEnum.PICO_CLOCK_REFERENCE = make_enum([ "PICO_INTERNAL_REF", "PICO_EXTERNAL_REF" ]) picoEnum.PICO_TRIGGER_WITHIN_PRE_TRIGGER = make_enum([ "PICO_DISABLE", "PICO_ARM" ]) picoEnum.PICO_TEMPERATURE_REFERENCE = make_enum([ "PICO_TEMPERATURE_UNINITIALISED", "PICO_TEMPERATURE_NORMAL", "PICO_TEMPERATURE_WARNING", "PICO_TEMPERATURE_CRITICAL", "PICO_TEMPERATURE_REFERENCE" ]) def _define_digital_port(): PICO_DIGITAL_PORT_NONE = 0 PICO_DIGITAL_PORT_MSO_POD = 1000 PICO_DIGITAL_PORT_UNKNOWN_DEVICE = -2 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_DIGITAL_PORT = _define_digital_port picoEnum.PICO_EXTERNAL_FREQUENCY = make_enum([ "PICO_FREQUENCY_OFF", "PICO_FREQUENCY_5MHZ", "PICO_FREQUENCY_10MHZ", "PICO_FREQUENCY_20MHZ", "PICO_FREQUENCY_25MHZ" ]) def _define_power_delivery_device_type(): PICO_USB_POWER_DELIEVRY_DEVICE_TYPE_NOTHING = 0 PICO_USB_POWER_DELIEVRY_DEVICE_TYPE_SOURCE = 2 PICO_USB_POWER_DELIEVRY_DEVICE_TYPE_DEBUG = 3 return {k.upper(): v for k, v in locals().items() if k.startswith("PICO")} picoEnum.PICO_USB_POWER_DELIEVRY_DEVICE_TYPE = _define_power_delivery_device_type picoEnum.PICO_AUXIO_MODE = make_enum([ "PICO_AUXIO_INPUT", "PICO_AUXIO_HIGH_OUT", "PICO_AUXIO_LOW_OUT", "PICO_AUXIO_TRIGGER_OUT" ]) ================================================ FILE: picosdk/PicoDeviceStructs.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the structures from the PicoDeviceStructs.h C header file for use with PicoScope 6000 A Series oscilloscopes using the ps6000a driver API functions. """ from ctypes import * from picosdk.library import Library class PicoStructlib(Library): def __init__(self): super(PicoStructlib, self).__init__("ps6000a") picoStruct = PicoStructlib() class PICO_TRIGGER_INFO(Structure): _pack_ = 1 _fields_ = [("status", c_uint32), ("segmentIndex", c_uint64), ("triggerIndex", c_uint64), ("triggerTime", c_double), ("timeUnits", c_uint32), ("missedTriggers", c_uint64), ("timeStampCounter", c_uint64)] picoStruct.PICO_TRIGGER_INFO = PICO_TRIGGER_INFO class PICO_TRIGGER_CHANNEL_PROPERTIES(Structure): _pack_ = 1 _fields_ = [("thresholdUpper", c_int16), ("thresholdUpperHysteresis", c_uint16), ("thresholdLower", c_int16), ("thresholdLowerHysteresis", c_uint16), ("channel", c_uint32)] picoStruct.PICO_TRIGGER_CHANNEL_PROPERTIES = PICO_TRIGGER_CHANNEL_PROPERTIES class PICO_CONDITION(Structure): _pack_ = 1 _fields_ = [("source", c_uint32), ("condition", c_uint32)] picoStruct.PICO_CONDITION = PICO_CONDITION class PICO_DIRECTION(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("direction", c_uint32), ("thresholdMode", c_uint32)] picoStruct.PICO_DIRECTION = PICO_DIRECTION class PICO_USER_PROBE_INTERACTIONS(Structure): _pack_ = 1 _fields_ = [("connected", c_uint16), ("channel", c_uint32), ("enabled", c_uint16), ("probeName", c_uint32), ("requiresPower", c_uint8), ("isPowered", c_uint8), ("status", c_uint32), ("probeOff", c_uint32), ("rangeFirst", c_uint32), ("rangeLast", c_uint32), ("rangeCurrent", c_uint32), ("couplingFirst", c_uint32), ("couplingLast", c_uint32), ("couplingCurrent", c_uint32), ("filterFlags", c_uint32), ("filterCurrent", c_uint32)] picoStruct.PICO_USER_PROBE_INTERACTIONS = PICO_USER_PROBE_INTERACTIONS class PICO_DATA_BUFFERS(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("waveform", c_uint64), ("downSampleRatioMode", c_uint32), ("read", c_uint32), ("bufferMax", c_void_p), ("bufferMin", c_void_p), ("dataType", c_uint32), ("nDistributionPoints", c_uint32)] picoStruct.PICO_DATA_BUFFERS = PICO_DATA_BUFFERS class PICO_STREAMING_DATA_INFO(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("mode", c_uint32), ("type", c_uint32), ("noOfSamples", c_int32), ("bufferIndex", c_uint64), ("startIndex", c_int32), ("overflow", c_int16)] picoStruct.PICO_STREAMING_DATA_INFO = PICO_STREAMING_DATA_INFO class PICO_STREAMING_DATA_TRIGGER_INFO(Structure): _pack_ = 1 _fields_ = [("triggerAt", c_uint64), ("triggered", c_int16), ("autoStop", c_int16)] picoStruct.PICO_STREAMING_DATA_TRIGGER_INFO = PICO_STREAMING_DATA_TRIGGER_INFO class PICO_SCALING_FACTORS(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("range", c_uint32), ("offset", c_int16), ("scalingFactor", c_double)] picoStruct.PICO_SCALING_FACTORS = PICO_SCALING_FACTORS class PICO_SCALING_FACTORS_FOR_RANGE_TYPES(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("rangeMin", c_int64), ("rangeMax", c_int64), ("rangeType", c_uint32), ("offset", c_int16), ("scalingFactor", c_double)] picoStruct.PICO_SCALING_FACTORS_FOR_RANGE_TYPES = PICO_SCALING_FACTORS_FOR_RANGE_TYPES class PROBE_APP(Structure): _pack_ = 1 _fields_ = [("id", c_int32), ("appMajorVersion", c_int32), ("appMinorVersion", c_int32)] picoStruct.PROBE_APP = PROBE_APP class DIGITAL_CHANNEL_DIRECTIONS(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("direction", c_uint32)] picoStruct.DIGITAL_CHANNEL_DIRECTIONS = DIGITAL_CHANNEL_DIRECTIONS class PICO_DIGITAL_PORT_INTERACTIONS(Structure): _pack_ = 1 _fields_ = [("connected", c_uint16), ("channel", c_uint32), ("digitalPortName", c_uint32), ("status", c_uint32), ("serial", c_int8), ("calibrationDate", c_int8)] picoStruct.PICO_DIGITAL_PORT_INTERACTIONS = PICO_DIGITAL_PORT_INTERACTIONS class PICO_CHANNEL_OVERVOLTAGE_TRIPPED(Structure): _pack_ = 1 _fields_ = [("channel", c_uint32), ("tripped", c_uint8)] picoStruct.PICO_CHANNEL_OVERVOLTAGE_TRIPPED = PICO_CHANNEL_OVERVOLTAGE_TRIPPED class PICO_USB_POWER_DELIVERY(Structure): _pack_ = 1 _fields_ = [("valid", c_uint8), ("busVoltagemV", c_uint32), ("rpCurrentLimitmA", c_uint32), ("partnerConnected", c_uint8), ("ccPolarity", c_uint8), ("attachedDevice", c_uint32), ("contractExists", c_uint8), ("currentPdo", c_uint32), ("currentRdo", c_uint32)] picoStruct.PICO_USB_POWER_DELIVERY = PICO_USB_POWER_DELIVERY class PICO_USB_POWER_DETAILS(Structure): _pack_ = 1 _fields_ = [("dataPort", c_uint32), ("powerPort", c_uint32)] picoStruct.PICO_USB_POWER_DETAILS = PICO_USB_POWER_DETAILS ================================================ FILE: picosdk/__init__.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # ================================================ FILE: picosdk/constants.py ================================================ # # Copyright (C) 2014-2018 Pico Technology Ltd. See LICENSE file for terms. # """ Defines python-visible versions of preprocessor-macros from Pico SDK C header files. All constants in this file are exposed directly on the Library class specific to each driver. That (rather than importing this file directly) is the supported way of accessing them, since some older drivers have different names/values for some of the macros. """ from picosdk.errors import UnknownConstantError # convenience functions provided in the old python SDK: def pico_tag(number): """Get the macro name for a given PICO_STATUS value.""" try: return PICO_STATUS_LOOKUP[number] except KeyError: raise UnknownConstantError("%s is not a known PICO_STATUS value." % number) def pico_num(tag): """Resolve the numerical constant associated with a PICO_STATUS macro.""" try: return PICO_STATUS[tag] except KeyError: raise UnknownConstantError("%s is not a known PICO_STATUS macro." % tag) def make_enum(members): """All C enums with no specific values follow the pattern 0, 1, 2... in the order they are in source.""" enum = {} for i, member in enumerate(members): keys = [member] if isinstance(member, tuple): # this member has multiple names! keys = member for key in keys: enum[key] = i return enum PICO_STATUS = { "PICO_OK": 0x00000000, "PICO_MAX_UNITS_OPENED": 0x00000001, "PICO_MEMORY_FAIL": 0x00000002, "PICO_NOT_FOUND": 0x00000003, "PICO_FW_FAIL": 0x00000004, "PICO_OPEN_OPERATION_IN_PROGRESS": 0x00000005, "PICO_OPERATION_FAILED": 0x00000006, "PICO_NOT_RESPONDING": 0x00000007, "PICO_CONFIG_FAIL": 0x00000008, "PICO_KERNEL_DRIVER_TOO_OLD": 0x00000009, "PICO_EEPROM_CORRUPT": 0x0000000A, "PICO_OS_NOT_SUPPORTED": 0x0000000B, "PICO_INVALID_HANDLE": 0x0000000C, "PICO_INVALID_PARAMETER": 0x0000000D, "PICO_INVALID_TIMEBASE": 0x0000000E, "PICO_INVALID_VOLTAGE_RANGE": 0x0000000F, "PICO_INVALID_CHANNEL": 0x00000010, "PICO_INVALID_TRIGGER_CHANNEL": 0x00000011, "PICO_INVALID_CONDITION_CHANNEL": 0x00000012, "PICO_NO_SIGNAL_GENERATOR": 0x00000013, "PICO_STREAMING_FAILED": 0x00000014, "PICO_BLOCK_MODE_FAILED": 0x00000015, "PICO_NULL_PARAMETER": 0x00000016, "PICO_ETS_MODE_SET": 0x00000017, "PICO_DATA_NOT_AVAILABLE": 0x00000018, "PICO_STRING_BUFFER_TO_SMALL": 0x00000019, "PICO_ETS_NOT_SUPPORTED": 0x0000001A, "PICO_AUTO_TRIGGER_TIME_TO_SHORT": 0x0000001B, "PICO_BUFFER_STALL": 0x0000001C, "PICO_TOO_MANY_SAMPLES": 0x0000001D, "PICO_TOO_MANY_SEGMENTS": 0x0000001E, "PICO_PULSE_WIDTH_QUALIFIER": 0x0000001F, "PICO_DELAY": 0x00000020, "PICO_SOURCE_DETAILS": 0x00000021, "PICO_CONDITIONS": 0x00000022, "PICO_USER_CALLBACK": 0x00000023, "PICO_DEVICE_SAMPLING": 0x00000024, "PICO_NO_SAMPLES_AVAILABLE": 0x00000025, "PICO_SEGMENT_OUT_OF_RANGE": 0x00000026, "PICO_BUSY": 0x00000027, "PICO_STARTINDEX_INVALID": 0x00000028, "PICO_INVALID_INFO": 0x00000029, "PICO_INFO_UNAVAILABLE": 0x0000002A, "PICO_INVALID_SAMPLE_INTERVAL": 0x0000002B, "PICO_TRIGGER_ERROR": 0x0000002C, "PICO_MEMORY": 0x0000002D, "PICO_SIG_GEN_PARAM": 0x0000002E, "PICO_SHOTS_SWEEPS_WARNING": 0x0000002F, "PICO_SIGGEN_TRIGGER_SOURCE": 0x00000030, "PICO_AUX_OUTPUT_CONFLICT": 0x00000031, "PICO_AUX_OUTPUT_ETS_CONFLICT": 0x00000032, "PICO_WARNING_EXT_THRESHOLD_CONFLICT": 0x00000033, "PICO_WARNING_AUX_OUTPUT_CONFLICT": 0x00000034, "PICO_SIGGEN_OUTPUT_OVER_VOLTAGE": 0x00000035, "PICO_DELAY_NULL": 0x00000036, "PICO_INVALID_BUFFER": 0x00000037, "PICO_SIGGEN_OFFSET_VOLTAGE": 0x00000038, "PICO_SIGGEN_PK_TO_PK": 0x00000039, "PICO_CANCELLED": 0x0000003A, "PICO_SEGMENT_NOT_USED": 0x0000003B, "PICO_INVALID_CALL": 0x0000003C, "PICO_GET_VALUES_INTERRUPTED": 0x0000003D, "PICO_NOT_USED": 0x0000003F, "PICO_INVALID_SAMPLERATIO": 0x00000040, "PICO_INVALID_STATE": 0x00000041, "PICO_NOT_ENOUGH_SEGMENTS": 0x00000042, "PICO_DRIVER_FUNCTION": 0x00000043, "PICO_RESERVED": 0x00000044, "PICO_INVALID_COUPLING": 0x00000045, "PICO_BUFFERS_NOT_SET": 0x00000046, "PICO_RATIO_MODE_NOT_SUPPORTED": 0x00000047, "PICO_RAPID_NOT_SUPPORT_AGGREGATION": 0x00000048, "PICO_INVALID_TRIGGER_PROPERTY": 0x00000049, "PICO_INTERFACE_NOT_CONNECTED": 0x0000004A, "PICO_RESISTANCE_AND_PROBE_NOT_ALLOWED": 0x0000004B, "PICO_POWER_FAILED": 0x0000004C, "PICO_SIGGEN_WAVEFORM_SETUP_FAILED": 0x0000004D, "PICO_FPGA_FAIL": 0x0000004E, "PICO_POWER_MANAGER": 0x0000004F, "PICO_INVALID_ANALOGUE_OFFSET": 0x00000050, "PICO_PLL_LOCK_FAILED": 0x00000051, "PICO_ANALOG_BOARD": 0x00000052, "PICO_CONFIG_FAIL_AWG": 0x00000053, "PICO_INITIALISE_FPGA": 0x00000054, "PICO_EXTERNAL_FREQUENCY_INVALID": 0x00000056, "PICO_CLOCK_CHANGE_ERROR": 0x00000057, "PICO_TRIGGER_AND_EXTERNAL_CLOCK_CLASH": 0x00000058, "PICO_PWQ_AND_EXTERNAL_CLOCK_CLASH": 0x00000059, "PICO_UNABLE_TO_OPEN_SCALING_FILE": 0x0000005A, "PICO_MEMORY_CLOCK_FREQUENCY": 0x0000005B, "PICO_I2C_NOT_RESPONDING": 0x0000005C, "PICO_NO_CAPTURES_AVAILABLE": 0x0000005D, "PICO_NOT_USED_IN_THIS_CAPTURE_MODE": 0x0000005E, "PICO_TOO_MANY_TRIGGER_CHANNELS_IN_USE": 0x0000005F, "PICO_INVALID_TRIGGER_DIRECTION": 0x00000060, "PICO_INVALID_TRIGGER_STATES": 0x00000061, "PICO_GET_DATA_ACTIVE": 0x00000103, "PICO_IP_NETWORKED": 0x00000104, "PICO_INVALID_IP_ADDRESS": 0x00000105, "PICO_IPSOCKET_FAILED": 0x00000106, "PICO_IPSOCKET_TIMEDOUT": 0x00000107, "PICO_SETTINGS_FAILED": 0x00000108, "PICO_NETWORK_FAILED": 0x00000109, "PICO_WS2_32_DLL_NOT_LOADED": 0x0000010A, "PICO_INVALID_IP_PORT": 0x0000010B, "PICO_COUPLING_NOT_SUPPORTED": 0x0000010C, "PICO_BANDWIDTH_NOT_SUPPORTED": 0x0000010D, "PICO_INVALID_BANDWIDTH": 0x0000010E, "PICO_AWG_NOT_SUPPORTED": 0x0000010F, "PICO_ETS_NOT_RUNNING": 0x00000110, "PICO_SIG_GEN_WHITENOISE_NOT_SUPPORTED": 0x00000111, "PICO_SIG_GEN_WAVETYPE_NOT_SUPPORTED": 0x00000112, "PICO_INVALID_DIGITAL_PORT": 0x00000113, "PICO_INVALID_DIGITAL_CHANNEL": 0x00000114, "PICO_INVALID_DIGITAL_TRIGGER_DIRECTION": 0x00000115, "PICO_SIG_GEN_PRBS_NOT_SUPPORTED": 0x00000116, "PICO_ETS_NOT_AVAILABLE_WITH_LOGIC_CHANNELS": 0x00000117, "PICO_WARNING_REPEAT_VALUE": 0x00000118, "PICO_POWER_SUPPLY_CONNECTED": 0x00000119, "PICO_POWER_SUPPLY_NOT_CONNECTED": 0x0000011A, "PICO_POWER_SUPPLY_REQUEST_INVALID": 0x0000011B, "PICO_POWER_SUPPLY_UNDERVOLTAGE": 0x0000011C, "PICO_CAPTURING_DATA": 0x0000011D, "PICO_USB3_0_DEVICE_NON_USB3_0_PORT": 0x0000011E, "PICO_NOT_SUPPORTED_BY_THIS_DEVICE": 0x0000011F, "PICO_INVALID_DEVICE_RESOLUTION": 0x00000120, "PICO_INVALID_NUMBER_CHANNELS_FOR_RESOLUTION": 0x00000121, "PICO_CHANNEL_DISABLED_DUE_TO_USB_POWERED": 0x00000122, "PICO_SIGGEN_DC_VOLTAGE_NOT_CONFIGURABLE": 0x00000123, "PICO_NO_TRIGGER_ENABLED_FOR_TRIGGER_IN_PRE_TRIG": 0x00000124, "PICO_TRIGGER_WITHIN_PRE_TRIG_NOT_ARMED": 0x00000125, "PICO_TRIGGER_WITHIN_PRE_NOT_ALLOWED_WITH_DELAY": 0x00000126, "PICO_TRIGGER_INDEX_UNAVAILABLE": 0x00000127, "PICO_AWG_CLOCK_FREQUENCY": 0x00000128, "PICO_TOO_MANY_CHANNELS_IN_USE": 0x00000129, "PICO_NULL_CONDITIONS": 0x0000012A, "PICO_DUPLICATE_CONDITION_SOURCE": 0x0000012B, "PICO_INVALID_CONDITION_INFO": 0x0000012C, "PICO_SETTINGS_READ_FAILED": 0x0000012D, "PICO_SETTINGS_WRITE_FAILED": 0x0000012E, "PICO_ARGUMENT_OUT_OF_RANGE": 0x0000012F, "PICO_HARDWARE_VERSION_NOT_SUPPORTED": 0x00000130, "PICO_DIGITAL_HARDWARE_VERSION_NOT_SUPPORTED": 0x00000131, "PICO_ANALOGUE_HARDWARE_VERSION_NOT_SUPPORTED": 0x00000132, "PICO_UNABLE_TO_CONVERT_TO_RESISTANCE": 0x00000133, "PICO_DUPLICATED_CHANNEL": 0x00000134, "PICO_INVALID_RESISTANCE_CONVERSION": 0x00000135, "PICO_INVALID_VALUE_IN_MAX_BUFFER": 0x00000136, "PICO_INVALID_VALUE_IN_MIN_BUFFER": 0x00000137, "PICO_SIGGEN_FREQUENCY_OUT_OF_RANGE": 0x00000138, "PICO_EEPROM2_CORRUPT": 0x00000139, "PICO_EEPROM2_FAIL": 0x0000013A, "PICO_SERIAL_BUFFER_TOO_SMALL": 0x0000013B, "PICO_SIGGEN_TRIGGER_AND_EXTERNAL_CLOCK_CLASH": 0x0000013C, "PICO_WARNING_SIGGEN_AUXIO_TRIGGER_DISABLED": 0x0000013D, "PICO_SIGGEN_GATING_AUXIO_NOT_AVAILABLE": 0x00000013E, "PICO_SIGGEN_GATING_AUXIO_ENABLED": 0x00000013F, "PICO_RESOURCE_ERROR": 0x00000140, "PICO_TEMPERATURE_TYPE_INVALID": 0x00000141, "PICO_TEMPERATURE_TYPE_NOT_SUPPORTED": 0x00000142, "PICO_TIMEOUT": 0x00000143, "PICO_DEVICE_NOT_FUNCTIONING": 0x00000144, "PICO_INTERNAL_ERROR": 0x00000145, "PICO_MULTIPLE_DEVICES_FOUND": 0x00000146, "PICO_WARNING_NUMBER_OF_SEGMENTS_REDUCED": 0x00000147, "PICO_CAL_PINS_STATES": 0x00000148, "PICO_CAL_PINS_FREQUENCY": 0x00000149, "PICO_CAL_PINS_AMPLITUDE": 0x0000014A, "PICO_CAL_PINS_WAVETYPE": 0x0000014B, "PICO_CAL_PINS_OFFSET": 0x0000014C, "PICO_PROBE_FAULT": 0x0000014D, "PICO_PROBE_IDENTITY_UNKNOWN": 0x0000014E, "PICO_PROBE_POWER_DC_POWER_SUPPLE_REQUIRED": 0x0000014F, "PICO_PROBE_NOT_POWERED_THROUGH_DC_POWER_SUPPLY": 0x00000150, "PICO_PROBE_CONFIG_FAILURE": 0x00000151, "PICO_PROBE_INTERACTION_CALLBACK": 0x00000152, "PICO_UNKNOWN_INTELLIGENT_PROBE": 0x00000153, "PICO_INTELLIGENT_PROBE_CORRUPT": 0x00000154, "PICO_PROBE_COLLECTION_NOT_STARTED": 0x00000155, "PICO_PROBE_POWER_CONSUMPTION_EXCEEDED": 0x00000156, "PICO_WARNING_PROBE_CHANNEL_OUT_OF_SYNC": 0x00000157, "PICO_ENDPOINT_MISSING": 0x00000158, "PICO_UNKNOWN_ENDPOINT_REQUEST": 0x00000159, "PICO_ADC_TYPE_ERROR": 0x0000015A, "PICO_FPGA2_FAILED": 0x0000015B, "PICO_FPGA2_DEVICE_STATUS": 0x0000015C, "PICO_ENABLED_PROGRAM_FPGA2_FAILED": 0x0000015D, "PICO_NO_CANNELS_OR_PORTS_ENABLED": 0x0000015E, "PICO_INVALID_RATIO_MODE": 0x0000015F, "PICO_READS_NOT_SUPPORTED_IN_CURRENT_CAPTURE_MODE": 0x00000160, "PICO_TRIGGER_READ_SELECTION_CHECK_FAILED": 0x00000161, "PICO_DATA_READ1_SELECTION_CHECK_FAILED": 0x00000162, "PICO_DATA_READ2_SELECTION_CHECK_FAILED": 0x00000164, "PICO_DATA_READ3_SELECTION_CHECK_FAILED": 0x00000168, "PICO_READ_SELECTION_OUT_OF_RANGE": 0x00000170, "PICO_MULTIPLE_RATIO_MODES": 0x00000171, "PICO_NO_SAMPLES_READ": 0x00000172, "PICO_RATIO_MODE_NOT_REQUESTED": 0x00000173, "PICO_NO_USER_READ_REQUESTS": 0x00000174, "PICO_ZERO_SAMPLES_INVALID": 0x00000175, "PICO_ANALOGUE_HARDWARE_MISSING": 0x00000176, "PICO_ANALOGUE_HARDWARE_PINS": 0x00000177, "PICO_ANALOGUE_SMPS_FAULT": 0x00000178, "PICO_DIGITAL_ANALOGUE_HARDWARE_CONFLICT": 0x00000179, "PICO_RATIO_MODE_BUFFER_NOT_SET": 0x0000017A, "PICO_RESOLUTION_NOT_SUPPORTED_BY_VARIENT": 0x0000017B, "PICO_THRESHOLD_OUT_OF_RANGE": 0x0000017C, "PICO_INVALID_SIMPLE_TRIGGER_DIRECTION": 0x0000017D, "PICO_AUX_NOT_SUPPORTED": 0x0000017E, "PICO_NULL_DIRECTIONS": 0x0000017F, "PICO_NULL_CHANNEL_PROPERTIES": 0x00000180, "PICO_TRIGGER_CHANNEL_NOT_ENABLED": 0x00000181, "PICO_CONDITION_HAS_NO_TRIGGER_PROPERTY": 0x00000182, "PICO_RATIO_MODE_TRIGGER_MASKING_INVALID": 0x00000183, "PICO_TRIGGER_DATA_REQUIRES_MIN_BUFFER_SIZE_OF_40_SAMPLES": 0x00000184, "PICO_NO_OF_CAPTURES_OUT_OF_RANGE": 0x00000185, "PICO_RATIO_MODE_SEGMENT_HEADER_DOES_NOT_REQUIRE_BUFFERS": 0x00000186, "PICO_FOR_SEGMENT_HEADER_USE_GETTRIGGERINFO": 0x00000187, "PICO_READ_NOT_SET": 0x00000188, "PICO_ADC_SETTING_MISMATCH": 0x00000189, "PICO_DATATYPE_INVALID": 0x0000018A, "PICO_RATIO_MODE_DOES_NOT_SUPPORT_DATATYPE": 0x0000018B, "PICO_CHANNEL_COMBINATION_NOT_VALID_IN_THIS_RESOLUTION": 0x0000018C, "PICO_USE_8BIT_RESOLUTION": 0x0000018D, "PICO_AGGREGATE_BUFFERS_SAME_POINTER": 0x0000018E, "PICO_OVERLAPPED_READ_VALUES_OUT_OF_RANGE": 0x0000018F, "PICO_OVERLAPPED_READ_SEGMENTS_OUT_OF_RANGE": 0x00000190, "PICO_CHANNELFLAGSCOMBINATIONS_ARRAY_SIZE_TOO_SMALL": 0x00000191, "PICO_CAPTURES_EXCEEDS_NO_OF_SUPPORTED_SEGMENTS": 0x00000192, "PICO_TIME_UNITS_OUT_OF_RANGE": 0x00000193, "PICO_NO_SAMPLES_REQUESTED": 0x00000194, "PICO_INVALID_ACTION": 0x00000195, "PICO_NO_OF_SAMPLES_NEED_TO_BE_EQUAL_WHEN_ADDING_BUFFERS": 0x00000196, "PICO_WAITING_FOR_DATA_BUFFERS": 0x00000197, "PICO_STREAMING_ONLY_SUPPORTS_ONE_READ": 0x00000198, "PICO_CLEAR_DATA_BUFFER_INVALID": 0x00000199, "PICO_INVALID_ACTION_FLAGS_COMBINATION": 0x0000019A, "PICO_PICO_MOTH_MIN_AND_MAX_NULL_BUFFERS_CANNOT_BE_ADDED": 0x0000019B, "PICO_CONFLICT_IN_SET_DATA_BUFFERS_CALL_REMOVE_DATA_BUFFER_TO_RESET": 0x0000019C, "PICO_REMOVING_DATA_BUFFER_ENTRIES_NOT_ALLOWED_WHILE_DATA_PROCESSING": 0x0000019D, "PICO_CYUSB_REQUEST_FAILED": 0x00000200, "PICO_STREAMING_DATA_REQUIRED": 0x00000201, "PICO_INVALID_NUMBER_OF_SAMPLES": 0x00000202, "PICO_INALID_DISTRIBUTION": 0x00000203, "PICO_BUFFER_LENGTH_GREATER_THAN_INT32_T": 0x00000204, "PICO_PLL_MUX_OUT_FAILED": 0x00000209, "PICO_ONE_PULSE_WIDTH_DIRECTION_ALLOWED": 0x0000020A, "PICO_EXTERNAL_TRIGGER_NOT_SUPPORTED": 0x0000020B, "PICO_NO_TRIGGER_CONDITIONS_SET": 0x0000020C, "PICO_NO_OF_CHANNEL_TRIGGER_PROPERTIES_OUT_OF_RANGE": 0x0000020D, "PICO_PROBE_COMPNENT_ERROR": 0x0000020E, "PICO_INVALID_TRIGGER_CHANNELS_FOR_ETS": 0x00000210, "PICO_NOT_AVALIABLE_WHEN_STREAMING_IS_RUNNING": 0x00000211, "PICO_INVALID_TRIGGER_WITHIN_PRE_TRIGGER_STATE": 0x00000212, "PICO_ZERO_NUMBER_OF_CAPTURES_INVALID": 0x00000213, "PICO_TRIGGER_DELAY_OUT_OF_RANGE": 0x00000300, "PICO_INVALID_THRESHOLD_DIRECTION": 0x00000301, "PICO_INVALID_THRESGOLD_MODE": 0x00000302, "PICO_DEVICE_TIME_STAMP_RESET": 0x01000000, "PICO_WATCHDOGTIMER": 0x10000000, "PICO_IPP_NOT_FOUND": 0x10000001, "PICO_IPP_NO_FUNCTION": 0x10000002, "PICO_IPP_ERROR": 0x10000003, "PICO_SHADOW_CAL_NOT_AVAILABLE": 0x10000004, "PICO_SHADOW_CAL_DISABLED": 0x10000005, "PICO_SHADOW_CAL_ERROR": 0x10000006, "PICO_SHADOW_CAL_CORRUPT": 0x10000007, } PICO_STATUS_LOOKUP = {v: k for k, v in PICO_STATUS.items()} PICO_INFO = { "PICO_DRIVER_VERSION": 0x00000000, "PICO_USB_VERSION": 0x00000001, "PICO_HARDWARE_VERSION": 0x00000002, "PICO_VARIANT_INFO": 0x00000003, "PICO_BATCH_AND_SERIAL": 0x00000004, "PICO_CAL_DATE": 0x00000005, "PICO_KERNEL_VERSION": 0x00000006, "PICO_DIGITAL_HARDWARE_VERSION": 0x00000007, "PICO_ANALOGUE_HARDWARE_VERSION": 0x00000008, "PICO_FIRMWARE_VERSION_1": 0x00000009, "PICO_FIRMWARE_VERSION_2": 0x0000000A, "PICO_MAC_ADDRESS": 0x0000000B, "PICO_SHADOW_CAL": 0x0000000C, "PICO_IPP_VERSION": 0x0000000D, } ================================================ FILE: picosdk/ctypes_wrapper.py ================================================ # coding=utf-8 # # Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms. # import ctypes import sys if sys.platform == 'win32': C_CALLBACK_FUNCTION_FACTORY = ctypes.WINFUNCTYPE else: C_CALLBACK_FUNCTION_FACTORY = ctypes.CFUNCTYPE ================================================ FILE: picosdk/device.py ================================================ # coding=utf-8 # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Definition of the Device class, which provides access to SDK functions which require a device handle, including capturing data and configuring the AWG. """ from __future__ import print_function import collections import numpy import math import time from picosdk.errors import DeviceCannotSegmentMemoryError, InvalidTimebaseError, ClosedDeviceError, \ NoChannelsEnabledError, NoValidTimebaseForOptionsError def requires_open(error_message="This operation requires a device to be connected."): def check_open_decorator(method): def check_open_impl(self, *args, **kwargs): if not self.is_open: raise ClosedDeviceError(error_message) return method(self, *args, **kwargs) return check_open_impl return check_open_decorator """ChannelConfig: A type for specifying channel setup for capture (pass into Device.set_channel, or Device.capture_*) name = The channel name as a string (e.g. 'A'.) enabled = bool indicating whether the channel should be enabled or disabled. coupling (optional) = 'AC' or 'DC', default is 'DC'. range_peak (optional) = +/- max volts, the highest precision range which includes your value will be selected. analog_offset (optional) = the meaning of 0 for this channel.""" ChannelConfig = collections.namedtuple('ChannelConfig', ['name', 'enabled', 'coupling', 'range_peak', 'analog_offset']) ChannelConfig.__new__.__defaults__ = (None, None, None) """TimebaseOptions: A type for specifying timebase constraints (pass to Device.find_timebase or Device.capture_*) All are optional. Please specify the options which matter to you: - the maximum time interval (if you want the fastest/most precise timebase you can get), - the number of samples in one buffer, - the minimum total collection time (if you want at least x.y seconds of uninterrupted capture data) - the oversample (if you want to sacrifice time precision for amplitude precision - see the programming guides.)""" TimebaseOptions = collections.namedtuple('TimebaseOptions', ['max_time_interval', 'no_of_samples', 'min_collection_time', 'oversample']) _TIMEBASE_OPTIONS_DEFAULTS = (None, None, None, 1) TimebaseOptions.__new__.__defaults__ = _TIMEBASE_OPTIONS_DEFAULTS class Device(object): """This object caches some information about the device state which cannot be queried from the driver. Please don't mix and match calls to this object with calls directly to the driver (or the ctypes wrapper), as this may cause unwanted behaviour (e.g. throwing an exception because no channels are enabled, when you enabled them yourself on the driver object.)""" def __init__(self, driver, handle): self.driver = driver self.handle = handle self.is_open = handle > 0 # if a channel is missing from here, it is disabled (or in an undefined state). self._channel_ranges = {} self._channel_offsets = {} @requires_open("The device either did not initialise correctly or has already been closed.") def close(self): self.driver.close_unit(self) self.handle = None self.is_open = False @property @requires_open() def info(self): return self.driver.get_unit_info(self) def __enter__(self): return self def __exit__(self, *args): self.close() if all(i is None for i in args): return True return False @requires_open() def set_channel(self, channel_config): name = channel_config.name if not channel_config.enabled: self.driver.set_channel(self, channel_name=name, enabled=channel_config.enabled) try: del self._channel_ranges[name] del self._channel_offsets[name] except KeyError: pass return # if enabled, we pass through the values from the channel config: self._channel_ranges[name] = self.driver.set_channel(self, channel_name=name, enabled=channel_config.enabled, coupling=channel_config.coupling, range_peak=channel_config.range_peak, analog_offset=channel_config.analog_offset) self._channel_offsets[name] = channel_config.analog_offset return self._channel_ranges[name] @requires_open() def set_channels(self, *channel_configs): """ set_channels(self, *channel_configs) An alternative to calling set_channel for each one, you can call this method with some channel configs. This method will also disable any missing channels from the passed configs, and disable ALL channels if the collection is empty. """ # Add channels which are missing as "disabled". if len(channel_configs) < len(self.driver.PICO_CHANNEL): channel_configs = list(channel_configs) present_channels = set(c.name for c in channel_configs) missing_channels = [cn for cn in self.driver.PICO_CHANNEL.keys() if cn not in present_channels] for channel_name in missing_channels: channel_configs.append(ChannelConfig(channel_name, False)) for channel_config in channel_configs: self.set_channel(channel_config) def _timebase_options_are_impossible(self, options): device_max_samples_possible = self.driver.MAX_MEMORY if options.no_of_samples is not None: if options.no_of_samples > device_max_samples_possible: return True elif options.max_time_interval is not None and options.min_collection_time is not None: effective_min_no_samples = math.ceil(options.min_collection_time / options.max_time_interval) if effective_min_no_samples > device_max_samples_possible: return True if None not in (options.no_of_samples, options.max_time_interval, options.min_collection_time): # if all 3 are requested, the result can be impossible. effective_min_no_samples = int(math.ceil(options.min_collection_time / options.max_time_interval)) if effective_min_no_samples > options.no_of_samples: return True # Is it still possible that this device cannot handle this request, but we don't know without making calls to # get_timebase. return False @staticmethod def _validate_timebase(timebase_options, timebase_info): """validate whether a timebase result matches the options requested.""" if timebase_options.max_time_interval is not None: if timebase_info.time_interval > timebase_options.max_time_interval: return False if timebase_options.no_of_samples is not None: if timebase_options.no_of_samples > timebase_info.max_samples: return False if timebase_options.min_collection_time is not None: if timebase_options.min_collection_time > timebase_info.max_samples * timebase_info.time_interval: return False return True @requires_open() def find_timebase(self, timebase_options): timebase_id = 0 # quickly validate that the request is not impossible. if self._timebase_options_are_impossible(timebase_options): raise NoValidTimebaseForOptionsError() # TODO binary search? last_error = None found_one_good = False while True: try: timebase_info = self.driver.get_timebase(self, timebase_id, 0, timebase_options.oversample) found_one_good = True if self._validate_timebase(timebase_options, timebase_info): return timebase_info except InvalidTimebaseError as e: if found_one_good: # we won't find a valid timebase. last_error = e break timebase_id += 1 args = () if last_error is not None: args = (last_error.args[0],) raise NoValidTimebaseForOptionsError(*args) @requires_open() def capture_block(self, timebase_options, channel_configs=()): """device.capture_block(timebase_options, channel_configs) timebase_options: TimebaseOptions object, specifying at least 1 constraint, and optionally oversample. channel_configs: a collection of ChannelConfig objects. If present, will be passed to set_channels. """ # set_channel: if channel_configs: self.set_channels(*channel_configs) if len(self._channel_ranges) == 0: raise NoChannelsEnabledError("We cannot capture any data if no channels are enabled.") # memory_segments: USE_SEGMENT_ID=0 try: # always force the number of memory segments on the device to 1 before computing timebases for a one-off # block capture. max_samples_possible = self.driver.memory_segments(self, USE_SEGMENT_ID+1) if timebase_options.no_of_samples is not None and timebase_options.no_of_samples > max_samples_possible.value: raise NoValidTimebaseForOptionsError() except DeviceCannotSegmentMemoryError: pass # get_timebase timebase_info = self.find_timebase(timebase_options) post_trigger_samples = timebase_options.no_of_samples pre_trigger_samples = 0 if post_trigger_samples is None: post_trigger_samples = int(math.ceil(timebase_options.min_collection_time / timebase_info.time_interval)) self.driver.set_null_trigger(self) # tell the device to capture something: approx_time_busy = self.driver.run_block(self, pre_trigger_samples, post_trigger_samples, timebase_info.timebase_id, timebase_options.oversample, USE_SEGMENT_ID) is_ready = self.driver.is_ready(self) while not is_ready: time.sleep(approx_time_busy / 5) is_ready = self.driver.is_ready(self) raw_data, overflow_warnings = self.driver.get_values(self, self._channel_ranges.keys(), post_trigger_samples, USE_SEGMENT_ID) self.driver.stop(self) times = numpy.linspace(0., post_trigger_samples * timebase_info.time_interval, post_trigger_samples, dtype=numpy.dtype('float32')) voltages = {} max_adc = self.driver.maximum_value(self) for channel, raw_array in raw_data.items(): array = raw_array.astype(numpy.dtype('float32'), casting='safe') factor = self._channel_ranges[channel] / max_adc array = array * factor voltages[channel] = array return times, voltages, overflow_warnings ================================================ FILE: picosdk/discover.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # from picosdk.errors import DeviceNotFoundError from picosdk.ps2000 import ps2000 from picosdk.ps2000a import ps2000a from picosdk.ps3000 import ps3000 from picosdk.ps3000a import ps3000a from picosdk.ps4000 import ps4000 from picosdk.ps4000a import ps4000a from picosdk.ps5000a import ps5000a from picosdk.ps6000 import ps6000 from picosdk.ps6000a import ps6000a # the A drivers are faster to enumerate devices, so search them first. drivers = [ ps2000a, ps3000a, ps4000a, ps5000a, ps6000a, ps6000, ps2000, ps3000, ps4000, ] def find_unit(): """Search for, open and return the first device connected, on any driver.""" for driver in drivers: try: device = driver.open_unit() except DeviceNotFoundError: continue return device raise DeviceNotFoundError("Could not find any devices on any drivers.") def find_all_units(): """Search for, open and return ALL devices on ALL pico drivers (supported in this SDK wrapper).""" devices = [] for driver in drivers: try: device = driver.open_unit() except DeviceNotFoundError: continue devices.append(device) if not devices: raise DeviceNotFoundError("Could not find any devices on any drivers.") return devices ================================================ FILE: picosdk/errors.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # class PicoError(Exception): """All errors thrown explicitly by this package will be PicoError's.""" pass class FeatureNotSupportedError(PicoError): """raised when a feature is not supported on the connected device.""" pass class CannotFindPicoSDKError(PicoError, IOError): pass class CannotOpenPicoSDKError(PicoError, IOError): pass class DeviceNotFoundError(PicoError, IOError): pass class ArgumentOutOfRangeError(PicoError, ValueError): pass class ValidRangeEnumValueNotValidForThisDevice(FeatureNotSupportedError, ValueError): pass class DeviceCannotSegmentMemoryError(FeatureNotSupportedError, TypeError): pass class InvalidMemorySegmentsError(PicoError, ValueError): pass class InvalidTimebaseError(PicoError, ValueError): pass class InvalidTriggerParameters(PicoError, ValueError): pass class InvalidCaptureParameters(PicoError, ValueError): pass class PicoSDKCtypesError(PicoError, IOError): pass class ClosedDeviceError(PicoError, IOError): pass class NoChannelsEnabledError(PicoError, ValueError): pass class NoValidTimebaseForOptionsError(PicoError, ValueError): pass class UnknownConstantError(PicoError, TypeError): pass ================================================ FILE: picosdk/functions.py ================================================ # # Copyright (C) 2018-2024 Pico Technology Ltd. See LICENSE file for terms. # from __future__ import division import numpy as np from picosdk.constants import PICO_STATUS, PICO_STATUS_LOOKUP from picosdk.errors import PicoSDKCtypesError def adc2mV(bufferADC, range, maxADC): """ adc2mc( c_short_Array bufferADC int range c_int32 maxADC ) Takes a buffer of raw adc count values and converts it into millivolts """ channelInputRanges = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000] vRange = channelInputRanges[range] bufferV = [(np.int64(x) * vRange) / maxADC.value for x in bufferADC] return bufferV def adc2mVpl1000(bufferADC, range, maxADC): """ adc2mVpl1000( c_short_Array bufferADC, int range, c_int32 maxADC ) Takes a buffer of raw adc count values and converts it into millvolts """ bufferV = [(x * range) / maxADC.value for x in bufferADC] return bufferV def mV2adc(millivolts, range, maxADC): """ mV2adc( float millivolts int range c_int32 maxADC ) Takes a voltage value and converts it into adc counts """ channelInputRanges = [10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000] vRange = channelInputRanges[range] adcValue = round((millivolts * maxADC.value)/vRange) return adcValue def mV2adcpl1000(millivolts, range, maxADC): """ mV2adc( float millivolts, int range, c_int32 maxADC ) Takes a voltage value and converts it to adc counts """ adcValue = round((millivolts * maxADC.value)/range) return adcValue def splitMSOData(dataLength, data): """ This method converts an array of values for a ditial port into the binary equivalent, splitting the bits by digital channel. Returns a set of 8 variables, each of which corresponds to the binary data values over time of the different digital channels from the lowest significant bit to the most significant bit. For PORT0 this will be in the order (D0, D1, D2, ... D7) and for PORT1 this will be (D8, D9, D10, ... D15). splitMSOData( c_int32 dataLength c_int16 array data ) """ # Makes an array for each digital channel binaryBufferD0 = np.chararray((dataLength.value, 1)) binaryBufferD1 = np.chararray((dataLength.value, 1)) binaryBufferD2 = np.chararray((dataLength.value, 1)) binaryBufferD3 = np.chararray((dataLength.value, 1)) binaryBufferD4 = np.chararray((dataLength.value, 1)) binaryBufferD7 = np.chararray((dataLength.value, 1)) binaryBufferD5 = np.chararray((dataLength.value, 1)) binaryBufferD6 = np.chararray((dataLength.value, 1)) # Changes the data from int type to a binary type and then separates the data for each digital channel for i in range(0, dataLength.value): MSOData = data[i] binaryMSOData = bin(MSOData) binaryMSOData = binaryMSOData[2:] binaryMSOData = binaryMSOData.zfill(8) binaryBufferD0[i] = binaryMSOData[7] binaryBufferD1[i] = binaryMSOData[6] binaryBufferD2[i] = binaryMSOData[5] binaryBufferD3[i] = binaryMSOData[4] binaryBufferD4[i] = binaryMSOData[3] binaryBufferD5[i] = binaryMSOData[2] binaryBufferD6[i] = binaryMSOData[1] binaryBufferD7[i] = binaryMSOData[0] return binaryBufferD0, \ binaryBufferD1, \ binaryBufferD2, \ binaryBufferD3, \ binaryBufferD4, \ binaryBufferD5, \ binaryBufferD6, \ binaryBufferD7 def splitMSODataFast(dataLength, data): """ # This implementation will work on either channel in the same way as the splitMSOData method above, albeit in a more efficient manner. Returns a tuple of 8 arrays, each of which is the values over time of a different digital channel. The tuple contains the channels in order (D7, D6, D5, ... D0) or equivalently (D15, D14, D13, ... D8). splitMSODataFast( c_int32 dataLength c_int16 array data ) """ # Makes an array for each digital channel bufferBinaryDj = ( np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), ) # Splits out the individual bits from the port into the binary values for each digital channel/pin. for i in range(dataLength.value): for j in range(8): bufferBinaryDj[j][i] = 1 if (data[i] & (1 << (7-j))) else 0 return bufferBinaryDj def assert_pico_ok(status): """ assert_pico_ok( status ) """ # checks for PICO_OK status return if status != PICO_STATUS['PICO_OK']: raise PicoSDKCtypesError("PicoSDK returned '{}'".format(PICO_STATUS_LOOKUP[status])) def assert_pico2000_ok(status): """ assert_pico_ok( status ) """ # checks for PICO_OK status return if status > 0: errorCheck = True else: errorCheck = False raise PicoSDKCtypesError("Unsuccessful API call") def mV2adcV2(millivolts, rangeMax, maxADC): """ mV2adcV2( float millivolts int rangeMax c_int32 maxADC ) Takes a voltage value and converts it into adc counts for psospa driver scopes """ adcValue = round((millivolts * maxADC.value)/(rangeMax/1000000)) return adcValue def adc2mVV2(bufferADC, rangeMax, maxADC): """ adc2mVV2( c_short_Array bufferADC int rangeMax c_int32 maxADC ) Takes a buffer of raw adc count values and converts it into millivolts for psospa driver scopes """ buffermV = [(x * (rangeMax/1000000)) / maxADC.value for x in bufferADC] return buffermV ================================================ FILE: picosdk/functionsExhibitions.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # import numpy as np import openpyxl from math import floor, log2, log10 import shutil import os import toml def dataImporter(name): workbook = openpyxl.load_workbook(name, data_only = True) sheet = workbook['filterParameters'] noOfChannels = sheet.cell(row = 2, column = 1).value bits = sheet.cell(row = 2, column = 2).value samplingRate = sheet.cell(row = 2, column = 3).value sampleLength = sheet.cell(row = 2, column = 4).value return noOfChannels, bits, samplingRate, sampleLength def ps6000aTimebase(samplingRate): sampleInterval = (1/samplingRate)/1000000 #s breakPoint = 6.4/1000000000 if sampleInterval >= breakPoint: timebase = floor((sampleInterval * 156250000)+5) else: timebase = floor(log2(sampleInterval * 5000000000)) return timebase def ps5000aTimebase(samplingRate): sampleInterval = (1/samplingRate)/1000000 #s breakPoint = 8/1000000000 if sampleInterval >= breakPoint: timebase = floor((sampleInterval * 125000000)+2) else: timebase = floor(log2(sampleInterval * 1000000000)) return timebase def ps3000aTimebase(samplingRate): sampleInterval = (1/samplingRate)/1000000 #s breakPoint = 8/1000000000 if sampleInterval >= breakPoint: timebase = floor((sampleInterval * 125000000)+2) else: timebase = floor(log2(sampleInterval * 1000000000)) return timebase def ps4000aTimebase(samplingRate): timebase = floor((80/samplingRate)-1) return timebase def ps2000aTimebase(samplingRate): sampleInterval = (1/samplingRate)/1000000 #s breakPoint = 4/1000000000 if sampleInterval>= breakPoint: timebase = floor((sampleInterval*125000000)+2) else: timebase = floor(log2(sampleInterval * 1000000000)) return timebase def ps2000Timebase(sampleRate): #assumes sample rate is in Hz #assumes sample interval in s sampleInterval = (1/sampleRate) timebase = floor(log10(sampleInterval*1000000000)) return timebase def BitEnumSelector(bits): if bits <= 8: enum = 0 elif bits <= 10: enum = 10 else: enum = 1 return enum def saveConfigFile(channels, bits, sampleRate,captureLength, segments): # configValues = [channels, bits, sampleRate, captureLength, segments] data = { "Active Channels" : int(channels), "Scope Bit Resolution" : int(bits), "Sampling Rate (MHz)" : float(sampleRate), "Capture Length (Samples)" : int(captureLength), "Number of Capture Segments for Rapid Block" : int(segments), } # # Save the list to a text file with open('configValues.toml', 'w') as file: toml.dump(data,file) return def loadConfigValues(): with open('configValues.toml', 'r') as file: restored_configValues = toml.load(file) channels = int(restored_configValues["Active Channels"]) bits = int(restored_configValues["Scope Bit Resolution"]) sampleRate = float(restored_configValues["Sampling Rate (MHz)"]) captureLength = int(float(restored_configValues["Capture Length (Samples)"])) segments = int(restored_configValues["Number of Capture Segments for Rapid Block"]) return channels, bits, sampleRate, captureLength, segments def copyFile(source_directory, filename): destination_directory = 'D:/' # Define the destination file path source_file = os.path.join(source_directory, filename) destination_file = os.path.join(destination_directory, filename) # Copy the file to the new location shutil.copy(source_file, destination_file) return ================================================ FILE: picosdk/library.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Definition of the Library class, which is the abstract representation of a picotech device driver. Note: Many of the functions in this class are missing: these are populated by the psN000(a).py modules, which subclass this type and attach the missing methods. """ from __future__ import print_function import sys from ctypes import c_int16, c_int32, c_uint32, c_float, create_string_buffer, byref from ctypes.util import find_library import collections import picosdk.constants as constants import numpy from picosdk.errors import CannotFindPicoSDKError, CannotOpenPicoSDKError, DeviceNotFoundError, \ ArgumentOutOfRangeError, ValidRangeEnumValueNotValidForThisDevice, DeviceCannotSegmentMemoryError, \ InvalidMemorySegmentsError, InvalidTimebaseError, InvalidTriggerParameters, InvalidCaptureParameters from picosdk.device import Device """TimebaseInfo: A type for holding the particulars of a timebase configuration. """ TimebaseInfo = collections.namedtuple('TimebaseInfo', ['timebase_id', 'time_interval', 'time_units', 'max_samples', 'segment_id']) def requires_device(error_message="This method requires a Device instance registered to this Library instance."): def check_device_decorator(method): def check_device_impl(self, device, *args, **kwargs): if not isinstance(device, Device) or device.driver != self: raise TypeError(error_message) return method(self, device, *args, **kwargs) return check_device_impl return check_device_decorator class Library(object): def __init__(self, name): self.name = name self._clib = self._load() # ! some drivers will replace these dicts at import time, where they have different constants (notably ps2000). self.PICO_INFO = constants.PICO_INFO self.PICO_STATUS = constants.PICO_STATUS self.PICO_STATUS_LOOKUP = constants.PICO_STATUS_LOOKUP # these must be set in each driver file. self.PICO_CHANNEL = {} self.PICO_COUPLING = {} self.PICO_VOLTAGE_RANGE = {} # most series of scopes top out at 512MS. self.MAX_MEMORY = 2**29 # These are set in some driver files, but not all. self.PICO_RATIO_MODE = {} self.PICO_THRESHOLD_DIRECTION = {} def _load(self): library_path = find_library(self.name) # 'find_library' fails in Cygwin. if not sys.platform == 'cygwin': if library_path is None: env_var_name = "PATH" if sys.platform == 'win32' else "LD_LIBRARY_PATH" raise CannotFindPicoSDKError("PicoSDK (%s) not found, check %s" % (self.name, env_var_name)) try: if sys.platform == 'win32': from ctypes import WinDLL result = WinDLL(library_path) elif sys.platform == 'cygwin': from ctypes import CDLL library_path = self.name result = CDLL(library_path + ".dll") else: from ctypes import cdll result = cdll.LoadLibrary(library_path) except OSError as e: raise CannotOpenPicoSDKError("PicoSDK (%s) not compatible (check 32 vs 64-bit): %s" % (self.name, e)) return result def __str__(self): return "picosdk %s library" % self.name def make_symbol(self, python_name, c_name, return_type, argument_types, docstring=None): """Used by python wrappers for particular drivers to register C functions on the class.""" c_function = getattr(self._clib, c_name) c_function.restype = return_type c_function.argtypes = argument_types if docstring is not None: c_function.__doc__ = docstring # make the functions available under *both* their original and generic names setattr(self, python_name, c_function) setattr(self, c_name, c_function) # AND if the function is camel case, add an "underscore-ized" version: if python_name.lower() != python_name: acc = [] for c in python_name[1:]: # Be careful to exclude both digits (lower index) and lower case (higher index). if ord('A') <= ord(c) <= ord('Z'): c = "_" + c.lower() acc.append(c) if acc[:2] == ['_', '_']: acc = acc[1:] setattr(self, "".join(acc), c_function) def list_units(self): """Returns: a list of dictionaries which identify connected devices which use this driver.""" handles = [] device_infos = [] try: while True: handle = self._python_open_unit() device_infos.append(self._python_get_unit_info_wrapper(handle, [])) handles.append(handle) except DeviceNotFoundError: pass for handle in handles: self._python_close_unit(handle) return device_infos def open_unit(self, serial=None, resolution=None): """optional arguments: serial: If no serial number is provided, this function opens the first device discovered. resolution: for some devices, you may specify a resolution as you open the device. You should retrieve this numeric constant from the relevant driver module. returns: a Device instance, which has functions on it for collecting data and using the waveform generator (if present). Note: Either use this object in a context manager, or manually call .close() on it when you are finished.""" return Device(self, self._python_open_unit(serial=serial, resolution=resolution)) @requires_device("close_unit requires a picosdk.device.Device instance, passed to the correct owning driver.") def close_unit(self, device): self._python_close_unit(device.handle) @requires_device("get_unit_info requires a picosdk.device.Device instance, passed to the correct owning driver.") def get_unit_info(self, device, *args): return self._python_get_unit_info_wrapper(device.handle, args) def _python_open_unit(self, serial=None, resolution=None): if serial is None: handle, status = self._python_open_any_unit(resolution) else: handle, status = self._python_open_specific_unit(serial, resolution) if handle < 1: message = ("Driver %s could find no device" % self.name) + ("s" if serial is None else (" matching %s" % serial)) if status is not None: message += " (%s)" % constants.pico_tag(status) raise DeviceNotFoundError(message) return handle def _python_open_any_unit(self, resolution): status = None if len(self._open_unit.argtypes) == 3: if resolution is None: resolution = self.DEFAULT_RESOLUTION chandle = c_int16() cresolution = c_int32() cresolution.value = resolution status = self._open_unit(byref(chandle), None, cresolution) handle = chandle.value elif len(self._open_unit.argtypes) == 2: chandle = c_int16() status = self._open_unit(byref(chandle), None) handle = chandle.value else: handle = self._open_unit() return handle, status def _python_open_specific_unit(self, serial, resolution): handle = -1 status = None if len(self._open_unit.argtypes) == 3: if resolution is None: resolution = self.DEFAULT_RESOLUTION chandle = c_int16() cresolution = c_int32() cresolution.value = resolution cserial = create_string_buffer(serial) status = self._open_unit(byref(chandle), cserial, cresolution) handle = chandle.value elif len(self._open_unit.argtypes) == 2: chandle = c_int16() cserial = create_string_buffer(serial) status = self._open_unit(byref(chandle), cserial) handle = chandle.value else: open_handles = [] temp_handle = self._open_unit() while temp_handle > 0: this_serial = self._python_get_unit_info(temp_handle, self.PICO_INFO["PICO_BATCH_AND_SERIAL"]) if this_serial == serial: handle = temp_handle break open_handles.append(temp_handle) temp_handle = self._open_unit() for temp_handle in open_handles: self._python_close_unit(temp_handle) return handle, status def _python_close_unit(self, handle): return self._close_unit(c_int16(handle)) @staticmethod def _create_empty_string_buffer(): try: return create_string_buffer("\0", 255) except TypeError: return create_string_buffer("\0".encode('utf8'), 255) def _python_get_unit_info(self, handle, info_type): string_size = 255 info = self._create_empty_string_buffer() if len(self._get_unit_info.argtypes) == 4: info_len = self._get_unit_info(c_int16(handle), info, c_int16(string_size), c_int16(info_type)) if info_len > 0: return info.value[:info_len] elif len(self._get_unit_info.argtypes) == 5: required_size = c_int16(0) status = self._get_unit_info(c_int16(handle), info, c_int16(string_size), byref(required_size), c_uint32(info_type)) if status == self.PICO_STATUS['PICO_OK']: if required_size.value < string_size: return info.value[:required_size.value] return "" def _python_get_unit_info_wrapper(self, handle, keys): # verify that the requested keys are valid for this driver: invalid_info_lines = list(set(keys) - set(self.PICO_INFO.keys())) if invalid_info_lines: raise ArgumentOutOfRangeError("%s not available for %s devices" % (",".join(invalid_info_lines), self.name)) if not keys: # backwards compatible behaviour from first release of this wrapper, which works on all drivers. UnitInfo = collections.namedtuple('UnitInfo', ['driver', 'variant', 'serial']) return UnitInfo( driver=self, variant=self._python_get_unit_info(handle, self.PICO_INFO["PICO_VARIANT_INFO"]), serial=self._python_get_unit_info(handle, self.PICO_INFO["PICO_BATCH_AND_SERIAL"]) ) # make a new type here, with the relevant keys. UnitInfo = collections.namedtuple('UnitInfo', list(keys)) info_lines = {} for line in keys: info_lines[line] = self._python_get_unit_info(handle, self.PICO_INFO[line]) return UnitInfo(**info_lines) @requires_device("set_channel requires a picosdk.device.Device instance, passed to the correct owning driver.") def set_channel(self, device, channel_name='A', enabled=True, coupling='DC', range_peak=float('inf'), analog_offset=None): """optional arguments: channel_name: a single channel (e.g. 'A') enabled: whether to enable the channel (boolean) coupling: string of the relevant enum member for your driver less the driver name prefix. e.g. 'DC' or 'AC'. range_peak: float which is the largest value you expect in the input signal. We will throw an exception if no range on the device is large enough for that value. analog_offset: the meaning of 0 for this channel. return value: Max voltage of new range. Raises an exception in error cases.""" excluded = () reliably_resolved = False max_voltage = None while not reliably_resolved: if enabled: range_id, max_voltage = self._resolve_range(range_peak, excluded) else: range_id = 0 max_voltage = None try: self._python_set_channel(device.handle, self.PICO_CHANNEL[channel_name], 1 if enabled else 0, self.PICO_COUPLING[coupling], range_id, analog_offset) reliably_resolved = True except ValidRangeEnumValueNotValidForThisDevice: excluded += (range_id,) return max_voltage def _resolve_range(self, signal_peak, exclude=()): # we use >= so that someone can specify the range they want precisely. # we allow exclude so that if the smallest range in the header file isn't available on this device (or in this # configuration) we can exclude it from the collection. It should be the numerical enum constant (the key in # PICO_VOLTAGE_RANGE). possibilities = list(filter(lambda tup: tup[1] >= signal_peak and tup[0] not in exclude, self.PICO_VOLTAGE_RANGE.items())) if not possibilities: raise ArgumentOutOfRangeError("%s device doesn't support a range as wide as %sV" % (self.name, signal_peak)) return min(possibilities, key=lambda i: i[1]) def _python_set_channel(self, handle, channel_id, enabled, coupling_id, range_id, analog_offset): if len(self._set_channel.argtypes) == 5 and self._set_channel.argtypes[1] == c_int16: if analog_offset is not None: raise ArgumentOutOfRangeError("This device doesn't support analog offset") return_code = self._set_channel(c_int16(handle), c_int16(channel_id), c_int16(enabled), c_int16(coupling_id), c_int16(range_id)) if return_code == 0: raise ValidRangeEnumValueNotValidForThisDevice("%sV is out of range for this device." % ( self.PICO_VOLTAGE_RANGE[range_id])) elif len(self._set_channel.argtypes) == 5 and self._set_channel.argtypes[1] == c_int32 or ( len(self._set_channel.argtypes) == 6): status = self.PICO_STATUS['PICO_OK'] if len(self._set_channel.argtypes) == 6: if analog_offset is None: analog_offset = 0.0 status = self._set_channel(c_int16(handle), c_int32(channel_id), c_int16(enabled), c_int32(coupling_id), c_int32(range_id), c_float(analog_offset)) elif len(self._set_channel.argtypes) == 5 and self._set_channel.argtypes[1] == c_int32: if analog_offset is not None: raise ArgumentOutOfRangeError("This device doesn't support analog offset") status = self._set_channel(c_int16(handle), c_int32(channel_id), c_int16(enabled), c_int16(coupling_id), c_int32(range_id)) if status != self.PICO_STATUS['PICO_OK']: if status == self.PICO_STATUS['PICO_INVALID_VOLTAGE_RANGE']: raise ValidRangeEnumValueNotValidForThisDevice("%sV is out of range for this device." % ( self.PICO_VOLTAGE_RANGE[range_id])) if status == self.PICO_STATUS['PICO_INVALID_CHANNEL'] and not enabled: # don't throw errors if the user tried to disable a missing channel. return raise ArgumentOutOfRangeError("problem configuring channel (%s)" % constants.pico_tag(status)) else: raise NotImplementedError("not done other driver types yet") @requires_device("memory_segments requires a picosdk.device.Device instance, passed to the correct owning driver.") def memory_segments(self, device, number_segments): if not hasattr(self, '_memory_segments'): raise DeviceCannotSegmentMemoryError() max_samples = c_int32(0) status = self._memory_segments(c_int16(device.handle), c_uint32(number_segments), byref(max_samples)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidMemorySegmentsError("could not segment the device memory into (%s) segments (%s)" % ( number_segments, constants.pico_tag(status))) return max_samples @requires_device("get_timebase requires a picosdk.device.Device instance, passed to the correct owning driver.") def get_timebase(self, device, timebase_id, no_of_samples, oversample=1, segment_index=0): """query the device about what time precision modes it can handle. note: the driver returns the timebase in nanoseconds, this function converts that into SI units (seconds)""" nanoseconds_result = self._python_get_timebase(device.handle, timebase_id, no_of_samples, oversample, segment_index) return TimebaseInfo(nanoseconds_result.timebase_id, nanoseconds_result.time_interval * 1.e-9, nanoseconds_result.time_units, nanoseconds_result.max_samples, nanoseconds_result.segment_id) def _python_get_timebase(self, handle, timebase_id, no_of_samples, oversample, segment_index): # We use get_timebase on ps2000 and ps3000 and parse the nanoseconds-int into a float. # on other drivers, we use get_timebase2, which gives us a float in the first place. if len(self._get_timebase.argtypes) == 7 and self._get_timebase.argtypes[1] == c_int16: time_interval = c_int32(0) time_units = c_int16(0) max_samples = c_int32(0) return_code = self._get_timebase(c_int16(handle), c_int16(timebase_id), c_int32(no_of_samples), byref(time_interval), byref(time_units), c_int16(oversample), byref(max_samples)) if return_code == 0: raise InvalidTimebaseError() return TimebaseInfo(timebase_id, float(time_interval.value), time_units.value, max_samples.value, None) elif hasattr(self, '_get_timebase2') and ( len(self._get_timebase2.argtypes) == 7 and self._get_timebase2.argtypes[1] == c_uint32): time_interval = c_float(0.0) max_samples = c_int32(0) status = self._get_timebase2(c_int16(handle), c_uint32(timebase_id), c_int32(no_of_samples), byref(time_interval), c_int16(oversample), byref(max_samples), c_uint32(segment_index)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidTimebaseError("get_timebase2 failed (%s)" % constants.pico_tag(status)) return TimebaseInfo(timebase_id, time_interval.value, None, max_samples.value, segment_index) else: raise NotImplementedError("not done other driver types yet") @requires_device() def set_null_trigger(self, device): auto_trigger_after_millis = 1 if hasattr(self, '_set_trigger') and len(self._set_trigger.argtypes) == 6: PS2000_NONE = 5 return_code = self._set_trigger(c_int16(device.handle), c_int16(PS2000_NONE), c_int16(0), c_int16(0), c_int16(0), c_int16(auto_trigger_after_millis)) if return_code == 0: raise InvalidTriggerParameters() elif hasattr(self, '_set_simple_trigger') and len(self._set_simple_trigger.argtypes) == 7: enabled = False status = self._set_simple_trigger(c_int16(device.handle), c_int16(int(enabled)), c_int32(self.PICO_CHANNEL['A']), c_int16(0), c_int32(self.PICO_THRESHOLD_DIRECTION['NONE']), c_uint32(0), c_int16(auto_trigger_after_millis)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidTriggerParameters("set_simple_trigger failed (%s)" % constants.pico_tag(status)) else: raise NotImplementedError("not done other driver types yet") @requires_device() def run_block(self, device, pre_trigger_samples, post_trigger_samples, timebase_id, oversample=1, segment_index=0): """tell the device to arm any triggers and start capturing in block mode now. returns: the approximate time (in seconds) which the device will take to capture with these settings.""" return self._python_run_block(device.handle, pre_trigger_samples, post_trigger_samples, timebase_id, oversample, segment_index) def _python_run_block(self, handle, pre_samples, post_samples, timebase_id, oversample, segment_index): time_indisposed = c_int32(0) if len(self._run_block.argtypes) == 5: return_code = self._run_block(c_int16(handle), c_int32(pre_samples + post_samples), c_int16(timebase_id), c_int16(oversample), byref(time_indisposed)) if return_code == 0: raise InvalidCaptureParameters() elif len(self._run_block.argtypes) == 9: status = self._run_block(c_int16(handle), c_int32(pre_samples), c_int32(post_samples), c_uint32(timebase_id), c_int16(oversample), byref(time_indisposed), c_uint32(segment_index), None, None) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("run_block failed (%s)" % constants.pico_tag(status)) else: raise NotImplementedError("not done other driver types yet") return float(time_indisposed.value) * 0.001 @requires_device() def is_ready(self, device): """poll this function to find out when block mode is ready or has triggered. returns: True if data is ready, False otherwise.""" if hasattr(self, '_ready') and len(self._ready.argtypes) == 1: return_code = self._ready(c_int16(device.handle)) return bool(return_code) elif hasattr(self, '_is_ready') and len(self._is_ready.argtypes) == 2: is_ready = c_int16(0) status = self._is_ready(c_int16(device.handle), byref(is_ready)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("is_ready failed (%s)" % constants.pico_tag(status)) return bool(is_ready.value) else: raise NotImplementedError("not done other driver types yet") @requires_device() def maximum_value(self, device): if not hasattr(self, '_maximum_value'): return (2**15)-1 max_adc = c_int16(0) self._maximum_value(c_int16(device.handle), byref(max_adc)) return max_adc.value @requires_device() def get_values(self, device, active_channels, num_samples, segment_index=0): # Initialise buffers to hold the data: results = {channel: numpy.empty(num_samples, numpy.dtype('int16')) for channel in active_channels} overflow = c_int16(0) if len(self._get_values.argtypes) == 7 and self._get_timebase.argtypes[1] == c_int16: inputs = {k: None for k in 'ABCD'} for k, arr in results.items(): inputs[k] = arr.ctypes.data return_code = self._get_values(c_int16(device.handle), inputs['A'], inputs['B'], inputs['C'], inputs['D'], byref(overflow), c_int32(num_samples)) if return_code == 0: raise InvalidCaptureParameters() elif len(self._get_values.argtypes) == 7 and self._get_timebase.argtypes[1] == c_uint32: # For this function pattern, we first call a function (self._set_data_buffer) to register each buffer. Then, # we can call self._get_values to actually populate them. for channel, array in results.items(): status = self._set_data_buffer(c_int16(device.handle), c_int32(self.PICO_CHANNEL[channel]), array.ctypes.data, c_int32(num_samples), c_uint32(segment_index), c_int32(self.PICO_RATIO_MODE['NONE'])) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("set_data_buffer failed (%s)" % constants.pico_tag(status)) samples_collected = c_uint32(num_samples) status = self._get_values(c_int16(device.handle), c_uint32(0), byref(samples_collected), c_uint32(1), c_int32(self.PICO_RATIO_MODE['NONE']), c_uint32(segment_index), byref(overflow)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("get_values failed (%s)" % constants.pico_tag(status)) overflow_warning = {} if overflow.value: for channel in results.keys(): if overflow.value & (1 >> self.PICO_CHANNEL[channel]): overflow_warning[channel] = True return results, overflow_warning @requires_device() def stop(self, device): if self._stop.restype == c_int16: return_code = self._stop(c_int16(device.handle)) if isinstance(return_code, c_int16): if return_code == 0: raise InvalidCaptureParameters() else: status = self._stop(c_int16(device.handle)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("stop failed (%s)" % constants.pico_tag(status)) ================================================ FILE: picosdk/picoMeasurements.py ================================================ # # Copyright (C) 2025 Pico Technology Ltd. See LICENSE file for terms. # import numpy as np ================================================ FILE: picosdk/picohrdl.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the picohrdl.h C header file for ADC-20/24 Data Loggers using the picohrdl driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.errors import ArgumentOutOfRangeError from picosdk.constants import make_enum class picohrdllib(Library): def __init__(self): super(picohrdllib, self).__init__("picohrdl") picohrdl = picohrdllib() picohrdl.HRDL_VOLTAGERANGE = make_enum([ "HRDL_2500_MV", "HRDL_1250_MV", "HRDL_625_MV", "HRDL_313_MV", "HRDL_156_MV", "HRDL_78_MV", "HRDL_39_MV", ]) picohrdl.HRDL_CONVERSIONTIME = make_enum([ "HRDL_60MS", "HRDL_100MS", "HRDL_180MS", "HRDL_340MS", "HRDL_660MS", ]) doc = """ int16_t HRDLCloseUnit ( int16_t handle ); """ picohrdl.make_symbol("_closeUnit_", "HRDLCloseUnit", c_int16, [c_int16], doc) doc = """ int16_t HRDLCollectSingleValueAsync ( int16_t handle, int16_t channel, int16_t range, int16_t conversionTime, int16_t singleEnded ); """ picohrdl.make_symbol("_collectSingleValue_Async_", "HRDLCollectSingleValueAsync", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t HRDLGetMinMaxAdcCounts ( int16_t handle, int32_t *minAdc, int32_t *maxAdc, int16_t channel ); """ picohrdl.make_symbol("_getMinMaxAdcCounts_", "HRDLGetMinMaxAdcCounts", c_int16, [c_int16, c_void_p, c_void_p, c_int16], doc) doc = """ int16_t HRDLGetNumberOfEnabledChannels ( int16_t handle, int16_t *nEnabledChannels ); """ picohrdl.make_symbol("_getNumberOfEnabledChannels_", "HRDLGetNumberOfEnabledChannels", c_int16, [c_int16, c_void_p], doc) doc = """ int16_t HRDLGetSingleValue ( int16_t handle, int16_t channel, int16_t range, int16_t conversionTime, int16_t singleEnded, int16_t *overflow, int32_t *value ); """ picohrdl.make_symbol("_getSingleValue_", "HRDLGetSingleValue", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16, c_void_p, c_void_p], doc) doc = """ int16_t HRDLGetSingleValueAsync ( int16_t handle, int32_t *value, int16_t *overflow ); """ picohrdl.make_symbol("_getSingleValueAsync_", "HRDLGetSingleValueAsync", c_int16, [c_int16, c_void_p, c_void_p], doc) doc = """ int32_t HRDLGetTimesAndVAlues ( int16_t handle, int32_t *times, int32_t *values, int16_t *overflow, int32_t noOfValues ); """ picohrdl.make_symbol("_getTimesAndValues_", "HRDLGetTimesAndValues", c_int16, [c_int16, c_void_p, c_void_p, c_void_p, c_int32], doc) doc = """ int16_t HRDLGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t info ); """ picohrdl.make_symbol("_getUnitInfo_", "HRDLGetUnitInfo", c_int16, [c_int16, c_void_p, c_int16, c_int16], doc) doc = """ int32_t HRDLGetValues ( int16_t handle, int32_t *values, int16_t *overflow, int32_t noOfValues ); """ picohrdl.make_symbol("_getValues_", "HRDLGetValues", c_int16, [c_int16, c_void_p, c_void_p, c_int32], doc) doc = """ int16_t HRDLOpenUnit ( void ); """ picohrdl.make_symbol("_openUnit_", "HRDLOpenUnit", c_int16, [], doc) doc = """ int16_t HRDLOpenUnitAsync ( void ); """ picohrdl.make_symbol("_openUnitAsync_", "HRDLOpenUnitAsync", c_int16, [], doc) doc = """ int16_t HRDLOpenUnitProgress ( int16_t *handle, int16_t *progress ); """ picohrdl.make_symbol("_openUnitProgress_", "HRDLOpenUnitProgress", c_int16, [c_void_p, c_void_p], doc) doc = """ int16_t HRDLReady ( int16_t handle ); """ picohrdl.make_symbol("_ready_", "HRDLReady", c_int16, [c_int16], doc) doc = """ int16_t HRDLRun ( int16_t handle, int32_t nValues, int16_t method ); """ picohrdl.make_symbol("_run_", "HRDLRun", c_int16, [c_int16, c_int32, c_int16], doc) doc = """ int16_t HRDLSetAnalogInChannel ( int16_t handle, int16_t channel, int16_t enabled, int16_t range, int16_t singleEnded ); """ picohrdl.make_symbol("_setAnalogInChannel_", "HRDLSetAnalogInChannel", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t HRDLSetDigitalIOChannel ( int16_t handle, int16_t directionOut, int16_t digitalOutPinState, int16_t enabledDigitalIn ); """ picohrdl.make_symbol("_setDigitalIOChannel_", "HRDLSetDigitalIOChannel", c_int16, [c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t HRDLSetInterval ( int16_t handle, int32_t samplesInterval_ms, int16_t conversionTime ); """ picohrdl.make_symbol("_setInterval_", "HRDLSetInterval", c_int16, [c_int16, c_int32, c_int16], doc) doc = """ int16_t HRDLSetMains ( int16_t handle, int16_t sixtyHertz ); """ picohrdl.make_symbol("_setMains_", "HRDLSetMains", c_int16, [c_int16, c_int16], doc) doc = """ void HRDLStop ( int16_t handle ); """ picohrdl.make_symbol("_stop_", "HRDLStop", c_int16, [c_int16], doc) ================================================ FILE: picosdk/picosynth.py ================================================ # # Copyright (C) 2022 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the picosynth.h C header file for the PicoSource AS108 Agile Synthesizer using the picosynth driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.errors import ArgumentOutOfRangeError from picosdk.constants import make_enum class Picosynthlib(Library): def __init__(self): super(Picosynthlib, self).__init__("picosynth") picosynth = Picosynthlib() picosynth.PICO_SOURCE_MODEL = make_enum([ "PICO_NONE_SPECIFIED", "PICO_SYNTH", ]) doc = """ PICO_STATUS picosynthOpenUnit ( PICO_SOURCE_MODEL model, uint32_t *handle, unit8_t *serialNumber );""" picosynth.make_symbol("_OpenUnit","picosynthOpenUnit",c_uint32,[c_uint32, c_void_p, c_void_p],doc) doc = """ PICO_STATUS picosynthEnumerateUnits ( PICO_SOURCE_MODEL model, uint8_t *serials, unit16_t *serialLth );""" picosynth.make_symbol("_EnumerateUnits","picosynthEnumerateUnits",c_uint32,[c_uint32, c_void_p, c_void_p],doc) doc = """ PICO_STATUS picosynthGetUnitInfo ( int8_t *string, unit16_t stringLength, uint16_t *requiredSize, PICO_INFO deviceInfo );""" picosynth.make_symbol("_GetUnitInfo","picosynthGetUnitInfo",c_uint32,[c_uint32, c_void_p, c_uint16, c_void_p, c_uint32],doc) doc = """ PICO_STATUS picosynthPingUnit ( uint32_t *handle, );""" picosynth.make_symbol("_PingUnit","picosynthPingUnit",c_uint32,[c_uint32],doc) doc = """ PICO_STATUS picosynthCloseUnit ( uint32_t *handle, );""" picosynth.make_symbol("_CloseUnit","picosynthCloseUnit",c_uint32,[c_uint32],doc) doc = """ PICO_STATUS picosynthSetOutputOff ( uint32_t *handle, );""" picosynth.make_symbol("_SetOutputOff","picosynthSetOutputOff",c_uint32,[c_uint32],doc) doc = """ PICO_STATUS picosynthSetFrequency ( uint32_t *handle, double frequencyHz, double powerLeveldBm );""" picosynth.make_symbol("_SetFrequency","picosynthSetFrequency",c_uint32,[c_uint32, c_double, c_double],doc) doc = """ PICO_STATUS picosynthSetPhase ( uint32_t handle, double phaseDeg );""" picosynth.make_symbol("_SetPhase", "picosynthSetPhase", c_uint32,[c_uint32, c_double], doc) doc = """ PICO_STATUS picosynthSetAmplitudeModulation ( uint32_t handle, double frequencyHz, double powerLeveldBm, double modulationDepthPercent, double modulationRateHz, MODULATION_SOURCE modulationSource, int16_t enabled );""" picosynth.make_symbol("_SetAmplitudeModulation","picosynthSetAmplitudeModulation", c_uint32,[c_uint32,c_double,c_double,c_double,c_double,c_uint32,c_int16],doc) doc = """ PICO_STATUS picosynthSetFrequencyModulation ( uint32_t handle, double frequencyHz, double powerLeveldBm, double modulationDeviationHz, double modulationRateHz, MODULATION_SOURCE modulationSource, int16_t enabled );""" picosynth.make_symbol("_SetFrequencyModulation","picosynthSetFrequencyModulation",c_uint32,[c_uint32,c_double,c_double,c_double,c_double,c_uint32,c_int16],doc) doc = """ PICO_STATUS picosynthSetPhaseModulation ( uint32_t handle, double frequencyHz, double powerLeveldBm, double modulationDeviationHz, double modulationRateHz, MODULATION_SOURCE modulationSource, int16_t enabled );""" picosynth.make_symbol("_SetPhaseModulation","picosynthSetPhaseModulation",c_uint32,[c_uint32,c_double,c_double,c_double,c_double,c_uint32,c_int16],doc) doc = """ PICO_STATUS picosynthSetFrequencyAndLevelSweep ( uint32_t handle, double startFrequencyHz, double stopFrequencyHz, double startLevel, double stopLevel, LEVEL_UNIT levelUnit, double dwellTimeUs, int32_t pointsInSweep, SWEEP_HOP_MODE mode, TRIGGER_MODE triggerMode );""" picosynth.make_symbol("_SetFrequencyAndLevelSweep","picosynthSetFrequencyAndLevelSweep", c_uint32,[c_uint32,c_double,c_double,c_double,c_double,c_uint32,c_double,c_int32,c_uint32,c_uint32],doc) doc = """ PICO_STATUS picosynthSetPhaseAndLevelSweep ( uint32_t handle, double frequencyHz, double startPhaseDeg, double stopPhaseDeg, double startLevel, double stopLevel, LEVEL_UNIT levelUnit, double dwellTimeUs, int32_t pointsInSweep, SWEEP_HOP_MODE mode, TRIGGER_MODE triggerMode );""" picosynth.make_symbol("_SetPhaseAndLevelSweep","picosynthSetPhaseAndLevelSweep", c_uint32,[c_uint32,c_double,c_double,c_double,c_double,c_double,c_uint32,c_double,c_int32,c_uint32,c_uint32],doc) doc = """ PICO_STATUS picosynthSetArbitraryPhaseAndLevel ( uint32_t handle, double frequencyHz, double *arbitraryPhaseDeg, double *arbitraryPowerLeveldBm, int32_t numberOfPoints, double dwellTimeUs, TRIGGER_MODE triggerMode );""" picosynth.make_symbol("_SetArbitraryPhaseAndLevel","picosynthSetArbitraryPhaseAndLevel",c_uint32,[c_uint32,c_double,c_double,c_double,c_int32,c_double,c_uint32],doc) doc = """ PICO_STATUS picosynthSetArbitraryFrequencyAndLevel ( uint32_t handle, double *arbitraryFrequencyHz, double *arbitraryPowerLeveldBm, int32_t numberOfPoints, double dwellTimeUs, TRIGGER_MODE triggerMode );""" picosynth.make_symbol("_SetArbitraryFrequencyAndLevel","picosynthSetArbitraryFrequencyAndLevel",c_uint32,[c_uint32,c_double,c_double,c_int32,c_double,c_uint32],doc) ================================================ FILE: picosdk/pl1000.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the pl1000.h C header file for PicoLog 1000 Series datalogger using the pl1000 driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class Pl1000lib(Library): def __init__(self): super(Pl1000lib, self).__init__("pl1000") pl1000 = Pl1000lib() def _pl1000Inputs(): PL1000_CHANNEL_1 = 1 PL1000_CHANNEL_2 = 2 PL1000_CHANNEL_3 = 3 PL1000_CHANNEL_4 = 4 PL1000_CHANNEL_5 = 5 PL1000_CHANNEL_6 = 6 PL1000_CHANNEL_7 = 7 PL1000_CHANNEL_8 = 8 PL1000_CHANNEL_9 = 9 PL1000_CHANNEL_10 = 10 PL1000_CHANNEL_11 = 11 PL1000_CHANNEL_12 = 12 PL1000_CHANNEL_13 = 13 PL1000_CHANNEL_14 = 14 PL1000_CHANNEL_15 = 15 PL1000_CHANNEL_16 = 16 PL1000_MAX_CHANNEL = PL1000_CHANNEL_16 return {k.upper(): v for k, v in locals().items() if k.startswith("PL1000")} pl1000.PL1000Inputs = _pl1000Inputs() pl1000.PL1000DO_Channel = make_enum([ 'PL1000_DO_CHANNEL_0', 'PL1000_DO_CHANNEL_1', 'PL1000_DO_CHANNEL_2', 'PL1000_DO_CHANNEL_3', 'PL1000_DO_CHANNEL_MAX', ]) pl1000.PL1000OpenProgress = { 'PL1000_OPEN_PROGRESS_FAIL' : -1, 'PL1000_OPEN_PROGRESS_PENDING': 0, 'PL1000_OPEN_PROGRESS_COMPLETE' : 1, } pl1000.PL1000_BLOCK_METHOD = make_enum([ "BM_SINGLE", "BM_WINDOW", "BM_STREAM", ]) doc = """ PICO_STATUS pl1000CloseUnit ( int16_t handle ); """ pl1000.make_symbol("_CloseUnit_", "pl1000CloseUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS pl1000GetSingle ( int16_t handle, PL1000_INPUTS channel, unit16_t *value ); """ pl1000.make_symbol("_GetSingle_", "pl1000GetSingle", c_uint32, [c_int16, c_int32, c_void_p], doc) doc = """ PICO_STATUS pl1000GetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ pl1000.make_symbol("_GetUnitInfo_", "pl1000GetUnitInfo", c_uint32, [c_int16, c_void_p, c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS pl1000GetValues ( int16_t handle, uint16_t *values, uint32_t *noOfValues, unit16_t *overflow, uint32_t *triggerIndex ); """ pl1000.make_symbol("_GetValues_", "pl1000GetValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS pl1000MaxValue ( int16_t handle, uint16_t *maxValue ); """ pl1000.make_symbol("_MaxValue_", "pl1000MaxValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS pl1000OpenUnit ( int16_t *handle ); """ pl1000.make_symbol("_OpenUnit_", "pl1000OpenUnit", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS pl1000OpenUnitAsync ( int16_t *status ); """ pl1000.make_symbol("_OpenUnitAsync_", "pl1000OpenUnitAsync", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS pl1000OpenUnitProgress ( int16_t *handle, int16_t *progress, int16_t *complete ); """ pl1000.make_symbol("_OpenUnitProgress_", "pl1000OpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS pl1000PingUnit ( int16_t handle ); """ pl1000.make_symbol("_PingUnit_", "pl1000PingUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS pl1000Ready ( int16_t handle, int16_t *ready ); """ pl1000.make_symbol("_Ready_", "pl1000Ready", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS pl1000Run ( int16_t handle, uint32_t no_of_values, BLOCK_METHOD method ); """ pl1000.make_symbol("_Run_", "pl1000Run", c_uint32, [c_int16, c_uint32, c_int32], doc) doc = """ PICO_STATUS pl1000SetDo ( int16_t handle, int16_t do_value, int16_t doNo ); """ pl1000.make_symbol("_SetDo_", "pl1000SetDo", c_uint32, [c_int16, c_int16, c_int16], doc) doc = """ PICO_STATUS pl1000SetInterval ( int16_t handle, uint32_t *us_for_block, uint32_t ideal_no_of_samples, int16_t *channels, int16_t no_of_channels ); """ pl1000.make_symbol("_SetInterval_", "pl1000SetInterval", c_uint32, [c_int16, c_void_p, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS pl1000SetPulseWidth ( int16_t handle, uint16_t period, uint8_t cycle ); """ pl1000.make_symbol("_SetPulseWidth_", "pl1000SetPulseWidth", c_uint32, [c_int16, c_int16, c_int8], doc) doc = """ PICO_STATUS pl1000SetTrigger ( int16_t handle, uint16_t enabled, uint16_t auto_trigger, uint16_t auto_ms, uint16_t channel, uint16_t dir, uint16_t threshold, uint16_t hysteresis, float delay ); """ pl1000.make_symbol("_SetTrigger_", "pl1000SetTrigger", c_uint32, [c_int16, c_uint16, c_uint16, c_uint16, c_uint16, c_uint16, c_uint16, c_uint16, c_float], doc) doc = """ PICO_STATUS pl1000Stop ( int16_t handle ); """ pl1000.make_symbol("_Stop_", "pl1000Stop", c_uint32, [c_int16], doc) ================================================ FILE: picosdk/ps2000.py ================================================ # # Copyright (C) 2015-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps2000.h C header file for PicoScope 2000 Series oscilloscopes using the ps2000 driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.errors import ArgumentOutOfRangeError from picosdk.constants import make_enum from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY class Ps2000lib(Library): def __init__(self): super(Ps2000lib, self).__init__("ps2000") ps2000 = Ps2000lib() ps2000.PS2000_CHANNEL = make_enum([ "PS2000_CHANNEL_A", "PS2000_CHANNEL_B", ]) # use the last character, i.e. the channel name: ps2000.PICO_CHANNEL = {k[-1]: v for k, v in ps2000.PS2000_CHANNEL.items()} # This field is passed to the driver as a boolean, not an enum. ps2000.PICO_COUPLING = { 'AC': 0, 'DC': 1 } ps2000.PS2000_WAVE_TYPE = make_enum([ "PS2000_SINE", "PS2000_SQUARE", "PS2000_TRIANGLE", "PS2000_RAMPUP", "PS2000_RAMPDOWN", "PS2000_DC_VOLTAGE", "PS2000_GAUSSIAN", "PS2000_SINC", "PS2000_HALF_SINE", ]) ps2000.PS2000_SWEEP_TYPE = make_enum([ "PS2000_UP", "PS2000_DOWN", "PS2000_UPDOWN", "PS2000_DOWNUP", ]) ps2000.PS2000_VOLTAGE_RANGE = { 'PS2000_20MV': 1, 'PS2000_50MV': 2, 'PS2000_100MV': 3, 'PS2000_200MV': 4, 'PS2000_500MV': 5, 'PS2000_1V': 6, 'PS2000_2V': 7, 'PS2000_5V': 8, 'PS2000_10V': 9, 'PS2000_20V': 10, } # float voltage value max (multiplier for output voltages). Parse the value in the constant name. ps2000.PICO_VOLTAGE_RANGE = { v: float(k.split('_')[1][:-1]) if k[-2] != 'M' else (0.001 * float(k.split('_')[1][:-2])) for k, v in ps2000.PS2000_VOLTAGE_RANGE.items() } ps2000.MAX_MEMORY = 32e3 ps2000.PS2000_TIME_UNITS = make_enum([ 'PS2000_FS', 'PS2000_PS', 'PS2000_NS', 'PS2000_US', 'PS2000_MS', 'PS2000_S', 'PS2000_MAX_TIME_UNITS', ]) doc = """ int16_t ps2000_open_unit ( void ); """ ps2000.make_symbol("_open_unit", "ps2000_open_unit", c_int16, [], doc) doc = """ int16_t ps2000_get_unit_info ( int16_t handle, int8_t *string, int16_t string_length, int16_t line ); """ ps2000.make_symbol("_get_unit_info", "ps2000_get_unit_info", c_int16, [c_int16, c_char_p, c_int16, c_int16], doc) doc = """ int16_t ps2000_flash_led ( int16_t handle ); """ ps2000.make_symbol("_flash_led", "ps2000_flash_led", c_int16, [c_int16, ], doc) doc = """ int16_t ps2000_close_unit ( int16_t handle ); """ ps2000.make_symbol("_close_unit", "ps2000_close_unit", c_int16, [c_int16, ], doc) doc = """ int16_t ps2000_set_channel ( int16_t handle, int16_t channel, int16_t enabled, int16_t dc, int16_t range ); """ ps2000.make_symbol("_set_channel", "ps2000_set_channel", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t ps2000_get_timebase ( int16_t handle, int16_t timebase, int32_t no_of_samples, int32_t *time_interval, int16_t *time_units, int16_t oversample, int32_t *max_samples ); """ ps2000.make_symbol("_get_timebase", "ps2000_get_timebase", c_int16, [c_int16, c_int16, c_int32, c_void_p, c_void_p, c_int16, c_void_p], doc) doc = """ int16_t ps2000_set_trigger ( int16_t handle, int16_t source, int16_t threshold, int16_t direction, int16_t delay, int16_t auto_trigger_ms ); """ ps2000.make_symbol("_set_trigger", "ps2000_set_trigger", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t ps2000_set_trigger2 ( int16_t handle, int16_t source, int16_t threshold, int16_t direction, float delay, int16_t auto_trigger_ms ); """ ps2000.make_symbol("_set_trigger2", "ps2000_set_trigger2", c_int16, [c_int16, c_int16, c_int16, c_int16, c_float, c_int16], doc) doc = """ int16_t ps2000_run_block ( int16_t handle, int32_t no_of_values, int16_t timebase, int16_t oversample, int32_t * time_indisposed_ms ); """ ps2000.make_symbol("_run_block", "ps2000_run_block", c_int16, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ int16_t ps2000_run_streaming ( int16_t handle, int16_t sample_interval_ms, int32_t max_samples, int16_t windowed ); """ ps2000.make_symbol("_run_streaming", "ps2000_run_streaming", c_int16, [c_int16, c_int16, c_int32, c_int16], doc) doc = """ int16_t ps2000_run_streaming_ns ( int16_t handle, uint32_t sample_interval, PS2000_TIME_UNITS time_units, uint32_t max_samples, int16_t auto_stop, uint32_t noOfSamplesPerAggregate, uint32_t overview_buffer_size ); """ ps2000.make_symbol("_run_streaming_ns", "ps2000_run_streaming_ns", c_int16, [c_int16, c_uint32, c_int32, c_uint32, c_int16, c_uint32, c_uint32], doc) doc = """ int16_t ps2000_ready ( int16_t handle ); """ ps2000.make_symbol("_ready", "ps2000_ready", c_int16, [c_int16, ], doc) doc = """ int16_t ps2000_stop ( int16_t handle ); """ ps2000.make_symbol("_stop", "ps2000_stop", c_int16, [c_int16, ], doc) doc = """ int32_t ps2000_get_values ( int16_t handle, int16_t *buffer_a, int16_t *buffer_b, int16_t *buffer_c, int16_t *buffer_d, int16_t *overflow, int32_t no_of_values ); """ ps2000.make_symbol("_get_values", "ps2000_get_values", c_int32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_int32], doc) doc = """ int32_t ps2000_get_times_and_values ( int16_t handle, int32_t *times, int16_t *buffer_a, int16_t *buffer_b, int16_t *buffer_c, int16_t *buffer_d, int16_t *overflow, int16_t time_units, int32_t no_of_values ); """ ps2000.make_symbol("_get_times_and_values", "ps2000_get_times_and_values", c_int32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_int16, c_int32], doc) doc = """ int16_t ps2000_last_button_press ( int16_t handle ); """ ps2000.make_symbol("_last_button_press", "ps2000_last_button_press", c_int16, [c_int16, ], doc) doc = """ int32_t ps2000_set_ets ( int16_t handle, int16_t mode, int16_t ets_cycles, int16_t ets_interleave ); """ ps2000.make_symbol("_set_ets", "ps2000_set_ets", c_int32, [c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t ps2000_set_led ( int16_t handle, int16_t state ); """ ps2000.make_symbol("_set_led", "ps2000_set_led", c_int16, [c_int16, c_int16], doc) doc = """ int16_t ps2000_open_unit_async ( void ); """ ps2000.make_symbol("_open_unit_async", "ps2000_open_unit_async", c_int16, [], doc) doc = """ int16_t ps2000_open_unit_progress ( int16_t *handle, int16_t *progress_percent ); """ ps2000.make_symbol("_open_unit_progress", "ps2000_open_unit_progress", c_int16, [c_void_p, c_void_p], doc) doc = """ int16_t ps2000_get_streaming_last_values ( int16_t handle, GetOverviewBuffersMaxMin ); """ ps2000.make_symbol("_get_streaming_last_values", "ps2000_get_streaming_last_values", c_int16, [c_int16, c_void_p], doc) doc = """ int16_t ps2000_overview_buffer_status ( int16_t handle, int16_t *previous_buffer_overrun ); """ ps2000.make_symbol("_overview_buffer_status", "ps2000_overview_buffer_status", c_int16, [c_int16, c_void_p], doc) doc = """ uint32_t ps2000_get_streaming_values ( int16_t handle, double *start_time, int16_t *pbuffer_a_max, int16_t *pbuffer_a_min, int16_t *pbuffer_b_max, int16_t *pbuffer_b_min, int16_t *pbuffer_c_max, int16_t *pbuffer_c_min, int16_t *pbuffer_d_max, int16_t *pbuffer_d_min, int16_t *overflow, uint32_t *triggerAt, int16_t *triggered, uint32_t no_of_values, uint32_t noOfSamplesPerAggregate ); """ ps2000.make_symbol("_get_streaming_values", "ps2000_get_streaming_values", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ uint32_t ps2000_get_streaming_values_no_aggregation ( int16_t handle, double *start_time, int16_t * pbuffer_a, int16_t * pbuffer_b, int16_t * pbuffer_c, int16_t * pbuffer_d, int16_t * overflow, uint32_t * triggerAt, int16_t * trigger, uint32_t no_of_values ); """ ps2000.make_symbol("_get_streaming_values_no_aggregation", "ps2000_get_streaming_values_no_aggregation", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32], doc) doc = """ int16_t ps2000_set_light ( int16_t handle, int16_t state ); """ ps2000.make_symbol("_set_light", "ps2000_set_light", c_int16, [c_int16, c_int16], doc) doc = """ int16_t ps2000_set_sig_gen_arbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, uint8_t *arbitraryWaveform, int32_t arbitraryWaveformSize, PS2000_SWEEP_TYPE sweepType, uint32_t sweeps ); """ ps2000.make_symbol("_set_sig_gen_arbitrary", "ps2000_set_sig_gen_arbitrary", c_int16, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_uint32], doc) doc = """ int16_t ps2000_set_sig_gen_built_in ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, PS2000_WAVE_TYPE waveType, float startFrequency, float stopFrequency, float increment, float dwellTime, PS2000_SWEEP_TYPE sweepType, uint32_t sweeps ); """ ps2000.make_symbol("_set_sig_gen_built_in", "ps2000_set_sig_gen_built_in", c_int16, [c_int16, c_int32, c_uint32, c_int32, c_float, c_float, c_float, c_float, c_int32, c_uint32], doc) doc = """ int16_t ps2000SetAdvTriggerChannelProperties ( int16_t handle, PS2000_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int32_t autoTriggerMilliseconds ); """ ps2000.make_symbol("_SetAdvTriggerChannelProperties", "ps2000SetAdvTriggerChannelProperties", c_int16, [c_int16, c_void_p, c_int16, c_int32], doc) doc = """ int16_t ps2000SetAdvTriggerChannelConditions ( int16_t handle, PS2000_TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps2000.make_symbol("_SetAdvTriggerChannelConditions", "ps2000SetAdvTriggerChannelConditions", c_int16, [c_int16, c_void_p, c_int16], doc) doc = """ int16_t ps2000SetAdvTriggerChannelDirections ( int16_t handle, PS2000_THRESHOLD_DIRECTION channelA, PS2000_THRESHOLD_DIRECTION channelB, PS2000_THRESHOLD_DIRECTION channelC, PS2000_THRESHOLD_DIRECTION channelD, PS2000_THRESHOLD_DIRECTION ext ); """ ps2000.make_symbol("_SetAdvTriggerChannelDirections", "ps2000SetAdvTriggerChannelDirections", c_int16, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ int16_t ps2000SetPulseWidthQualifier ( int16_t handle, PS2000_PWQ_CONDITIONS *conditions, int16_t nConditions, PS2000_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS2000_PULSE_WIDTH_TYPE type ); """ ps2000.make_symbol("_SetPulseWidthQualifier", "ps2000SetPulseWidthQualifier", c_int16, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ int16_t ps2000SetAdvTriggerDelay ( int16_t handle, uint32_t delay, float preTriggerDelay ); """ ps2000.make_symbol("_SetAdvTriggerDelay", "ps2000SetAdvTriggerDelay", c_int16, [c_int16, c_uint32, c_float], doc) doc = """ int16_t ps2000PingUnit ( int16_t handle ); """ ps2000.make_symbol("_PingUnit", "ps2000PingUnit", c_int16, [c_int16, ], doc) ps2000.PICO_INFO = {k: v for k, v in ps2000.PICO_INFO.items() if v <= 0x00000005} ps2000.PICO_INFO["PICO_ERROR_CODE"] = 0x00000006 ps2000.PICO_INFO["PICO_KERNEL_DRIVER_VERSION"] = 0x00000007 doc = """ void *my_get_overview_buffers ( int16_t **overviewBuffers int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, uint32_t nValues ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps2000.GetOverviewBuffersType = C_CALLBACK_FUNCTION_FACTORY(None, POINTER(POINTER(c_int16)), c_int16, c_uint32, c_int16, c_int16, c_uint32) ps2000.GetOverviewBuffersType.__doc__ = doc ================================================ FILE: picosdk/ps2000a.py ================================================ # # Copyright (C) 2014-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps2000aApi.h C header file for PicoScope 2000 Series oscilloscopes using the ps2000a driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class Ps2000alib(Library): def __init__(self): super(Ps2000alib, self).__init__("ps2000a") ps2000a = Ps2000alib() # A tuple in an enum like this is 2 names for the same value. ps2000a.PS2000A_CHANNEL = make_enum([ "PS2000A_CHANNEL_A", "PS2000A_CHANNEL_B", "PS2000A_CHANNEL_C", "PS2000A_CHANNEL_D", ("PS2000A_EXTERNAL", "PS2000A_MAX_CHANNELS"), "PS2000A_TRIGGER_AUX", "PS2000A_MAX_TRIGGER_SOURCE", ]) # only include the normal analog channels for now: ps2000a.PICO_CHANNEL = {k[-1]: v for k, v in ps2000a.PS2000A_CHANNEL.items() if "PS2000A_CHANNEL_" in k} ps2000a.PS2000A_COUPLING = make_enum([ 'PS2000A_AC', 'PS2000A_DC', ]) # Just use AC and DC. ps2000a.PICO_COUPLING = {k[-2:]: v for k, v in ps2000a.PS2000A_COUPLING.items()} ps2000a.PS2000A_RANGE = make_enum([ "PS2000A_10MV", "PS2000A_20MV", "PS2000A_50MV", "PS2000A_100MV", "PS2000A_200MV", "PS2000A_500MV", "PS2000A_1V", "PS2000A_2V", "PS2000A_5V", "PS2000A_10V", "PS2000A_20V", "PS2000A_50V", "PS2000A_MAX_RANGES", ]) ps2000a.PICO_VOLTAGE_RANGE = { v: float(k.split('_')[1][:-1]) if k[-2] != 'M' else (0.001 * float(k.split('_')[1][:-2])) for k, v in ps2000a.PS2000A_RANGE.items() if k != "PS2000A_MAX_RANGES" } ps2000a.MAX_MEMORY = 128e6 ps2000a.PS2000A_RATIO_MODE = { 'PS2000A_RATIO_MODE_NONE': 0, 'PS2000A_RATIO_MODE_AGGREGATE': 1, 'PS2000A_RATIO_MODE_DECIMATE': 2, 'PS2000A_RATIO_MODE_AVERAGE': 4, } ps2000a.PS2000A_TIME_UNITS = make_enum([ 'PS2000A_FS', 'PS2000A_PS', 'PS2000A_NS', 'PS2000A_US', 'PS2000A_MS', 'PS2000A_S', 'PS2000A_MAX_TIME_UNITS', ]) ps2000a.PICO_RATIO_MODE = {k[19:]: v for k, v in ps2000a.PS2000A_RATIO_MODE.items()} def _define_threshold_direction(): ps2000a_above = 0 ps2000a_below = 1 ps2000a_rising = 2 ps2000a_falling = 3 ps2000a_rising_or_falling = 4 ps2000a_above_lower = 5 ps2000a_below_lower = 6 ps2000a_rising_lower = 7 ps2000a_falling_lower = 8 ps2000a_inside = ps2000a_above ps2000a_outside = ps2000a_below ps2000a_enter = ps2000a_rising ps2000a_exit = ps2000a_falling ps2000a_enter_or_exit = ps2000a_rising_or_falling ps2000a_positive_runt = 9 ps2000a_negative_runt = 10 ps2000a_none = ps2000a_rising return {k.upper(): v for k, v in locals().items() if k.startswith("ps2000a")} ps2000a.PS2000A_THRESHOLD_DIRECTION = _define_threshold_direction() ps2000a.PICO_THRESHOLD_DIRECTION = { k[8:]: v for k, v in ps2000a.PS2000A_THRESHOLD_DIRECTION.items() } ps2000a.PS2000A_THRESHOLD_MODE = make_enum([ "PS2000A_LEVEL", "PS2000A_WINDOW", ]) ps2000a.PS2000A_TRIGGER_STATE = make_enum([ "PS2000A_CONDITION_DONT_CARE", "PS2000A_CONDITION_TRUE", "PS2000A_CONDITION_FALSE", "PS2000A_CONDITION_MAX", ]) def _define_digital_port(): ps2000a_digital_port0 = 0x80 ps2000a_digital_port1 = ps2000a_digital_port0 + 1 ps2000a_digital_port2 = ps2000a_digital_port0 + 2 ps2000a_digital_port3 = ps2000a_digital_port0 + 3 ps2000a_max_digital_ports = ps2000a_digital_port3 - ps2000a_digital_port0 + 1 return {k.upper(): v for k, v in locals().items() if k.startswith("ps2000a")} ps2000a.PS2000A_DIGITAL_PORT = _define_digital_port() ps2000a.PS2000A_DIGITAL_CHANNEL = make_enum([ "PS2000A_DIGITAL_CHANNEL_0", "PS2000A_DIGITAL_CHANNEL_1", "PS2000A_DIGITAL_CHANNEL_2", "PS2000A_DIGITAL_CHANNEL_3", "PS2000A_DIGITAL_CHANNEL_4", "PS2000A_DIGITAL_CHANNEL_5", "PS2000A_DIGITAL_CHANNEL_6", "PS2000A_DIGITAL_CHANNEL_7", "PS2000A_DIGITAL_CHANNEL_8", "PS2000A_DIGITAL_CHANNEL_9", "PS2000A_DIGITAL_CHANNEL_10", "PS2000A_DIGITAL_CHANNEL_11", "PS2000A_DIGITAL_CHANNEL_12", "PS2000A_DIGITAL_CHANNEL_13", "PS2000A_DIGITAL_CHANNEL_14", "PS2000A_DIGITAL_CHANNEL_15", "PS2000A_DIGITAL_CHANNEL_16", "PS2000A_DIGITAL_CHANNEL_17", "PS2000A_DIGITAL_CHANNEL_18", "PS2000A_DIGITAL_CHANNEL_19", "PS2000A_DIGITAL_CHANNEL_20", "PS2000A_DIGITAL_CHANNEL_21", "PS2000A_DIGITAL_CHANNEL_22", "PS2000A_DIGITAL_CHANNEL_23", "PS2000A_DIGITAL_CHANNEL_24", "PS2000A_DIGITAL_CHANNEL_25", "PS2000A_DIGITAL_CHANNEL_26", "PS2000A_DIGITAL_CHANNEL_27", "PS2000A_DIGITAL_CHANNEL_28", "PS2000A_DIGITAL_CHANNEL_29", "PS2000A_DIGITAL_CHANNEL_30", "PS2000A_DIGITAL_CHANNEL_31", "PS2000A_MAX_DIGITAL_CHANNELS", ]) ps2000a.PS2000A_DIGITAL_DIRECTION = make_enum([ "PS2000A_DIGITAL_DONT_CARE", "PS2000A_DIGITAL_DIRECTION_LOW", "PS2000A_DIGITAL_DIRECTION_HIGH", "PS2000A_DIGITAL_DIRECTION_RISING", "PS2000A_DIGITAL_DIRECTION_FALLING", "PS2000A_DIGITAL_DIRECTION_RISING_OR_FALLING", "PS2000A_DIGITAL_MAX_DIRECTION", ]) ps2000a.PS2000A_PULSE_WIDTH_TYPE = make_enum([ "PS2000A_PW_TYPE_NONE", "PS2000A_PW_TYPE_LESS_THAN", "PS2000A_PW_TYPE_GREATER_THAN", "PS2000A_PW_TYPE_IN_RANGE", "PS2000A_PW_TYPE_OUT_OF_RANGE" ]) class PS2000A_TRIGGER_CONDITIONS(Structure): _pack_ = 1 _fields_ = [("channelA", c_int32), ("channelB", c_int32), ("channelC", c_int32), ("channelD", c_int32), ("external", c_int32), ("aux", c_int32), ("pulseWidthQualifier", c_int32), ("digital", c_int32)] ps2000a.PS2000A_TRIGGER_CONDITIONS = PS2000A_TRIGGER_CONDITIONS class PS2000A_PWQ_CONDITIONS(Structure): _pack_ = 1 _fields_ = [("channelA", c_int32), ("channelB", c_int32), ("channelC", c_int32), ("channelD", c_int32), ("external", c_int32), ("aux", c_int32), ("digital", c_int32)] ps2000a.PS2000A_PWQ_CONDITIONS = PS2000A_PWQ_CONDITIONS class PS2000A_DIGITAL_CHANNEL_DIRECTIONS(Structure): _pack_ = 1 _fields_ = [("channel", c_int32), ("direction", c_int32)] ps2000a.PS2000A_DIGITAL_CHANNEL_DIRECTIONS = PS2000A_DIGITAL_CHANNEL_DIRECTIONS class PS2000A_TRIGGER_CHANNEL_PROPERTIES(Structure): _pack_ = 1 _fields_ = [("thresholdUpper", c_int16), ("thresholdHysteresis", c_uint16), ("thresholdLower", c_int16), ("thresholdLowerHysteresis", c_uint16), ("channel", c_int32), ("thresholdMode", c_int32)] ps2000a.PS2000A_TRIGGER_CHANNEL_PROPERTIES = PS2000A_TRIGGER_CHANNEL_PROPERTIES doc = """ PICO_STATUS ps2000aOpenUnit ( int16_t *status, int8_t *serial ); """ ps2000a.make_symbol("_OpenUnit", "ps2000aOpenUnit", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps2000aOpenUnitAsync ( int16_t *status, int8_t *serial ); """ ps2000a.make_symbol("_OpenUnitAsync", "ps2000aOpenUnitAsync", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps2000aOpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps2000a.make_symbol("_OpenUnitProgress", "ps2000aOpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps2000a.make_symbol("_GetUnitInfo", "ps2000aGetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps2000aFlashLed ( int16_t handle, int16_t start ); """ ps2000a.make_symbol("_FlashLed", "ps2000aFlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps2000aCloseUnit ( int16_t handle ); """ ps2000a.make_symbol("_CloseUnit", "ps2000aCloseUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps2000aMemorySegments ( int16_t handle, uint32_t nSegments, int32_t *nMaxSamples ); """ ps2000a.make_symbol("_MemorySegments", "ps2000aMemorySegments", c_uint32, [c_int16, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps2000aSetChannel ( int16_t handle, PS2000A_CHANNEL channel, int16_t enabled, PS2000A_COUPLING type, PS2000A_RANGE range, float analogOffset ); """ ps2000a.make_symbol("_SetChannel", "ps2000aSetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int32, c_float], doc) doc = """ PICO_STATUS ps2000aSetDigitalPort ( int16_t handle, PS2000A_DIGITAL_PORT port, int16_t enabled, int16_t logicLevel ); """ ps2000a.make_symbol("_SetDigitalPort", "ps2000aSetDigitalPort", c_uint32, [c_int16, c_int32, c_int16, c_int16], doc) doc = """ PICO_STATUS ps2000aSetNoOfCaptures ( int16_t handle, uint32_t nCaptures ); """ ps2000a.make_symbol("_SetNoOfCaptures", "ps2000aSetNoOfCaptures", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps2000aGetTimebase ( int16_t handle, uint32_t timebase, int32_t noSamples, int32_t *timeIntervalNanoseconds, int16_t oversample, int32_t *totalSamples, uint32_t segmentIndex ); """ ps2000a.make_symbol("_GetTimebase", "ps2000aGetTimebase", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps2000aGetTimebase2 ( int16_t handle, uint32_t timebase, int32_t noSamples, float *timeIntervalNanoseconds, int16_t oversample, int32_t *totalSamples, uint32_t segmentIndex ); """ ps2000a.make_symbol("_GetTimebase2", "ps2000aGetTimebase2", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps2000aSetSigGenArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, int16_t *arbitraryWaveform, int32_t arbitraryWaveformSize, PS2000A_SWEEP_TYPE sweepType, PS2000A_EXTRA_OPERATIONS operation, PS2000A_INDEX_MODE indexMode, uint32_t shots, uint32_t sweeps, PS2000A_SIGGEN_TRIG_TYPE triggerType, PS2000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps2000a.make_symbol("_SetSigGenArbitrary", "ps2000aSetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps2000aSetSigGenBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t waveType, float startFrequency, float stopFrequency, float increment, float dwellTime, PS2000A_SWEEP_TYPE sweepType, PS2000A_EXTRA_OPERATIONS operation, uint32_t shots, uint32_t sweeps, PS2000A_SIGGEN_TRIG_TYPE triggerType, PS2000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps2000a.make_symbol("_SetSigGenBuiltIn", "ps2000aSetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_float, c_float, c_float, c_float, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps2000aSetSigGenPropertiesArbitrary ( int16_t handle, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, PS2000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS2000A_SIGGEN_TRIG_TYPE triggerType, PS2000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps2000a.make_symbol("_SetSigGenPropertiesArbitrary", "ps2000aSetSigGenPropertiesArbitrary", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps2000aSetSigGenPropertiesBuiltIn ( int16_t handle, double startFrequency, double stopFrequency, double increment, double dwellTime, PS2000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS2000A_SIGGEN_TRIG_TYPE triggerType, PS2000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps2000a.make_symbol("_SetSigGenPropertiesBuiltIn", "ps2000aSetSigGenPropertiesBuiltIn", c_uint32, [c_int16, c_double, c_double, c_double, c_double, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps2000aSigGenFrequencyToPhase ( int16_t handle, double frequency, PS2000A_INDEX_MODE indexMode, uint32_t bufferLength, uint32_t *phase ); """ ps2000a.make_symbol("_SigGenFrequencyToPhase", "ps2000aSigGenFrequencyToPhase", c_uint32, [c_int16, c_double, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps2000aSigGenArbitraryMinMaxValues ( int16_t handle, int16_t *minArbitraryWaveformValue, int16_t *maxArbitraryWaveformValue, uint32_t *minArbitraryWaveformSize, uint32_t *maxArbitraryWaveformSize ); """ ps2000a.make_symbol("_SigGenArbitraryMinMaxValues", "ps2000aSigGenArbitraryMinMaxValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aSigGenSoftwareControl ( int16_t handle, int16_t state ); """ ps2000a.make_symbol("_SigGenSoftwareControl", "ps2000aSigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps2000aSetEts ( int16_t handle, PS2000A_ETS_MODE mode, int16_t etsCycles, int16_t etsInterleave, int32_t *sampleTimePicoseconds ); """ ps2000a.make_symbol("_SetEts", "ps2000aSetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aSetSimpleTrigger ( int16_t handle, int16_t enable, PS2000A_CHANNEL source, int16_t threshold, PS2000A_THRESHOLD_DIRECTION direction, uint32_t delay, int16_t autoTrigger_ms ); """ ps2000a.make_symbol("_SetSimpleTrigger", "ps2000aSetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps2000aSetTriggerDigitalPortProperties ( int16_t handle, PS2000A_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps2000a.make_symbol("_SetTriggerDigitalPortProperties", "ps2000aSetTriggerDigitalPortProperties", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps2000aSetDigitalAnalogTriggerOperand ( int16_t handle, PS2000A_TRIGGER_OPERAND operand ); """ ps2000a.make_symbol("_SetDigitalAnalogTriggerOperand", "ps2000aSetDigitalAnalogTriggerOperand", c_uint32, [c_int16, c_int32], doc) doc = """ PICO_STATUS ps2000aSetTriggerChannelProperties ( int16_t handle, PS2000A_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, int32_t autoTriggerMilliseconds ); """ ps2000a.make_symbol("_SetTriggerChannelProperties", "ps2000aSetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps2000aSetTriggerChannelConditions ( int16_t handle, PS2000A_TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps2000a.make_symbol("_SetTriggerChannelConditions", "ps2000aSetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps2000aSetTriggerChannelDirections ( int16_t handle, PS2000A_THRESHOLD_DIRECTION channelA, PS2000A_THRESHOLD_DIRECTION channelB, PS2000A_THRESHOLD_DIRECTION channelC, PS2000A_THRESHOLD_DIRECTION channelD, PS2000A_THRESHOLD_DIRECTION ext, PS2000A_THRESHOLD_DIRECTION aux ); """ ps2000a.make_symbol("_SetTriggerChannelDirections", "ps2000aSetTriggerChannelDirections", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps2000aSetTriggerDelay ( int16_t handle, uint32_t delay ); """ ps2000a.make_symbol("_SetTriggerDelay", "ps2000aSetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps2000aSetPulseWidthQualifier ( int16_t handle, PS2000A_PWQ_CONDITIONS *conditions, int16_t nConditions, PS2000A_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS2000A_PULSE_WIDTH_TYPE type ); """ ps2000a.make_symbol("_SetPulseWidthQualifier", "ps2000aSetPulseWidthQualifier", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps2000aIsTriggerOrPulseWidthQualifierEnabled ( int16_t handle, int16_t *triggerEnabled, int16_t *pulseWidthQualifierEnabled ); """ ps2000a.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps2000aIsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetTriggerTimeOffset64 ( int16_t handle, int64_t *time, PS2000A_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps2000a.make_symbol("_GetTriggerTimeOffset", "ps2000aGetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS PREF2 PREF3 (ps2000aGetValuesTriggerTimeOffsetBulk64) ( int16_t handle, int64_t *times, PS2000A_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps2000a.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps2000aGetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps2000aGetNoOfCaptures ( int16_t handle, uint32_t *nCaptures ); """ ps2000a.make_symbol("_GetNoOfCaptures", "ps2000aGetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetNoOfProcessedCaptures ( int16_t handle, uint32_t *nProcessedCaptures ); """ ps2000a.make_symbol("_GetNoOfProcessedCaptures", "ps2000aGetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aSetDataBuffer ( int16_t handle, int32_t channelOrPort, int16_t *buffer, int32_t bufferLth, uint32_t segmentIndex, PS2000A_RATIO_MODE mode ); """ ps2000a.make_symbol("_SetDataBuffer", "ps2000aSetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps2000aSetDataBuffers ( int16_t handle, int32_t channelOrPort, int16_t *bufferMax, int16_t *bufferMin, int32_t bufferLth, uint32_t segmentIndex, PS2000A_RATIO_MODE mode ); """ ps2000a.make_symbol("_SetDataBuffers", "ps2000aSetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps2000aSetEtsTimeBuffer ( int16_t handle, int64_t *buffer, int32_t bufferLth ); """ ps2000a.make_symbol("_SetEtsTimeBuffer", "ps2000aSetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps2000aIsReady ( int16_t handle, int16_t *ready ); """ ps2000a.make_symbol("_IsReady", "ps2000aIsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aRunBlock ( int16_t handle, int32_t noOfPreTriggerSamples, int32_t noOfPostTriggerSamples, uint32_t timebase, int16_t oversample, int32_t *timeIndisposedMs, uint32_t segmentIndex, ps2000aBlockReady lpReady, void *pParameter ); """ ps2000a.make_symbol("_RunBlock", "ps2000aRunBlock", c_uint32, [c_int16, c_int32, c_int32, c_uint32, c_int16, c_void_p, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aRunStreaming ( int16_t handle, uint32_t *sampleInterval, PS2000A_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostPreTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, uint32_t overviewBufferSize ); """ ps2000a.make_symbol("_RunStreaming", "ps2000aRunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps2000aGetStreamingLatestValues ( int16_t handle, ps2000aStreamingReady lpPs2000aReady, void *pParameter ); """ ps2000a.make_symbol("_GetStreamingLatestValues", "ps2000aGetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ void *ps2000aStreamingReady ( int16_t handle, int32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void *pParameter ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps2000a.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps2000a.StreamingReadyType.__doc__ = doc doc = """ PICO_STATUS ps2000aNoOfStreamingValues ( int16_t handle, uint32_t *noOfValues ); """ ps2000a.make_symbol("_NoOfStreamingValues", "ps2000aNoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetMaxDownSampleRatio ( int16_t handle, uint32_t noOfUnaggreatedSamples, uint32_t *maxDownSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex ); """ ps2000a.make_symbol("_GetMaxDownSampleRatio", "ps2000aGetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps2000aGetValues ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps2000a.make_symbol("_GetValues", "ps2000aGetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetValuesBulk ( int16_t handle, uint32_t *noOfSamples, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, uint32_t downSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, int16_t *overflow ); """ ps2000a.make_symbol("_GetValuesBulk", "ps2000aGetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32, c_uint32, c_int32, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetValuesAsync ( int16_t handle, uint32_t startIndex, uint32_t noOfSamples, uint32_t downSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, void *lpDataReady, void *pParameter ); """ ps2000a.make_symbol("_GetValuesAsync", "ps2000aGetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetValuesOverlapped ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps2000a.make_symbol("_GetValuesOverlapped", "ps2000aGetValuesOverlapped", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetValuesOverlappedBulk ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS2000A_RATIO_MODE downSampleRatioMode, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, int16_t *overflow ); """ ps2000a.make_symbol("_GetValuesOverlappedBulk", "ps2000aGetValuesOverlappedBulk", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_int32, c_void_p], doc) doc = """ PICO_STATUS ps2000aStop ( int16_t handle ); """ ps2000a.make_symbol("_Stop", "ps2000aStop", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps2000aHoldOff ( int16_t handle, uint64_t holdoff, PS2000A_HOLDOFF_TYPE type ); """ ps2000a.make_symbol("_HoldOff", "ps2000aHoldOff", c_uint32, [c_int16, c_uint64, c_int32], doc) doc = """ PICO_STATUS ps2000aGetChannelInformation ( int16_t handle, PS2000A_CHANNEL_INFO info, int32_t probe, int32_t *ranges, int32_t *length, int32_t channels ); """ ps2000a.make_symbol("_GetChannelInformation", "ps2000aGetChannelInformation", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps2000aEnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps2000a.make_symbol("_EnumerateUnits", "ps2000aEnumerateUnits", c_uint32, [c_void_p, c_char_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aPingUnit ( int16_t handle ); """ ps2000a.make_symbol("_PingUnit", "ps2000aPingUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps2000aMaximumValue ( int16_t handle, int16_t *value ); """ ps2000a.make_symbol("_MaximumValue", "ps2000aMaximumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aMinimumValue ( int16_t handle, int16_t *value ); """ ps2000a.make_symbol("_MinimumValue", "ps2000aMinimumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetAnalogueOffset ( int16_t handle, PS2000A_RANGE range, PS2000A_COUPLING coupling, float *maximumVoltage, float *minimumVoltage ); """ ps2000a.make_symbol("_GetAnalogueOffset", "ps2000aGetAnalogueOffset", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps2000aGetMaxSegments ( int16_t handle, uint32_t *maxSegments ); """ ps2000a.make_symbol("_GetMaxSegments", "ps2000aGetMaxSegments", c_uint32, [c_int16, c_void_p], doc) ps2000a.INI_LOGIC_VOLTS = 1.5 doc = """ void *ps2000aBlockReady ( int16_t handle, PICO_STATUS status, void *pParameter ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps2000a.BlockReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p) ps2000a.BlockReadyType.__doc__ = doc ================================================ FILE: picosdk/ps3000.py ================================================ # # Copyright (C) 2015-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps3000.h C header file for PicoScope 3000 Series oscilloscopes using the ps3000 driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.constants import make_enum class Ps3000lib(Library): def __init__(self): super(Ps3000lib, self).__init__("ps3000") ps3000 = Ps3000lib() ps3000.PS3000_CHANNEL = make_enum([ "PS3000_CHANNEL_A", "PS3000_CHANNEL_B", "PS3000_CHANNEL_C", "PS3000_CHANNEL_D", ]) # use the last character, i.e. the channel name: ps3000.PICO_CHANNEL = {k[-1]: v for k, v in ps3000.PS3000_CHANNEL.items()} # This field is passed to the driver as a boolean, not an enum. ps3000.PICO_COUPLING = { 'AC': 0, 'DC': 1 } ps3000.PS3000_VOLTAGE_RANGE = { 'PS3000_20MV': 1, 'PS3000_50MV': 2, 'PS3000_100MV': 3, 'PS3000_200MV': 4, 'PS3000_500MV': 5, 'PS3000_1V': 6, 'PS3000_2V': 7, 'PS3000_5V': 8, 'PS3000_10V': 9, 'PS3000_20V': 10, 'PS3000_50V': 11, 'PS3000_100V': 12, 'PS3000_200V': 13, 'PS3000_400V': 14, } # float voltage value max (multiplier for output voltages). Parse the value in the constant name. ps3000.PICO_VOLTAGE_RANGE = { v: float(k.split('_')[1][:-1]) if k[-2] != 'M' else (0.001 * float(k.split('_')[1][:-2])) for k, v in ps3000.PS3000_VOLTAGE_RANGE.items() } doc = """ int16_t ps3000_open_unit ( void ); """ ps3000.make_symbol("_open_unit", "ps3000_open_unit", c_int16, [], doc) doc = """ int16_t ps3000_get_unit_info ( int16_t handle, int8_t *string, int16_t string_length, int16_t line ); """ ps3000.make_symbol("_get_unit_info", "ps3000_get_unit_info", c_int16, [c_int16, c_char_p, c_int16, c_int16], doc) doc = """ int16_t ps3000_flash_led ( int16_t handle ); """ ps3000.make_symbol("_flash_led", "ps3000_flash_led", c_int16, [c_int16, ], doc) doc = """ int16_t ps3000_close_unit ( int16_t handle ); """ ps3000.make_symbol("_close_unit", "ps3000_close_unit", c_int16, [c_int16, ], doc) doc = """ int16_t ps3000_set_channel ( int16_t handle, int16_t channel, int16_t enabled, int16_t dc, int16_t range ); """ ps3000.make_symbol("_set_channel", "ps3000_set_channel", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t ps3000_get_timebase ( int16_t handle, int16_t timebase, int32_t no_of_samples, int32_t *time_interval, int16_t *time_units, int16_t oversample, int32_t *max_samples ); """ ps3000.make_symbol("_get_timebase", "ps3000_get_timebase", c_int16, [c_int16, c_int16, c_int32, c_void_p, c_void_p, c_int16, c_void_p], doc) doc = """ int32_t ps3000_set_siggen ( int16_t handle, int16_t wave_type, int32_t start_frequency, int32_t stop_frequency, float increment, int16_t dwell_time, int16_t repeat, int16_t dual_slope ); """ ps3000.make_symbol("_set_siggen", "ps3000_set_siggen", c_int32, [c_int16, c_int16, c_int32, c_int32, c_float, c_int16, c_int16, c_int16], doc) doc = """ int32_t ps3000_set_ets ( int16_t handle, int16_t mode, int16_t ets_cycles, int16_t ets_interleave ); """ ps3000.make_symbol("_set_ets", "ps3000_set_ets", c_int32, [c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t ps3000_set_trigger ( int16_t handle, int16_t source, int16_t threshold, int16_t direction, int16_t delay, int16_t auto_trigger_ms ); """ ps3000.make_symbol("_set_trigger", "ps3000_set_trigger", c_int16, [c_int16, c_int16, c_int16, c_int16, c_int16, c_int16], doc) doc = """ int16_t ps3000_set_trigger2 ( int16_t handle, int16_t source, int16_t threshold, int16_t direction, float delay, int16_t auto_trigger_ms ); """ ps3000.make_symbol("_set_trigger2", "ps3000_set_trigger2", c_int16, [c_int16, c_int16, c_int16, c_int16, c_float, c_int16], doc) doc = """ int16_t ps3000_run_block ( int16_t handle, int32_t no_of_values, int16_t timebase, int16_t oversample, int32_t * time_indisposed_ms ); """ ps3000.make_symbol("_run_block", "ps3000_run_block", c_int16, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ int16_t ps3000_run_streaming ( int16_t handle, int16_t sample_interval_ms, int32_t max_samples, int16_t windowed ); """ ps3000.make_symbol("_run_streaming", "ps3000_run_streaming", c_int16, [c_int16, c_int16, c_int32, c_int16], doc) doc = """ int16_t ps3000_run_streaming_ns ( int16_t handle, uint32_t sample_interval, PS3000_TIME_UNITS time_units, uint32_t max_samples, int16_t auto_stop, uint32_t noOfSamplesPerAggregate, uint32_t overview_buffer_size ); """ ps3000.make_symbol("_run_streaming_ns", "ps3000_run_streaming_ns", c_int16, [c_int16, c_uint32, c_int32, c_uint32, c_int16, c_uint32, c_uint32], doc) doc = """ int16_t ps3000_ready ( int16_t handle ); """ ps3000.make_symbol("_ready", "ps3000_ready", c_int16, [c_int16, ], doc) doc = """ int16_t ps3000_stop ( int16_t handle ); """ ps3000.make_symbol("_stop", "ps3000_stop", c_int16, [c_int16, ], doc) doc = """ int32_t ps3000_get_values ( int16_t handle, int16_t *buffer_a, int16_t *buffer_b, int16_t *buffer_c, int16_t *buffer_d, int16_t *overflow, int32_t no_of_values ); """ ps3000.make_symbol("_get_values", "ps3000_get_values", c_int32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_int32], doc) doc = """ void ps3000_release_stream_buffer ( int16_t handle ); """ ps3000.make_symbol("_release_stream_buffer", "ps3000_release_stream_buffer", None, [c_int16, ], doc) doc = """ int32_t ps3000_get_times_and_values ( int16_t handle, int32_t *times, int16_t *buffer_a, int16_t *buffer_b, int16_t *buffer_c, int16_t *buffer_d, int16_t *overflow, int16_t time_units, int32_t no_of_values ); """ ps3000.make_symbol("_get_times_and_values", "ps3000_get_times_and_values", c_int32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_int16, c_int32], doc) doc = """ int16_t ps3000_open_unit_async ( void ); """ ps3000.make_symbol("_open_unit_async", "ps3000_open_unit_async", c_int16, [], doc) doc = """ int16_t ps3000_open_unit_progress ( int16_t *handle, int16_t *progress_percent ); """ ps3000.make_symbol("_open_unit_progress", "ps3000_open_unit_progress", c_int16, [c_void_p, c_void_p], doc) doc = """ int16_t ps3000_streaming_ns_get_interval_stateless ( int16_t handle, int16_t nChannels, uint32_t *sample_interval ); """ ps3000.make_symbol("_streaming_ns_get_interval_stateless", "ps3000_streaming_ns_get_interval_stateless", c_int16, [c_int16, c_int16, c_void_p], doc) doc = """ int16_t ps3000_get_streaming_last_values ( int16_t handle, GetOverviewBuffersMaxMin ); """ ps3000.make_symbol("_get_streaming_last_values", "ps3000_get_streaming_last_values", c_int16, [c_int16, c_void_p], doc) doc = """ int16_t ps3000_overview_buffer_status ( int16_t handle, int16_t *previous_buffer_overrun ); """ ps3000.make_symbol("_overview_buffer_status", "ps3000_overview_buffer_status", c_int16, [c_int16, c_void_p], doc) doc = """ uint32_t ps3000_get_streaming_values ( int16_t handle, double *start_time, int16_t *pbuffer_a_max, int16_t *pbuffer_a_min, int16_t *pbuffer_b_max, int16_t *pbuffer_b_min, int16_t *pbuffer_c_max, int16_t *pbuffer_c_min, int16_t *pbuffer_d_max, int16_t *pbuffer_d_min, int16_t *overflow, uint32_t *triggerAt, int16_t *triggered, uint32_t no_of_values, uint32_t noOfSamplesPerAggregate ); """ ps3000.make_symbol("_get_streaming_values", "ps3000_get_streaming_values", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ uint32_t ps3000_get_streaming_values_no_aggregation ( int16_t handle, double *start_time, int16_t * pbuffer_a, int16_t * pbuffer_b, int16_t * pbuffer_c, int16_t * pbuffer_d, int16_t * overflow, uint32_t * triggerAt, int16_t * trigger, uint32_t no_of_values ); """ ps3000.make_symbol("_get_streaming_values_no_aggregation", "ps3000_get_streaming_values_no_aggregation", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32], doc) doc = """ int16_t ps3000_save_streaming_data ( int16_t handle, PS3000_CALLBACK_FUNC lpCallbackFunc, int16_t *dataBuffers, int16_t dataBufferSize ); """ ps3000.make_symbol("_save_streaming_data", "ps3000_save_streaming_data", c_int16, [c_int16, c_void_p, c_void_p, c_int16], doc) doc = """ int16_t ps3000SetAdvTriggerChannelProperties ( int16_t handle, PS3000_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int32_t autoTriggerMilliseconds ); """ ps3000.make_symbol("_SetAdvTriggerChannelProperties", "ps3000SetAdvTriggerChannelProperties", c_int16, [c_int16, c_void_p, c_int16, c_int32], doc) doc = """ int16_t ps3000SetAdvTriggerChannelConditions ( int16_t handle, PS3000_TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps3000.make_symbol("_SetAdvTriggerChannelConditions", "ps3000SetAdvTriggerChannelConditions", c_int16, [c_int16, c_void_p, c_int16], doc) doc = """ int16_t ps3000SetAdvTriggerChannelDirections ( int16_t handle, PS3000_THRESHOLD_DIRECTION channelA, PS3000_THRESHOLD_DIRECTION channelB, PS3000_THRESHOLD_DIRECTION channelC, PS3000_THRESHOLD_DIRECTION channelD, PS3000_THRESHOLD_DIRECTION ext ); """ ps3000.make_symbol("_SetAdvTriggerChannelDirections", "ps3000SetAdvTriggerChannelDirections", c_int16, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ int16_t ps3000SetPulseWidthQualifier ( int16_t handle, PS3000_PWQ_CONDITIONS *conditions, int16_t nConditions, PS3000_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS3000_PULSE_WIDTH_TYPE type ); """ ps3000.make_symbol("_SetPulseWidthQualifier", "ps3000SetPulseWidthQualifier", c_int16, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ int16_t ps3000SetAdvTriggerDelay ( int16_t handle, uint32_t delay, float preTriggerDelay ); """ ps3000.make_symbol("_SetAdvTriggerDelay", "ps3000SetAdvTriggerDelay", c_int16, [c_int16, c_uint32, c_float], doc) doc = """ int16_t ps3000PingUnit ( int16_t handle ); """ ps3000.make_symbol("_PingUnit", "ps3000PingUnit", c_int16, [c_int16, ], doc) ps3000.PICO_INFO = {k: v for k, v in ps3000.PICO_INFO.items() if v <= 0x00000005} ps3000.PICO_INFO["PICO_ERROR_CODE"] = 0x00000006 ================================================ FILE: picosdk/ps3000a.py ================================================ # # Copyright (C) 2014-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps3000aApi.h C header file for PicoScope 3000 Series oscilloscopes using the ps3000a driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class Ps3000alib(Library): def __init__(self): super(Ps3000alib, self).__init__("ps3000a") ps3000a = Ps3000alib() ps3000a.PS3000A_COUPLING = make_enum([ 'PS3000A_AC', 'PS3000A_DC', ]) # Just use AC and DC. ps3000a.PICO_COUPLING = {k[-2:]: v for k, v in ps3000a.PS3000A_COUPLING.items()} # A tuple in an enum like this is 2 names for the same value. ps3000a.PS3000A_CHANNEL = make_enum([ "PS3000A_CHANNEL_A", "PS3000A_CHANNEL_B", "PS3000A_CHANNEL_C", "PS3000A_CHANNEL_D", ("PS3000A_EXTERNAL", "PS3000A_MAX_CHANNELS"), "PS3000A_TRIGGER_AUX", "PS3000A_MAX_TRIGGER_SOURCE", ]) # only include the normal analog channels for now: ps3000a.PICO_CHANNEL = {k[-1]: v for k, v in ps3000a.PS3000A_CHANNEL.items() if "PS3000A_CHANNEL_" in k} ps3000a.PS3000A_RANGE = make_enum([ "PS3000A_10MV", "PS3000A_20MV", "PS3000A_50MV", "PS3000A_100MV", "PS3000A_200MV", "PS3000A_500MV", "PS3000A_1V", "PS3000A_2V", "PS3000A_5V", "PS3000A_10V", "PS3000A_20V", "PS3000A_50V", "PS3000A_MAX_RANGES", ]) ps3000a.PICO_VOLTAGE_RANGE = { v: float(k.split('_')[1][:-1]) if k[-2] != 'M' else (0.001 * float(k.split('_')[1][:-2])) for k, v in ps3000a.PS3000A_RANGE.items() if k != "PS3000A_MAX_RANGES" } ps3000a.PS3000A_RATIO_MODE = { 'PS3000A_RATIO_MODE_NONE': 0, 'PS3000A_RATIO_MODE_AGGREGATE': 1, 'PS3000A_RATIO_MODE_DECIMATE': 2, 'PS3000A_RATIO_MODE_AVERAGE': 4, } ps3000a.PS3000A_TIME_UNITS = make_enum([ 'PS3000A_FS', 'PS3000A_PS', 'PS3000A_NS', 'PS3000A_US', 'PS3000A_MS', 'PS3000A_S', 'PS3000A_MAX_TIME_UNITS', ]) ps3000a.PS3000A_DIGITAL_CHANNEL = make_enum([ "PS3000A_DIGITAL_CHANNEL_0", "PS3000A_DIGITAL_CHANNEL_1", "PS3000A_DIGITAL_CHANNEL_2", "PS3000A_DIGITAL_CHANNEL_3", "PS3000A_DIGITAL_CHANNEL_4", "PS3000A_DIGITAL_CHANNEL_5", "PS3000A_DIGITAL_CHANNEL_6", "PS3000A_DIGITAL_CHANNEL_7", "PS3000A_DIGITAL_CHANNEL_8", "PS3000A_DIGITAL_CHANNEL_9", "PS3000A_DIGITAL_CHANNEL_10", "PS3000A_DIGITAL_CHANNEL_11", "PS3000A_DIGITAL_CHANNEL_12", "PS3000A_DIGITAL_CHANNEL_13", "PS3000A_DIGITAL_CHANNEL_14", "PS3000A_DIGITAL_CHANNEL_15", "PS3000A_DIGITAL_CHANNEL_16", "PS3000A_DIGITAL_CHANNEL_17", "PS3000A_DIGITAL_CHANNEL_18", "PS3000A_DIGITAL_CHANNEL_19", "PS3000A_DIGITAL_CHANNEL_20", "PS3000A_DIGITAL_CHANNEL_21", "PS3000A_DIGITAL_CHANNEL_22", "PS3000A_DIGITAL_CHANNEL_23", "PS3000A_DIGITAL_CHANNEL_24", "PS3000A_DIGITAL_CHANNEL_25", "PS3000A_DIGITAL_CHANNEL_26", "PS3000A_DIGITAL_CHANNEL_27", "PS3000A_DIGITAL_CHANNEL_28", "PS3000A_DIGITAL_CHANNEL_29", "PS3000A_DIGITAL_CHANNEL_30", "PS3000A_DIGITAL_CHANNEL_31", "PS3000A_MAX_DIGITAL_CHANNELS" ]) ps3000a.PS3000A_DIGITAL_DIRECTION = make_enum([ "PS3000A_DIGITAL_DONT_CARE", "PS3000A_DIGITAL_DIRECTION_LOW", "PS3000A_DIGITAL_DIRECTION_HIGH", "PS3000A_DIGITAL_DIRECTION_RISING", "PS3000A_DIGITAL_DIRECTION_FALLING", "PS3000A_DIGITAL_DIRECTION_RISING_OR_FALLING", "PS3000A_DIGITAL_MAX_DIRECTION" ]) def _define_digital_port(): PS3000A_DIGITAL_PORT0 = 0x80 PS3000A_DIGITAL_PORT1 = PS3000A_DIGITAL_PORT0 + 1 PS3000A_DIGITAL_PORT2 = PS3000A_DIGITAL_PORT0 + 2 PS3000A_DIGITAL_PORT3 = PS3000A_DIGITAL_PORT0 + 3 PS3000A_MAX_DIGITAL_PORTS = (PS3000A_DIGITAL_PORT3 - PS3000A_DIGITAL_PORT0) + 1 return {k.upper(): v for k, v in locals().items() if k.startswith("PS3000A")} ps3000a.PS3000A_DIGITAL_PORT = _define_digital_port() ps3000a.PS3000A_TRIGGER_STATE = make_enum([ "PS3000A_CONDITION_DONT_CARE", "PS3000A_CONDITION_TRUE", "PS3000A_CONDITION_FALSE", "PS3000A_CONDITION_MAX" ]) ps3000a.PS3000A_THRESHOLD_DIRECTION = make_enum([ ("PS3000A_ABOVE", "PS3000A_INSIDE"), ("PS3000A_BELOW", "PS3000A_OUTSIDE","PS3000A_NONE"), ("PS3000A_RISING", "PS3000A_ENTER"), ("PS3000A_FALLING", "PS3000A_EXIT"), ("PS3000A_RISING_OR_FALLING", "PS3000A_ENTER_OR_EXIT"), "PS3000A_ABOVE_LOWER", "PS3000A_BELOW_LOWER", "PS3000A_RISING_LOWER", "PS3000A_FALLING_LOWER", "PS3000A_POSITIVE_RUNT", "PS3000A_NEGATIVE_RUNT" ]) ps3000a.PS3000A_THRESHOLD_MODE = make_enum([ "PS3000A_LEVEL", "PS3000A_WINDOW" ]) class PS3000A_DIGITAL_CHANNEL_DIRECTIONS(Structure): _pack_ = 1 _fields_ = [("channel", c_int32), ("direction", c_int32)] ps3000a.PS3000A_DIGITAL_CHANNEL_DIRECTIONS = PS3000A_DIGITAL_CHANNEL_DIRECTIONS class PS3000A_TRIGGER_CONDITIONS(Structure): _pack_ = 1 _fields_ = [("channelA", c_uint32), ("channelB", c_uint32), ("channelC", c_uint32), ("channelD", c_uint32), ("external", c_uint32), ("aux", c_uint32), ("pulseWidthQualifier", c_uint32)] ps3000a.PS3000A_TRIGGER_CONDITIONS = PS3000A_TRIGGER_CONDITIONS class PS3000A_TRIGGER_CONDITIONS_V2(Structure): _pack_ = 1 _fields_ = [("channelA", c_uint32), ("channelB", c_uint32), ("channelC", c_uint32), ("channelD", c_uint32), ("external", c_uint32), ("aux", c_uint32), ("pulseWidthQualifier", c_uint32), ("digital", c_uint32)] ps3000a.PS3000A_TRIGGER_CONDITIONS_V2 = PS3000A_TRIGGER_CONDITIONS_V2 class PS3000A_TRIGGER_CHANNEL_PROPERTIES(Structure): _pack_ = 1 _fields_ = [("thresholdUpper", c_int16), ("thresholdUpperHysteresis", c_uint16), ("thresholdLower", c_int16), ("thresholdLowerHysteresis", c_uint16), ("channel", c_uint32), ("thresholdMode", c_uint32)] ps3000a.PS3000A_TRIGGER_CHANNEL_PROPERTIES = PS3000A_TRIGGER_CHANNEL_PROPERTIES doc = """ PICO_STATUS ps3000aOpenUnit ( int16_t *handle, int8_t *serial ); """ ps3000a.make_symbol("_OpenUnit", "ps3000aOpenUnit", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps3000aOpenUnitAsync ( int16_t *status, int8_t *serial ); """ ps3000a.make_symbol("_OpenUnitAsync", "ps3000aOpenUnitAsync", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps3000aOpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps3000a.make_symbol("_OpenUnitProgress", "ps3000aOpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps3000a.make_symbol("_GetUnitInfo", "ps3000aGetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps3000aFlashLed ( int16_t handle, int16_t start ); """ ps3000a.make_symbol("_FlashLed", "ps3000aFlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps3000aCloseUnit ( int16_t handle ); """ ps3000a.make_symbol("_CloseUnit", "ps3000aCloseUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps3000aMemorySegments ( int16_t handle, uint32_t nSegments, int32_t *nMaxSamples ); """ ps3000a.make_symbol("_MemorySegments", "ps3000aMemorySegments", c_uint32, [c_int16, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps3000aSetChannel ( int16_t handle, PS3000a_CHANNEL channel, int16_t enabled, PS3000a_COUPLING type, PS3000a_RANGE range, float analogOffset ); """ ps3000a.make_symbol("_SetChannel", "ps3000aSetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int32, c_float], doc) doc = """ PICO_STATUS ps3000aSetDigitalPort ( int16_t handle, PS3000a_DIGITAL_PORT port, int16_t enabled, int16_t logicLevel ); """ ps3000a.make_symbol("_SetDigitalPort", "ps3000aSetDigitalPort", c_uint32, [c_int16, c_int32, c_int16, c_int16], doc) doc = """ PICO_STATUS ps3000aSetBandwidthFilter ( int16_t handle, PS3000A_CHANNEL channel, PS3000A_BANDWIDTH_LIMITER bandwidth ); """ ps3000a.make_symbol("_SetBandwidthFilter", "ps3000aSetBandwidthFilter", c_uint32, [c_int16, c_int32, c_int32], doc) doc = """ PICO_STATUS ps3000aSetNoOfCaptures ( int16_t handle, uint32_t nCaptures ); """ ps3000a.make_symbol("_SetNoOfCaptures", "ps3000aSetNoOfCaptures", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps3000aGetTimebase ( int16_t handle, uint32_t timebase, int32_t noSamples, int32_t *timeIntervalNanoseconds, int16_t oversample, int32_t *maxSamples, uint32_t segmentIndex ); """ ps3000a.make_symbol("_GetTimebase", "ps3000aGetTimebase", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps3000aGetTimebase2 ( int16_t handle, uint32_t timebase, int32_t noSamples, float *timeIntervalNanoseconds, int16_t oversample, int32_t *maxSamples, uint32_t segmentIndex ); """ ps3000a.make_symbol("_GetTimebase2", "ps3000aGetTimebase2", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps3000aSetSigGenArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, int16_t *arbitraryWaveform, int32_t arbitraryWaveformSize, PS3000A_SWEEP_TYPE sweepType, PS3000A_EXTRA_OPERATIONS operation, PS3000A_INDEX_MODE indexMode, uint32_t shots, uint32_t sweeps, PS3000A_SIGGEN_TRIG_TYPE triggerType, PS3000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps3000a.make_symbol("_SetSigGenArbitrary", "ps3000aSetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps3000aSetSigGenBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t waveType, float startFrequency, float stopFrequency, float increment, float dwellTime, PS3000A_SWEEP_TYPE sweepType, PS3000A_EXTRA_OPERATIONS operation, uint32_t shots, uint32_t sweeps, PS3000A_SIGGEN_TRIG_TYPE triggerType, PS3000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps3000a.make_symbol("_SetSigGenBuiltIn", "ps3000aSetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_float, c_float, c_float, c_float, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps3000aSetSigGenPropertiesArbitrary ( int16_t handle, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, PS3000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS3000A_SIGGEN_TRIG_TYPE triggerType, PS3000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps3000a.make_symbol("_SetSigGenPropertiesArbitrary", "ps3000aSetSigGenPropertiesArbitrary", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps3000aSetSigGenPropertiesBuiltIn ( int16_t handle, double startFrequency, double stopFrequency, double increment, double dwellTime, PS3000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS3000A_SIGGEN_TRIG_TYPE triggerType, PS3000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps3000a.make_symbol("_SetSigGenPropertiesBuiltIn", "ps3000aSetSigGenPropertiesBuiltIn", c_uint32, [c_int16, c_double, c_double, c_double, c_double, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps3000aSigGenFrequencyToPhase ( int16_t handle, double frequency, PS3000A_INDEX_MODE indexMode, uint32_t bufferLength, uint32_t *phase ); """ ps3000a.make_symbol("_SigGenFrequencyToPhase", "ps3000aSigGenFrequencyToPhase", c_uint32, [c_int16, c_double, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps3000aSigGenArbitraryMinMaxValues ( int16_t handle, int16_t *minArbitraryWaveformValue, int16_t *maxArbitraryWaveformValue, uint32_t *minArbitraryWaveformSize, uint32_t *maxArbitraryWaveformSize ); """ ps3000a.make_symbol("_SigGenArbitraryMinMaxValues", "ps3000aSigGenArbitraryMinMaxValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetMaxEtsValues ( int16_t handle, int16_t *etsCycles, int16_t *etsInterleave ); """ ps3000a.make_symbol("_GetMaxEtsValues", "ps3000aGetMaxEtsValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aSigGenSoftwareControl ( int16_t handle, int16_t state ); """ ps3000a.make_symbol("_SigGenSoftwareControl", "ps3000aSigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps3000aSetEts ( int16_t handle, PS3000A_ETS_MODE mode, int16_t etsCycles, int16_t etsInterleave, int32_t *sampleTimePicoseconds ); """ ps3000a.make_symbol("_SetEts", "ps3000aSetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aSetSimpleTrigger ( int16_t handle, int16_t enable, PS3000A_CHANNEL source, int16_t threshold, PS3000A_THRESHOLD_DIRECTION direction, uint32_t delay, int16_t autoTrigger_ms ); """ ps3000a.make_symbol("_SetSimpleTrigger", "ps3000aSetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps3000aSetTriggerDigitalPortProperties ( int16_t handle, PS3000A_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps3000a.make_symbol("_SetTriggerDigitalPortProperties", "ps3000aSetTriggerDigitalPortProperties", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps3000aSetPulseWidthDigitalPortProperties ( int16_t handle, PS3000A_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps3000a.make_symbol("_SetPulseWidthDigitalPortProperties", "ps3000aSetPulseWidthDigitalPortProperties", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps3000aSetTriggerChannelProperties ( int16_t handle, PS3000A_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, int32_t autoTriggerMilliseconds ); """ ps3000a.make_symbol("_SetTriggerChannelProperties", "ps3000aSetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps3000aSetTriggerChannelConditions ( int16_t handle, PS3000A_TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps3000a.make_symbol("_SetTriggerChannelConditions", "ps3000aSetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps3000aSetTriggerChannelConditionsV2 ( int16_t handle, PS3000A_TRIGGER_CONDITIONS_V2 *conditions, int16_t nConditions ); """ ps3000a.make_symbol("_SetTriggerChannelConditionsV2", "ps3000aSetTriggerChannelConditionsV2", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps3000aSetTriggerChannelDirections ( int16_t handle, PS3000A_THRESHOLD_DIRECTION channelA, PS3000A_THRESHOLD_DIRECTION channelB, PS3000A_THRESHOLD_DIRECTION channelC, PS3000A_THRESHOLD_DIRECTION channelD, PS3000A_THRESHOLD_DIRECTION ext, PS3000A_THRESHOLD_DIRECTION aux ); """ ps3000a.make_symbol("_SetTriggerChannelDirections", "ps3000aSetTriggerChannelDirections", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps3000aSetTriggerDelay ( int16_t handle, uint32_t delay ); """ ps3000a.make_symbol("_SetTriggerDelay", "ps3000aSetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps3000aSetPulseWidthQualifier ( int16_t handle, PS3000A_PWQ_CONDITIONS *conditions, int16_t nConditions, PS3000A_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS3000A_PULSE_WIDTH_TYPE type ); """ ps3000a.make_symbol("_SetPulseWidthQualifier", "ps3000aSetPulseWidthQualifier", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps3000aSetPulseWidthQualifierV2 ( int16_t handle, PS3000A_PWQ_CONDITIONS_V2 *conditions, int16_t nConditions, PS3000A_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS3000A_PULSE_WIDTH_TYPE type ); """ ps3000a.make_symbol("_SetPulseWidthQualifierV2", "ps3000aSetPulseWidthQualifierV2", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps3000aIsTriggerOrPulseWidthQualifierEnabled ( int16_t handle, int16_t *triggerEnabled, int16_t *pulseWidthQualifierEnabled ); """ ps3000a.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps3000aIsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetTriggerTimeOffset64 ( int16_t handle, int64_t *time, PS3000A_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps3000a.make_symbol("_GetTriggerTimeOffset", "ps3000aGetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps3000aGetValuesTriggerTimeOffsetBulk64 ( int16_t handle, int64_t *times, PS3000A_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps3000a.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps3000aGetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps3000aGetNoOfCaptures ( int16_t handle, uint32_t *nCaptures ); """ ps3000a.make_symbol("_GetNoOfCaptures", "ps3000aGetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetNoOfProcessedCaptures ( int16_t handle, uint32_t *nProcessedCaptures ); """ ps3000a.make_symbol("_GetNoOfProcessedCaptures", "ps3000aGetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aSetDataBuffer ( int16_t handle, int32_t channelOrPort, int16_t *buffer, int32_t bufferLth, uint32_t segmentIndex, PS3000a_RATIO_MODE mode ); """ ps3000a.make_symbol("_SetDataBuffer", "ps3000aSetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps3000aSetDataBuffers ( int16_t handle, int32_t channelOrPort, int16_t *bufferMax, int16_t *bufferMin, int32_t bufferLth, uint32_t segmentIndex, PS3000a_RATIO_MODE mode ); """ ps3000a.make_symbol("_SetDataBuffers", "ps3000aSetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps3000aSetEtsTimeBuffer ( int16_t handle, int64_t *buffer, int32_t bufferLth ); """ ps3000a.make_symbol("_SetEtsTimeBuffer", "ps3000aSetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps3000aIsReady ( int16_t handle, int16_t *ready ); """ ps3000a.make_symbol("_IsReady", "ps3000aIsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aRunBlock ( int16_t handle, int32_t noOfPreTriggerSamples, int32_t noOfPostTriggerSamples, uint32_t timebase, int16_t oversample, int32_t *timeIndisposedMs, uint32_t segmentIndex, ps3000aBlockReady lpReady, void *pParameter ); """ ps3000a.make_symbol("_RunBlock", "ps3000aRunBlock", c_uint32, [c_int16, c_int32, c_int32, c_uint32, c_int16, c_void_p, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aRunStreaming ( int16_t handle, uint32_t *sampleInterval, PS3000A_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostPreTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, PS3000A_RATIO_MODE downSampleRatioMode, uint32_t overviewBufferSize ); """ ps3000a.make_symbol("_RunStreaming", "ps3000aRunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps3000aGetStreamingLatestValues ( int16_t handle, ps3000aStreamingReady lpPs3000aReady, void *pParameter ); """ ps3000a.make_symbol("_GetStreamingLatestValues", "ps3000aGetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ void *ps3000aStreamingReady ( int16_t handle, int32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void *pParameter ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps3000a.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps3000a.StreamingReadyType.__doc__ = doc doc = """ PICO_STATUS ps3000aNoOfStreamingValues ( int16_t handle, uint32_t *noOfValues ); """ ps3000a.make_symbol("_NoOfStreamingValues", "ps3000aNoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetMaxDownSampleRatio ( int16_t handle, uint32_t noOfUnaggreatedSamples, uint32_t *maxDownSampleRatio, PS3000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex ); """ ps3000a.make_symbol("_GetMaxDownSampleRatio", "ps3000aGetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps3000aGetValues ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS3000a_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps3000a.make_symbol("_GetValues", "ps3000aGetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetValuesBulk ( int16_t handle, uint32_t *noOfSamples, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, uint32_t downSampleRatio, PS3000A_RATIO_MODE downSampleRatioMode, int16_t *overflow ); """ ps3000a.make_symbol("_GetValuesBulk", "ps3000aGetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32, c_uint32, c_int32, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetValuesAsync ( int16_t handle, uint32_t startIndex, uint32_t noOfSamples, uint32_t downSampleRatio, PS3000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, void *lpDataReady, void *pParameter ); """ ps3000a.make_symbol("_GetValuesAsync", "ps3000aGetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetValuesOverlapped ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS3000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps3000a.make_symbol("_GetValuesOverlapped", "ps3000aGetValuesOverlapped", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetValuesOverlappedBulk ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS3000A_RATIO_MODE downSampleRatioMode, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, int16_t *overflow ); """ ps3000a.make_symbol("_GetValuesOverlappedBulk", "ps3000aGetValuesOverlappedBulk", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetTriggerInfoBulk ( int16_t handle, PS3000A_TRIGGER_INFO *triggerInfo, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps3000a.make_symbol("_GetTriggerInfoBulk", "ps3000aGetTriggerInfoBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps3000aStop ( int16_t handle ); """ ps3000a.make_symbol("_Stop", "ps3000aStop", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps3000aHoldOff ( int16_t handle, uint64_t holdoff, PS3000A_HOLDOFF_TYPE type ); """ ps3000a.make_symbol("_HoldOff", "ps3000aHoldOff", c_uint32, [c_int16, c_uint64, c_int32], doc) doc = """ PICO_STATUS ps3000aGetChannelInformation ( int16_t handle, PS3000A_CHANNEL_INFO info, int32_t probe, int32_t *ranges, int32_t *length, int32_t channels ); """ ps3000a.make_symbol("_GetChannelInformation", "ps3000aGetChannelInformation", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps3000aEnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps3000a.make_symbol("_EnumerateUnits", "ps3000aEnumerateUnits", c_uint32, [c_void_p, c_char_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aPingUnit ( int16_t handle ); """ ps3000a.make_symbol("_PingUnit", "ps3000aPingUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps3000aMaximumValue ( int16_t handle, int16_t *value ); """ ps3000a.make_symbol("_MaximumValue", "ps3000aMaximumValue", c_uint32, [c_int16, c_void_p], doc) doc = """" PICO_STATUS ps3000aMinimumValue ( int16_t handle, int16_t *value ); """ ps3000a.make_symbol("_MinimumValue", "ps3000aMinimumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetAnalogueOffset ( int16_t handle, PS3000A_RANGE range, PS3000A_COUPLING coupling, float *maximumVoltage, float *minimumVoltage ); """ ps3000a.make_symbol("_GetAnalogueOffset", "ps3000aGetAnalogueOffset", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps3000aGetMaxSegments ( int16_t handle, uint32_t *maxSegments ); """ ps3000a.make_symbol("_GetMaxSegments", "ps3000aGetMaxSegments", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps3000aChangePowerSource ( int16_t handle, PICO_STATUS powerState ); """ ps3000a.make_symbol("_ChangePowerSource", "ps3000aChangePowerSource", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps3000aCurrentPowerSource ( int16_t handle ); """ ps3000a.make_symbol("_CurrentPowerSource", "ps3000aCurrentPowerSource", c_uint32, [c_int16, c_uint32], doc) ps3000a.INI_LOGIC_VOLTS = 1.5 ================================================ FILE: picosdk/ps4000.py ================================================ # # Copyright (C) 2015-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps4000Api.h C header file for PicoScope 4000 Series oscilloscopes using the ps4000 driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class Ps4000lib(Library): def __init__(self): super(Ps4000lib, self).__init__("ps4000") ps4000 = Ps4000lib() # This field is passed to the driver as a boolean, not an enum. ps4000.PICO_COUPLING = { 'AC': 0, 'DC': 1 } # A tuple in an enum like this is 2 names for the same value. ps4000.PS4000_CHANNEL = make_enum([ "PS4000_CHANNEL_A", "PS4000_CHANNEL_B", "PS4000_CHANNEL_C", "PS4000_CHANNEL_D", ("PS4000_EXTERNAL", "PS4000_MAX_CHANNELS"), "PS4000_TRIGGER_AUX", "PS4000_MAX_TRIGGER_SOURCE", ]) # only include the normal analog channels for now: ps4000.PICO_CHANNEL = {k[-1]: v for k, v in ps4000.PS4000_CHANNEL.items() if "PS4000_CHANNEL_" in k} ps4000.PS4000_RANGE = make_enum([ "PS4000_10MV", "PS4000_20MV", "PS4000_50MV", "PS4000_100MV", "PS4000_200MV", "PS4000_500MV", "PS4000_1V", "PS4000_2V", "PS4000_5V", "PS4000_10V", "PS4000_20V", "PS4000_50V", "PS4000_100V", ("PS4000_RESISTANCE_100R", "PS4000_MAX_RANGES"), "PS4000_RESISTANCE_1K", "PS4000_RESISTANCE_10K", "PS4000_RESISTANCE_100K", "PS4000_RESISTANCE_1M", ("PS4000_ACCELEROMETER_10MV", "PS4000_MAX_RESISTANCES"), "PS4000_ACCELEROMETER_20MV", "PS4000_ACCELEROMETER_50MV", "PS4000_ACCELEROMETER_100MV", "PS4000_ACCELEROMETER_200MV", "PS4000_ACCELEROMETER_500MV", "PS4000_ACCELEROMETER_1V", "PS4000_ACCELEROMETER_2V", "PS4000_ACCELEROMETER_5V", "PS4000_ACCELEROMETER_10V", "PS4000_ACCELEROMETER_20V", "PS4000_ACCELEROMETER_50V", "PS4000_ACCELEROMETER_100V", ("PS4000_TEMPERATURE_UPTO_40", "PS4000_MAX_ACCELEROMETER"), "PS4000_TEMPERATURE_UPTO_70", "PS4000_TEMPERATURE_UPTO_100", "PS4000_TEMPERATURE_UPTO_130", ("PS4000_RESISTANCE_5K", "PS4000_MAX_TEMPERATURES"), "PS4000_RESISTANCE_25K", "PS4000_RESISTANCE_50K", "PS4000_MAX_EXTRA_RESISTANCES", ]) def process_enum(enum): """The PS4000 range enum is complicated enough that we need some clearer logic:""" import re pattern = re.compile(r'PS4000_([0-9]+M?)V') voltage_range = {} for enum_item_name, enum_item_value in enum.items(): match = pattern.match(enum_item_name) if match is None: continue voltage_string = match.group(1) voltage = float(voltage_string) if voltage_string[-1] != 'M' else (0.001 * float(voltage_string[:-1])) voltage_range[enum_item_value] = voltage return voltage_range ps4000.PICO_VOLTAGE_RANGE = process_enum(ps4000.PS4000_RANGE) ps4000.PS4000_TIME_UNITS = make_enum([ 'PS4000_FS', 'PS4000_PS', 'PS4000_NS', 'PS4000_US', 'PS4000_MS', 'PS4000_S', 'PS4000_MAX_TIME_UNITS', ]) doc = """ PICO_STATUS ps4000OpenUnit ( int16_t *handle ); """ ps4000.make_symbol("_OpenUnit0", "ps4000OpenUnit", c_uint32, [c_void_p, ], doc) doc = """ PICO_STATUS ps4000OpenUnitAsync ( int16_t *status ); """ ps4000.make_symbol("_OpenUnitAsync0", "ps4000OpenUnitAsync", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS ps4000OpenUnitEx ( int16_t *handle, int8_t *serial ); """ ps4000.make_symbol("_OpenUnit", "ps4000OpenUnitEx", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps4000OpenUnitAsyncEx ( int16_t *status, int8_t *serial ); """ ps4000.make_symbol("_OpenUnitAsync", "ps4000OpenUnitAsync", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps4000OpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps4000.make_symbol("_OpenUnitProgress", "ps4000OpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000GetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps4000.make_symbol("_GetUnitInfo", "ps4000GetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps4000FlashLed ( int16_t handle, int16_t start ); """ ps4000.make_symbol("_FlashLed", "ps4000FlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000IsLedFlashing ( int16_t handle, int16_t *status ); """ ps4000.make_symbol("_IsLedFlashing", "ps4000IsLedFlashing", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000CloseUnit ( int16_t handle ); """ ps4000.make_symbol("_CloseUnit", "ps4000CloseUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000MemorySegments ( int16_t handle, uint16_t nSegments, int32_t *nMaxSamples ); """ ps4000.make_symbol("_MemorySegments", "ps4000MemorySegments", c_uint32, [c_int16, c_uint16, c_void_p], doc) doc = """ PICO_STATUS ps4000SetChannel ( int16_t handle, PS4000_CHANNEL channel, int16_t enabled, int16_t dc, PS4000_RANGE range ); """ ps4000.make_symbol("_SetChannel", "ps4000SetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000SetNoOfCaptures ( int16_t handle, uint16_t nCaptures ); """ ps4000.make_symbol("_SetNoOfCaptures", "ps4000SetNoOfCaptures", c_uint32, [c_int16, c_uint16], doc) doc = """ PICO_STATUS ps4000GetTimebase ( int16_t handle, uint32_t timebase, int32_t noSamples, int32_t *timeIntervalNanoseconds, int16_t oversample, int32_t *maxSamples, uint16_t segmentIndex ); """ ps4000.make_symbol("_GetTimebase", "ps4000GetTimebase", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps4000GetTimebase2 ( int16_t handle, uint32_t timebase, int32_t noSamples, float *timeIntervalNanoseconds, int16_t oversample, int32_t *maxSamples, uint16_t segmentIndex ); """ ps4000.make_symbol("_GetTimebase2", "ps4000GetTimebase2", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps4000SigGenOff ( int16_t handle ); """ ps4000.make_symbol("_SigGenOff", "ps4000SigGenOff", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000SetSigGenArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, int16_t *arbitraryWaveform, int32_t arbitraryWaveformSize, SWEEP_TYPE sweepType, int16_t operationType, INDEX_MODE indexMode, uint32_t shots, uint32_t sweeps, SIGGEN_TRIG_TYPE triggerType, SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps4000.make_symbol("_SetSigGenArbitrary", "ps4000SetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int16, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000SetSigGenBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t waveType, float startFrequency, float stopFrequency, float increment, float dwellTime, SWEEP_TYPE sweepType, int16_t operationType, uint32_t shots, uint32_t sweeps, SIGGEN_TRIG_TYPE triggerType, SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps4000.make_symbol("_SetSigGenBuiltIn", "ps4000SetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_float, c_float, c_float, c_float, c_int32, c_int16, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000SigGenFrequencyToPhase ( int16_t handle, double frequency, INDEX_MODE indexMode, uint32_t bufferLength, uint32_t *phase ); """ ps4000.make_symbol("_SigGenFrequencyToPhase", "ps4000SigGenFrequencyToPhase", c_uint32, [c_int16, c_double, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps4000SigGenArbitraryMinMaxValues ( int16_t handle, int16_t *minArbitraryWaveformValue, int16_t *maxArbitraryWaveformValue, uint32_t *minArbitraryWaveformSize, uint32_t *maxArbitraryWaveformSize ); """ ps4000.make_symbol("_SigGenArbitraryMinMaxValues", "ps4000SigGenArbitraryMinMaxValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000SigGenSoftwareControl ( int16_t handle, int16_t state ); """ ps4000.make_symbol("_SigGenSoftwareControl", "ps4000SigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000SetEts ( int16_t handle, PS4000_ETS_MODE mode, int16_t etsCycles, int16_t etsInterleave, int32_t *sampleTimePicoseconds ); """ ps4000.make_symbol("_SetEts", "ps4000SetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000SetSimpleTrigger ( int16_t handle, int16_t enable, PS4000_CHANNEL source, int16_t threshold, THRESHOLD_DIRECTION direction, uint32_t delay, int16_t autoTrigger_ms ); """ ps4000.make_symbol("_SetSimpleTrigger", "ps4000SetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps4000SetTriggerChannelProperties ( int16_t handle, TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, int32_t autoTriggerMilliseconds ); """ ps4000.make_symbol("_SetTriggerChannelProperties", "ps4000SetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000SetExtTriggerRange ( int16_t handle, PS4000_RANGE extRange ); """ ps4000.make_symbol("_SetExtTriggerRange", "ps4000SetExtTriggerRange", c_uint32, [c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000SetTriggerChannelConditions ( int16_t handle, TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps4000.make_symbol("_SetTriggerChannelConditions", "ps4000SetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps4000SetTriggerChannelDirections ( int16_t handle, THRESHOLD_DIRECTION channelA, THRESHOLD_DIRECTION channelB, THRESHOLD_DIRECTION channelC, THRESHOLD_DIRECTION channelD, THRESHOLD_DIRECTION ext, THRESHOLD_DIRECTION aux ); """ ps4000.make_symbol("_SetTriggerChannelDirections", "ps4000SetTriggerChannelDirections", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps4000SetTriggerDelay ( int16_t handle, uint32_t delay ); """ ps4000.make_symbol("_SetTriggerDelay", "ps4000SetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps4000SetPulseWidthQualifier ( int16_t handle, PWQ_CONDITIONS *conditions, int16_t nConditions, THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PULSE_WIDTH_TYPE type ); """ ps4000.make_symbol("_SetPulseWidthQualifier", "ps4000SetPulseWidthQualifier", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps4000IsTriggerOrPulseWidthQualifierEnabled ( int16_t handle, int16_t *triggerEnabled, int16_t *pulseWidthQualifierEnabled ); """ ps4000.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps4000IsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000GetTriggerTimeOffset ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, PS4000_TIME_UNITS *timeUnits, uint16_t segmentIndex ); """ ps4000.make_symbol("_GetTriggerTimeOffset0", "ps4000GetTriggerTimeOffset", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps4000GetTriggerChannelTimeOffset ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, PS4000_TIME_UNITS *timeUnits, uint16_t segmentIndex, PS4000_CHANNEL channel ); """ ps4000.make_symbol("_GetTriggerChannelTimeOffset0", "ps4000GetTriggerChannelTimeOffset", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint16, c_int32], doc) doc = """ PICO_STATUS ps4000GetTriggerTimeOffset64 ( int16_t handle, int64_t *time, PS4000_TIME_UNITS *timeUnits, uint16_t segmentIndex ); """ ps4000.make_symbol("_GetTriggerTimeOffset", "ps4000GetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps4000GetTriggerChannelTimeOffset64 ( int16_t handle, int64_t *time, PS4000_TIME_UNITS *timeUnits, uint16_t segmentIndex, PS4000_CHANNEL channel ); """ ps4000.make_symbol("_GetTriggerChannelTimeOffset64", "ps4000GetTriggerChannelTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint16, c_int32], doc) doc = """ PICO_STATUS ps4000GetValuesTriggerTimeOffsetBulk ( int16_t handle, uint32_t *timesUpper, uint32_t *timesLower, PS4000_TIME_UNITS *timeUnits, uint16_t fromSegmentIndex, uint16_t toSegmentIndex ); """ ps4000.make_symbol("_GetValuesTriggerTimeOffsetBulk0", "ps4000GetValuesTriggerTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint16, c_uint16], doc) doc = """ PICO_STATUS ps4000GetValuesTriggerChannelTimeOffsetBulk ( int16_t handle, uint32_t *timesUpper, uint32_t *timesLower, PS4000_TIME_UNITS *timeUnits, uint16_t fromSegmentIndex, uint16_t toSegmentIndex, PS4000_CHANNEL channel ); """ ps4000.make_symbol("_GetValuesTriggerChannelTimeOffsetBulk0", "ps4000GetValuesTriggerChannelTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint16, c_uint16, c_int32], doc) doc = """ PICO_STATUS ps4000GetValuesTriggerTimeOffsetBulk64 ( int16_t handle, int64_t *times, PS4000_TIME_UNITS *timeUnits, uint16_t fromSegmentIndex, uint16_t toSegmentIndex ); """ ps4000.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps4000GetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint16, c_uint16], doc) doc = """ PICO_STATUS ps4000GetValuesTriggerChannelTimeOffsetBulk64 ( int16_t handle, int64_t *times, PS4000_TIME_UNITS *timeUnits, uint16_t fromSegmentIndex, uint16_t toSegmentIndex, PS4000_CHANNEL channel ); """ ps4000.make_symbol("_GetValuesTriggerChannelTimeOffsetBulk", "ps4000GetValuesTriggerChannelTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint16, c_uint16, c_int32], doc) doc = """ PICO_STATUS ps4000SetDataBufferBulk ( int16_t handle, PS4000_CHANNEL channel, int16_t *buffer, int32_t bufferLth, uint16_t waveform ); """ ps4000.make_symbol("_SetDataBufferBulk", "ps4000SetDataBufferBulk", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_uint16], doc) doc = """ PICO_STATUS ps4000SetDataBuffers ( int16_t handle, PS4000_CHANNEL channel, int16_t *bufferMax, int16_t *bufferMin, int32_t bufferLth ); """ ps4000.make_symbol("_SetDataBuffers", "ps4000SetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000SetDataBufferWithMode ( int16_t handle, PS4000_CHANNEL channel, int16_t *buffer, int32_t bufferLth, RATIO_MODE mode ); """ ps4000.make_symbol("_SetDataBufferWithMode", "ps4000SetDataBufferWithMode", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_int32], doc) doc = """ PICO_STATUS ps4000SetDataBuffersWithMode ( int16_t handle, PS4000_CHANNEL channel, int16_t *bufferMax, int16_t *bufferMin, int32_t bufferLth, RATIO_MODE mode ); """ ps4000.make_symbol("_SetDataBuffersWithMode", "ps4000SetDataBuffersWithMode", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32, c_int32], doc) doc = """ PICO_STATUS ps4000SetDataBuffer ( int16_t handle, PS4000_CHANNEL channel, int16_t *buffer, int32_t bufferLth ); """ ps4000.make_symbol("_SetDataBuffer", "ps4000SetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000SetEtsTimeBuffer ( int16_t handle, int64_t *buffer, int32_t bufferLth ); """ ps4000.make_symbol("_SetEtsTimeBuffer", "ps4000SetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000SetEtsTimeBuffers ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, int32_t bufferLth ); """ ps4000.make_symbol("_SetEtsTimeBuffers", "ps4000SetEtsTimeBuffers", c_uint32, [c_int16, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000RunBlock ( int16_t handle, int32_t noOfPreTriggerSamples, int32_t noOfPostTriggerSamples, uint32_t timebase, int16_t oversample, int32_t *timeIndisposedMs, uint16_t segmentIndex, ps4000BlockReady lpReady, void *pParameter ); """ ps4000.make_symbol("_RunBlock", "ps4000RunBlock", c_uint32, [c_int16, c_int32, c_int32, c_uint32, c_int16, c_void_p, c_uint16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000RunStreaming ( int16_t handle, uint32_t *sampleInterval, PS4000_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostPreTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, uint32_t overviewBufferSize ); """ ps4000.make_symbol("_RunStreaming", "ps4000RunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps4000RunStreamingEx ( int16_t handle, uint32_t *sampleInterval, PS4000_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostPreTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, int16_t downSampleRatioMode, uint32_t overviewBufferSize ); """ ps4000.make_symbol("_RunStreamingEx", "ps4000RunStreamingEx", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_int16, c_uint32], doc) doc = """ PICO_STATUS ps4000IsReady ( int16_t handle, int16_t * ready ); """ ps4000.make_symbol("_IsReady", "ps4000IsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000GetStreamingLatestValues ( int16_t handle, ps4000StreamingReady lpPs4000Ready, void *pParameter ); """ ps4000.make_symbol("_GetStreamingLatestValues", "ps4000GetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ void *ps4000StreamingReady ( int16_t handle, int32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void *pParameter ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps4000.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps4000.StreamingReadyType.__doc__ = doc doc = """ PICO_STATUS ps4000NoOfStreamingValues ( int16_t handle, uint32_t *noOfValues ); """ ps4000.make_symbol("_NoOfStreamingValues", "ps4000NoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000GetMaxDownSampleRatio ( int16_t handle, uint32_t noOfUnaggreatedSamples, uint32_t *maxDownSampleRatio, int16_t downSampleRatioMode, uint16_t segmentIndex ); """ ps4000.make_symbol("_GetMaxDownSampleRatio", "ps4000GetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int16, c_uint16], doc) doc = """ PICO_STATUS ps4000GetValues ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, int16_t downSampleRatioMode, uint16_t segmentIndex, int16_t *overflow ); """ ps4000.make_symbol("_GetValues", "ps4000GetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int16, c_uint16, c_void_p], doc) doc = """ PICO_STATUS ps4000GetValuesBulk ( int16_t handle, uint32_t *noOfSamples, uint16_t fromSegmentIndex, uint16_t toSegmentIndex, int16_t *overflow ); """ ps4000.make_symbol("_GetValuesBulk", "ps4000GetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint16, c_uint16, c_void_p], doc) doc = """ PICO_STATUS ps4000GetValuesAsync ( int16_t handle, uint32_t startIndex, uint32_t noOfSamples, uint32_t downSampleRatio, int16_t downSampleRatioMode, uint16_t segmentIndex, void *lpDataReady, void *pParameter ); """ ps4000.make_symbol("_GetValuesAsync", "ps4000GetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int16, c_uint16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000Stop ( int16_t handle ); """ ps4000.make_symbol("_Stop", "ps4000Stop", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000SetProbe ( int16_t handle, PS4000_PROBE probe, PS4000_RANGE range ); """ ps4000.make_symbol("_SetProbe", "ps4000SetProbe", c_uint32, [c_int16, c_int32, c_int32], doc) doc = """ PICO_STATUS ps4000HoldOff ( int16_t handle, uint64_t holdoff, PS4000_HOLDOFF_TYPE type ); """ ps4000.make_symbol("_HoldOff", "ps4000HoldOff", c_uint32, [c_int16, c_uint64, c_int32], doc) doc = """ PICO_STATUS ps4000GetProbe ( int16_t handle, PS4000_PROBE *probe ); """ ps4000.make_symbol("_GetProbe", "ps4000GetProbe", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000GetChannelInformation ( int16_t handle, PS4000_CHANNEL_INFO info, int32_t probe, int32_t *ranges, int32_t *length, int32_t channels ); """ ps4000.make_symbol("_GetChannelInformation", "ps4000GetChannelInformation", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000SetFrequencyCounter ( int16_t handle, PS4000_CHANNEL channel, int16_t enabled, PS4000_FREQUENCY_COUNTER_RANGE range, int16_t thresholdMajor, int16_t thresholdMinor ); """ ps4000.make_symbol("_SetFrequencyCounter", "ps4000SetFrequencyCounter", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000EnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps4000.make_symbol("_EnumerateUnits", "ps4000EnumerateUnits", c_uint32, [c_void_p, c_char_p, c_void_p], doc) doc = """ PICO_STATUS ps4000PingUnit ( int16_t handle ); """ ps4000.make_symbol("_PingUnit", "ps4000PingUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000SetBwFilter ( int16_t handle, PS4000_CHANNEL channel, int16_t enable ); """ ps4000.make_symbol("_SetBwFilter", "ps4000SetBwFilter", c_uint32, [c_int16, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000TriggerWithinPreTriggerSamples ( int16_t handle, int16_t state ); """ ps4000.make_symbol("_TriggerWithinPreTriggerSamples", "ps4000TriggerWithinPreTriggerSamples", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000GetNoOfCaptures ( int16_t handle, uint16_t *nCaptures ); """ ps4000.make_symbol("_GetNoOfCaptures", "ps4000GetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) ================================================ FILE: picosdk/ps4000a.py ================================================ # # Copyright (C) 2015-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps4000aApi.h C header file for PicoScope 4000 Series oscilloscopes using the ps4000a driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.constants import make_enum from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY class Ps4000alib(Library): def __init__(self): super(Ps4000alib, self).__init__("ps4000a") ps4000a = Ps4000alib() ps4000a.PS4000A_BANDWIDTH_LIMITER = make_enum([ 'PS4000A_BW_FULL', 'PS4000A_BW_20KHZ', 'PS4000A_BW_100KHZ', 'PS4000A_BW_1MHZ', ]) ps4000a.PS4000A_COUPLING = make_enum([ 'PS4000A_AC', 'PS4000A_DC', ]) # Just use AC and DC. ps4000a.PICO_COUPLING = {k[-2:]: v for k, v in ps4000a.PS4000A_COUPLING.items()} # A tuple in an enum like this is 2 names for the same value. ps4000a.PS4000A_CHANNEL = { "PS4000A_CHANNEL_A" : 0, "PS4000A_CHANNEL_B" : 1, "PS4000A_CHANNEL_C" : 2, "PS4000A_CHANNEL_D" : 3, ("PS4000A_CHANNEL_E", "PS4000A_MAX_4_CHANNELS") : 4, "PS4000A_CHANNEL_F" : 5, "PS4000A_CHANNEL_G" : 6 , "PS4000A_CHANNEL_H" : 7, ("PS4000A_MAX_CHANNELS", "PS4000A_EXTERNAL") : 8, "PS4000A_TRIGGER_AUX" : 9, "PS4000A_MAX_TRIGGER_SOURCES" : 10, "PS4000A_PULSE_WIDTH_SOURCE" : 0x10000000 } ps4000a.PICO_CHANNEL = {k[19:]: v for k, v in ps4000a.PS4000A_CHANNEL.items()} # The voltage ranges for this driver are so oddly defined, that it is easier to describe them as a literal than trying # to use make_enum: def _define_ranges(): # These are lower case to keep the python style police happy. They are available in the range dictionary with their # usual upper case names precisely as in the C header file. pico_x1_probe_10mv = 0 pico_x1_probe_20mv = 1 pico_x1_probe_50mv = 2 pico_x1_probe_100mv = 3 pico_x1_probe_200mv = 4 pico_x1_probe_500mv = 5 pico_x1_probe_1v = 6 pico_x1_probe_2v = 7 pico_x1_probe_5v = 8 pico_x1_probe_10v = 9 pico_x1_probe_20v = 10 pico_x1_probe_50v = 11 pico_x1_probe_100v = 12 pico_x1_probe_200v = 13 pico_x1_probe_ranges = (pico_x1_probe_200v + 1) - pico_x1_probe_10mv pico_ps4000a_resistance_315k = 0x00000200 pico_ps4000a_resistance_1100k = pico_ps4000a_resistance_315k + 1 pico_ps4000a_resistance_10m = pico_ps4000a_resistance_315k + 2 pico_ps4000a_max_resistance_ranges = (pico_ps4000a_resistance_10m + 1) - pico_ps4000a_resistance_315k pico_ps4000a_resistance_adcv_flag = 0x10000000 pico_connect_probe_off = 1024 pico_d9_bnc_10mv = 0 pico_d9_bnc_20mv = 1 pico_d9_bnc_50mv = 2 pico_d9_bnc_100mv = 3 pico_d9_bnc_200mv = 4 pico_d9_bnc_500mv = 5 pico_d9_bnc_1v = 6 pico_d9_bnc_2v = 7 pico_d9_bnc_5v = 8 pico_d9_bnc_10v = 9 pico_d9_bnc_20v = 10 pico_d9_bnc_50v = 11 pico_d9_bnc_100v = 12 pico_d9_bnc_200v = 13 pico_max_d9_bnc_ranges = (pico_d9_bnc_200v + 1) - pico_d9_bnc_10mv pico_d9_2x_bnc_10mv = pico_d9_bnc_10mv pico_d9_2x_bnc_20mv = pico_d9_bnc_20mv pico_d9_2x_bnc_50mv = pico_d9_bnc_50mv pico_d9_2x_bnc_100mv = pico_d9_bnc_100mv pico_d9_2x_bnc_200mv = pico_d9_bnc_200mv pico_d9_2x_bnc_500mv = pico_d9_bnc_500mv pico_d9_2x_bnc_1v = pico_d9_bnc_1v pico_d9_2x_bnc_2v = pico_d9_bnc_2v pico_d9_2x_bnc_5v = pico_d9_bnc_5v pico_d9_2x_bnc_10v = pico_d9_bnc_10v pico_d9_2x_bnc_20v = pico_d9_bnc_20v pico_d9_2x_bnc_50v = pico_d9_bnc_50v pico_d9_2x_bnc_100v = pico_d9_bnc_100v pico_d9_2x_bnc_200v = pico_d9_bnc_200v pico_max_d9_2x_bnc_ranges = (pico_d9_2x_bnc_200v + 1) - pico_d9_2x_bnc_10mv pico_differential_10mv = pico_d9_bnc_10mv pico_differential_20mv = pico_d9_bnc_20mv pico_differential_50mv = pico_d9_bnc_50mv pico_differential_100mv = pico_d9_bnc_100mv pico_differential_200mv = pico_d9_bnc_200mv pico_differential_500mv = pico_d9_bnc_500mv pico_differential_1v = pico_d9_bnc_1v pico_differential_2v = pico_d9_bnc_2v pico_differential_5v = pico_d9_bnc_5v pico_differential_10v = pico_d9_bnc_10v pico_differential_20v = pico_d9_bnc_20v pico_differential_50v = pico_d9_bnc_50v pico_differential_100v = pico_d9_bnc_100v pico_differential_200v = pico_d9_bnc_200v pico_max_differential_ranges = (pico_differential_200v + 1) - pico_differential_10mv, pico_current_clamp_200a_2ka_1a = 4000 pico_current_clamp_200a_2ka_2a = pico_current_clamp_200a_2ka_1a + 1 pico_current_clamp_200a_2ka_5a = pico_current_clamp_200a_2ka_1a + 2 pico_current_clamp_200a_2ka_10a = pico_current_clamp_200a_2ka_1a + 3 pico_current_clamp_200a_2ka_20a = pico_current_clamp_200a_2ka_1a + 4 pico_current_clamp_200a_2ka_50a = pico_current_clamp_200a_2ka_1a + 5 pico_current_clamp_200a_2ka_100a = pico_current_clamp_200a_2ka_1a + 6 pico_current_clamp_200a_2ka_200a = pico_current_clamp_200a_2ka_1a + 7 pico_current_clamp_200a_2ka_500a = pico_current_clamp_200a_2ka_1a + 8 pico_current_clamp_200a_2ka_1000a = pico_current_clamp_200a_2ka_1a + 9 pico_current_clamp_200a_2ka_2000a = pico_current_clamp_200a_2ka_1a + 10 pico_max_current_clamp_200a_2ka_ranges = (pico_current_clamp_200a_2ka_2000a + 1) - pico_current_clamp_200a_2ka_1a pico_current_clamp_40a_100ma = 5000 pico_current_clamp_40a_200ma = pico_current_clamp_40a_100ma + 1 pico_current_clamp_40a_500ma = pico_current_clamp_40a_100ma + 2 pico_current_clamp_40a_1a = pico_current_clamp_40a_100ma + 3 pico_current_clamp_40a_2a = pico_current_clamp_40a_100ma + 4 pico_current_clamp_40a_5a = pico_current_clamp_40a_100ma + 5 pico_current_clamp_40a_10a = pico_current_clamp_40a_100ma + 6 pico_current_clamp_40a_20a = pico_current_clamp_40a_100ma + 7 pico_current_clamp_40a_40a = pico_current_clamp_40a_100ma + 8 pico_max_current_clamp_40a_ranges = (pico_current_clamp_40a_40a + 1) - pico_current_clamp_40a_100ma pico_1kv_2_5v = 6003 pico_1kv_5v = pico_1kv_2_5v + 1 pico_1kv_12_5v = pico_1kv_2_5v + 2 pico_1kv_25v = pico_1kv_2_5v + 3 pico_1kv_50v = pico_1kv_2_5v + 4 pico_1kv_125v = pico_1kv_2_5v + 5 pico_1kv_250v = pico_1kv_2_5v + 6 pico_1kv_500v = pico_1kv_2_5v + 7 pico_1kv_1000v = pico_1kv_2_5v + 8 pico_max_1kv_ranges = (pico_1kv_1000v + 1) - pico_1kv_2_5v return {k.upper(): v for k, v in locals().items() if k.startswith("pico")} ps4000a.PICO_CONNECT_PROBE_RANGE = _define_ranges() def process_enum(enum): """The PS4000a range enum is complicated enough that we need some clearer logic:""" import re pattern = re.compile(r'PICO_X1_PROBE_([0-9]+M?)V') voltage_range = {} for enum_item_name, enum_item_value in enum.items(): match = pattern.match(enum_item_name) if match is None: continue voltage_string = match.group(1) voltage = float(voltage_string) if voltage_string[-1] != 'M' else (0.001 * float(voltage_string[:-1])) voltage_range[enum_item_value] = voltage return voltage_range ps4000a.PICO_VOLTAGE_RANGE = process_enum(ps4000a.PICO_CONNECT_PROBE_RANGE) class PS4000A_USER_PROBE_INTERACTIONS(Structure): _pack_ = 1 _fields_ = [ ("connected", c_uint16), ("channel", c_uint32), ("enabled", c_uint16), ("probeName", c_int32), ("requiresPower_", c_uint8), ("isPowered_", c_uint8), ("status", c_uint32), ("probeOff", c_uint32), ("rangeFirst_", c_uint32), ("rangeLast_", c_uint32), ("rangeCurrent_", c_uint32), ("couplingFirst_", c_uint32), ("couplingLast_", c_uint32), ("couplingCurrent_", c_uint32), ("filterFlags_", c_uint32), ("filterCurrent_", c_uint32), ("defaultFilter_", c_uint32)] ps4000a.PS4000A_USER_PROBE_INTERACTIONS = PS4000A_USER_PROBE_INTERACTIONS ps4000a.PS4000A_RATIO_MODE = { 'PS4000A_RATIO_MODE_NONE': 0, 'PS4000A_RATIO_MODE_AGGREGATE': 1, 'PS4000A_RATIO_MODE_DECIMATE': 2, 'PS4000A_RATIO_MODE_AVERAGE': 4, } ps4000a.PICO_RATIO_MODE = {k[19:]: v for k, v in ps4000a.PS4000A_RATIO_MODE.items()} ps4000a.PS4000A_TIME_UNITS = make_enum([ 'PS4000A_FS', 'PS4000A_PS', 'PS4000A_NS', 'PS4000A_US', 'PS4000A_MS', 'PS4000A_S', 'PS4000A_MAX_TIME_UNITS', ]) ps4000a.PS4000A_WAVE_TYPE = make_enum([ 'PS4000A_SINE', 'PS4000A_SQUARE', 'PS4000A_TRIANGLE', 'PS4000A_RAMP_UP', 'PS4000A_RAMP_DOWN', 'PS4000A_SINC', 'PS4000A_GAUSSIAN', 'PS4000A_HALF_SINE', 'PS4000A_DC_VOLTAGE', 'PS4000A_WHITE_NOISE', 'PS4000A_MAX_WAVE_TYPES', ]) ps4000a.PS4000A_SWEEP_TYPE = make_enum([ 'PS4000A_UP', 'PS4000A_DOWN', 'PS4000A_UPDOWN', 'PS4000A_DOWNUP', 'PS4000A_MAX_SWEEP_TYPES', ]) ps4000a.PS4000A_SIGGEN_TRIG_TYPE = make_enum([ 'PS4000A_SIGGEN_RISING', 'PS4000A_SIGGEN_FALLING', 'PS4000A_SIGGEN_GATE_HIGH', 'PS4000A_SIGGEN_GATE_LOW', ]) ps4000a.PS4000A_SIGGEN_TRIG_SOURCE = make_enum([ 'PS4000A_SIGGEN_NONE', 'PS4000A_SIGGEN_SCOPE_TRIG', 'PS4000A_SIGGEN_AUX_IN', 'PS4000A_SIGGEN_EXT_IN', 'PS4000A_SIGGEN_SOFT_TRIG', ]) ps4000a.PS4000A_INDEX_MODE = make_enum([ 'PS4000A_SINGLE', 'PS4000A_DUAL', 'PS4000A_QUAD', 'PS4000A_MAX_INDEX_MODES', ]) ps4000a.PS4000A_EXTRA_OPERATIONS = make_enum([ 'PS4000A_ES_OFF', 'PS4000A_WHITENOISE', 'PS4000A_PRBS', ]) ps4000a.PS4000A_CONDITIONS_INFO = { 'PS4000A_CLEAR': 1, 'PS4000A_ADD': 2, } ps4000a.PS4000A_THRESHOLD_DIRECTION = make_enum([ ("PS4000A_ABOVE", "PS4000A_INSIDE"), ("PS4000A_BELOW", "PS4000A_OUTSIDE"), ("PS4000A_RISING", "PS4000A_ENTER", "PS4000A_NONE"), ("PS4000A_FALLING", "PS4000A_EXIT"), ("PS4000A_RISING_OR_FALLING", "PS4000A_ENTER_OR_EXIT"), "PS4000A_ABOVE_LOWER", "PS4000A_BELOW_LOWER", "PS4000A_RISING_LOWER", "PS4000A_FALLING_LOWER", "PS4000A_POSITIVE_RUNT", "PS4000A_NEGATIVE_RUNT", ]) ps4000a.PS4000A_THRESHOLD_MODE = make_enum([ "PS4000A_LEVEL", "PS4000A_WINDOW" ]) ps4000a.PS4000A_TRIGGER_STATE = make_enum([ "PS4000A_DONT_CARE", "PS4000A_TRUE", "PS4000A_FALSE" ]) ps4000a.PS4000A_PULSE_WIDTH_TYPE = make_enum([ "PW_TYPE NONE", "PW_TYPE_LESS_THAN", "PW_TYPE_GREATER_THAN", "PW_TYPE_IN_RANGE", "PW_TYPE_OUT_OF_RANGE" ]) class PS4000A_CONDITION (Structure): _pack_ = 1 _fields_ = [("source", c_int32), ("condition", c_int32)] ps4000a.PS4000A_CONDITION = PS4000A_CONDITION class PS4000A_DIRECTION(Structure): _pack_ = 1 _fields_ = [("channel", c_int32), ("direction", c_int32)] ps4000a.PS4000A_DIRECTION = PS4000A_DIRECTION class PS4000A_TRIGGER_CHANNEL_PROPERTIES(Structure): _pack_ = 1 _fields_ = [("thresholdUpper", c_int16), ("thresholdUpperHysteresis", c_uint16), ("thresholdLower", c_int16), ("thresholdLowerHysteresis", c_uint16), ("channel", c_int32), ("thresholdMode", c_int32)] ps4000a.PS4000A_TRIGGER_CHANNEL_PROPERTIES = PS4000A_TRIGGER_CHANNEL_PROPERTIES doc = """ PICO_STATUS ps4000aOpenUnit ( int16_t *handle, int8_t *serial ); """ ps4000a.make_symbol("_OpenUnit", "ps4000aOpenUnit", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps4000aOpenUnitAsync ( int16_t *status, int8_t *serial ); """ ps4000a.make_symbol("_OpenUnitAsync", "ps4000aOpenUnitAsync", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps4000aOpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps4000a.make_symbol("_OpenUnitProgress", "ps4000aOpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps4000a.make_symbol("_GetUnitInfo", "ps4000aGetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps4000aFlashLed ( int16_t handle, int16_t start ); """ ps4000a.make_symbol("_FlashLed", "ps4000aFlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000aSetChannelLed ( int16_t handle, PS4000A_CHANNEL_LED_SETTING *ledStates, uint16_t nLedStates ); """ ps4000a.make_symbol("_SetChannelLed", "ps4000aSetChannelLed", c_uint32, [c_int16, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps4000aIsLedFlashing ( int16_t handle, int16_t *status ); """ ps4000a.make_symbol("_IsLedFlashing", "ps4000aIsLedFlashing", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aCloseUnit ( int16_t handle ); """ ps4000a.make_symbol("_CloseUnit", "ps4000aCloseUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000aMemorySegments ( int16_t handle, uint32_t nSegments, int32_t *nMaxSamples ); """ ps4000a.make_symbol("_MemorySegments", "ps4000aMemorySegments", c_uint32, [c_int16, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps4000aSetChannel ( int16_t handle, PS4000A_CHANNEL channel, int16_t enabled, PS4000A_COUPLING type, PS4000A_RANGE range, float analogOffset ); """ ps4000a.make_symbol("_SetChannel", "ps4000aSetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int32, c_float], doc) doc = """ PICO_STATUS ps4000aSetBandwidthFilter ( int16_t handle, PS4000A_CHANNEL channel, PS4000A_BANDWIDTH_LIMITER bandwidth ); """ ps4000a.make_symbol("_SetBandwidthFilter", "ps4000aSetBandwidthFilter", c_uint32, [c_int16, c_int32, c_int32], doc) doc = """ PICO_STATUS ps4000aApplyResistanceScaling ( int16_t handle, PS4000A_CHANNEL channel, PS4000A_RANGE range, int16_t *bufferMax, int16_t *bufferMin, uint32_t buffertLth, int16_t *overflow ); """ ps4000a.make_symbol("_ApplyResistanceScaling", "ps4000aApplyResistanceScaling", c_uint32, [c_int16, c_int32, c_int32, c_int16, c_int16, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps4000aGetTimebase ( int16_t handle, uint32_t timebase, int32_t noSamples, int32_t *timeIntervalNanoseconds, int32_t *maxSamples, uint32_t segmentIndex ); """ ps4000a.make_symbol('_GetTimebase', 'ps4000aGetTimebase', c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetTimebase2 ( int16_t handle, uint32_t timebase, int32_t noSamples, float *timeIntervalNanoseconds, int32_t *maxSamples, uint32_t segmentIndex ); """ ps4000a.make_symbol("_GetTimebase2", "ps4000aGetTimebase2", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps4000aSetSigGenArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, int16_t *arbitraryWaveform, int32_t arbitraryWaveformSize, PS4000A_SWEEP_TYPE sweepType, PS4000A_EXTRA_OPERATIONS operation, PS4000A_INDEX_MODE indexMode, uint32_t shots, uint32_t sweeps, PS4000A_SIGGEN_TRIG_TYPE triggerType, PS4000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps4000a.make_symbol("_SetSigGenArbitrary", "ps4000aSetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000aSetSigGenBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, PS4000A_WAVE_TYPE waveType, double startFrequency, double stopFrequency, double increment, double dwellTime, PS4000A_SWEEP_TYPE sweepType, PS4000A_EXTRA_OPERATIONS operation, uint32_t shots, uint32_t sweeps, PS4000A_SIGGEN_TRIG_TYPE triggerType, PS4000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps4000a.make_symbol("_SetSigGenBuiltIn", "ps4000aSetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int32, c_double, c_double, c_double, c_double, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000aSetSigGenPropertiesArbitrary ( int16_t handle, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, PS4000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS4000A_SIGGEN_TRIG_TYPE triggerType, PS4000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps4000a.make_symbol("_SetSigGenPropertiesArbitrary", "ps4000aSetSigGenPropertiesArbitrary", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000aSetSigGenPropertiesBuiltIn ( int16_t handle, double startFrequency, double stopFrequency, double increment, double dwellTime, PS4000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS4000A_SIGGEN_TRIG_TYPE triggerType, PS4000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps4000a.make_symbol("_SetSigGenPropertiesBuiltIn", "ps4000aSetSigGenPropertiesBuiltIn", c_uint32, [c_int16, c_double, c_double, c_double, c_double, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps4000aSigGenFrequencyToPhase ( int16_t handle, double frequency, PS4000A_INDEX_MODE indexMode, uint32_t bufferLength, uint32_t *phase ); """ ps4000a.make_symbol("_SigGenFrequencyToPhase", "ps4000aSigGenFrequencyToPhase", c_uint32, [c_int16, c_double, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps4000aSigGenArbitraryMinMaxValues ( int16_t handle, int16_t *minArbitraryWaveformValue, int16_t *maxArbitraryWaveformValue, uint32_t *minArbitraryWaveformSize, uint32_t *maxArbitraryWaveformSize ); """ ps4000a.make_symbol("_SigGenArbitraryMinMaxValues", "ps4000aSigGenArbitraryMinMaxValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aSigGenSoftwareControl ( int16_t handle, int16_t state );""" ps4000a.make_symbol("_SigGenSoftwareControl", "ps4000aSigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000aSetEts ( int16_t handle, PS4000A_ETS_MODE mode, int16_t etsCycles, int16_t etsInterleave, int32_t *sampleTimePicoseconds ); """ ps4000a.make_symbol("_SetEts", "ps4000aSetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aSetTriggerChannelProperties ( int16_t handle, PS4000A_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, int32_t autoTriggerMilliseconds ); """ ps4000a.make_symbol("_SetTriggerChannelProperties", "ps4000aSetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000aSetTriggerChannelConditions ( int16_t handle, PS4000A_CONDITION *conditions, int16_t nConditions, PS4000A_CONDITIONS_INFO info ); """ ps4000a.make_symbol("_SetTriggerChannelConditions", "ps4000aSetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000aSetTriggerChannelDirections ( int16_t handle, PS4000A_DIRECTION *directions, int16_t nDirections ); """ ps4000a.make_symbol("_SetTriggerChannelDirections", "ps4000aSetTriggerChannelDirections", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps4000aSetSimpleTrigger ( int16_t handle, int16_t enable, PS4000A_CHANNEL source, int16_t threshold, PS4000A_THRESHOLD_DIRECTION direction, uint32_t delay, int16_t autoTrigger_ms ); """ ps4000a.make_symbol("_SetSimpleTrigger", "ps4000aSetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps4000aSetTriggerDelay ( int16_t handle, uint32_t delay ); """ ps4000a.make_symbol("_SetTriggerDelay", "ps4000aSetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps4000aSetPulseWidthQualifierProperties ( int16_t handle, PS4000A_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS4000A_PULSE_WIDTH_TYPE type ); """ ps4000a.make_symbol("_SetPulseWidthQualifierProperties", "ps4000aSetPulseWidthQualifierProperties", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps4000aSetPulseWidthQualifierConditions ( int16_t handle, PS4000A_CONDITION *conditions, int16_t nConditions, PS4000A_CONDITIONS_INFO info ); """ ps4000a.make_symbol("_SetPulseWidthQualifierConditions", "ps4000aSetPulseWidthQualifierConditions", c_uint32, [c_int16, c_void_p, c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000aIsTriggerOrPulseWidthQualifierEnabled ( int16_t handle, int16_t *triggerEnabled, int16_t *pulseWidthQualifierEnabled ); """ ps4000a.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps4000aIsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetTriggerTimeOffset ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, PS4000A_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps4000a.make_symbol("_GetTriggerTimeOffset", "ps4000aGetTriggerTimeOffset", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetTriggerTimeOffset64 ( int16_t handle, int64_t *time, PS4000A_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps4000a.make_symbol("_GetTriggerTimeOffset64", "ps4000aGetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetValuesTriggerTimeOffsetBulk ( int16_t handle, uint32_t *timesUpper, uint32_t *timesLower, PS4000A_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps4000a.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps4000aGetValuesTriggerTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetValuesTriggerTimeOffsetBulk64 ( int16_t handle, int64_t *times, PS4000A_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps4000a.make_symbol("_GetValuesTriggerTimeOffsetBulk64", "ps4000aGetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps4000aSetDataBuffers ( int16_t handle, PS4000A_CHANNEL channel, int16_t *bufferMax, int16_t *bufferMin, int32_t bufferLth, uint32_t segmentIndex, PS4000A_RATIO_MODE mode ); """ ps4000a.make_symbol("_SetDataBuffers", "ps4000aSetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps4000aSetDataBuffer ( int16_t handle, PS4000A_CHANNEL channel, int16_t *buffer, int32_t bufferLth, uint32_t segmentIndex, PS4000A_RATIO_MODE mode ); """ ps4000a.make_symbol("_SetDataBuffer", "ps4000aSetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps4000aSetEtsTimeBuffer ( int16_t handle, int64_t *buffer, int32_t bufferLth ); """ ps4000a.make_symbol("_SetEtsTimeBuffer", "ps4000aSetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000aSetEtsTimeBuffers ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, int32_t bufferLth ); """ ps4000a.make_symbol("_SetEtsTimeBuffers", "ps4000aSetEtsTimeBuffers", c_uint32, [c_int16, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000aIsReady ( int16_t handle, int16_t *ready ); """ ps4000a.make_symbol("_IsReady", "ps4000aIsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aRunBlock ( int16_t handle, int32_t noOfPreTriggerSamples, int32_t noOfPostTriggerSamples, uint32_t timebase, int32_t *timeIndisposedMs, uint32_t segmentIndex, ps4000aBlockReady lpReady, void *pParameter ); """ ps4000a.make_symbol("_RunBlock", "ps4000aRunBlock", c_uint32, [c_int16, c_int32, c_int32, c_uint32, c_void_p, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aRunStreaming ( int16_t handle, uint32_t *sampleInterval, PS4000A_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, uint32_t overviewBufferSize ); """ ps4000a.make_symbol("_RunStreaming", "ps4000aRunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetStreamingLatestValues ( int16_t handle, ps4000aStreamingReady lpPs4000aReady, void *pParameter ); """ ps4000a.make_symbol("_GetStreamingLatestValues", "ps4000aGetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ void *ps4000aStreamingReady ( int16_t handle, int32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void *pParameter ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps4000a.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps4000a.StreamingReadyType.__doc__ = doc doc = """ PICO_STATUS ps4000aNoOfStreamingValues ( int16_t handle, uint32_t *noOfValues ); """ ps4000a.make_symbol("_NoOfStreamingValues", "ps4000aNoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetMaxDownSampleRatio ( int16_t handle, uint32_t noOfUnaggreatedSamples, uint32_t *maxDownSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex ); """ ps4000a.make_symbol("_GetMaxDownSampleRatio", "ps4000aGetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetValues ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps4000a.make_symbol("_GetValues", "ps4000aGetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetValuesAsync ( int16_t handle, uint32_t startIndex, uint32_t noOfSamples, uint32_t downSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, void *lpDataReady, void *pParameter ); """ ps4000a.make_symbol("_GetValuesAsync", "ps4000aGetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetValuesBulk ( int16_t handle, uint32_t *noOfSamples, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, uint32_t downSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, int16_t *overflow ); """ ps4000a.make_symbol("_GetValuesBulk", "ps4000aGetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32, c_uint32, c_int32, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetValuesOverlapped ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps4000a.make_symbol("_GetValuesOverlapped", "ps4000aGetValuesOverlapped", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetValuesOverlappedBulk ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS4000A_RATIO_MODE downSampleRatioMode, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, int16_t *overflow ); """ ps4000a.make_symbol("_GetValuesOverlappedBulk", "ps4000aGetValuesOverlappedBulk", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps4000aEnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps4000a.make_symbol("_EnumerateUnits", "ps4000aEnumerateUnits", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetChannelInformation ( int16_t handle, PS4000A_CHANNEL_INFO info, int32_t probe, int32_t *ranges, int32_t *length, int32_t channels ); """ ps4000a.make_symbol("_GetChannelInformation", "ps4000aGetChannelInformation", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000aConnectDetect ( int16_t handle, PS4000A_CONNECT_DETECT *sensor, int16_t nSensors ); """ ps4000a.make_symbol("_ConnectDetect", "ps4000aConnectDetect", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps4000aMaximumValue ( int16_t handle, int16_t *value ); """ ps4000a.make_symbol("_MaximumValue", "ps4000aMaximumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aMinimumValue ( int16_t handle, int16_t * value ); """ ps4000a.make_symbol("_MinimumValue", "ps4000aMinimumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetAnalogueOffset ( int16_t handle, PS4000A_RANGE range, PS4000A_COUPLING coupling, float *maximumVoltage, float *minimumVoltage ); """ ps4000a.make_symbol("_GetAnalogueOffset", "ps4000aGetAnalogueOffset", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetMaxSegments ( int16_t handle, uint32_t *maxSegments ); """ ps4000a.make_symbol("_GetMaxSegments", "ps4000aGetMaxSegments", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aChangePowerSource ( int16_t handle, PICO_STATUS powerState ); """ ps4000a.make_symbol("_ChangePowerSource", "ps4000aChangePowerSource", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps4000aCurrentPowerSource ( int16_t handle ); """ ps4000a.make_symbol("_CurrentPowerSource", "ps4000aCurrentPowerSource", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000aStop ( int16_t handle ); """ ps4000a.make_symbol("_Stop", "ps4000aStop", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000aPingUnit ( int16_t handle ); """ ps4000a.make_symbol("_PingUnit", "ps4000aPingUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps4000aSetNoOfCaptures ( int16_t handle, uint32_t nCaptures ); """ ps4000a.make_symbol("_SetNoOfCaptures", "ps4000aSetNoOfCaptures", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps4000aGetNoOfCaptures ( int16_t handle, uint32_t *nCaptures ); """ ps4000a.make_symbol("_GetNoOfCaptures", "ps4000aGetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetNoOfProcessedCaptures ( int16_t handle, uint32_t *nProcessedCaptures ); """ ps4000a.make_symbol("_GetNoOfProcessedCaptures", "ps4000aGetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aDeviceMetaData ( int16_t handle, int8_t *settings, int32_t *nSettingsLength, PS4000A_META_TYPE type, PS4000A_META_OPERATION operation, PS4000A_META_FORMAT format ); """ ps4000a.make_symbol("_DeviceMetaData", "ps4000aDeviceMetaData", c_uint32, [c_int16, c_void_p, c_void_p, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps4000aGetString ( int16_t handle, PICO_STRING_VALUE stringValue, int8_t *string, int32_t *stringLength ); """ ps4000a.make_symbol("_GetString", "ps4000aGetString", c_uint32, [c_int16, c_int32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps4000aGetCommonModeOverflow ( int16_t handle, uint16_t *overflow ); """ ps4000a.make_symbol("_GetCommonModeOverflow", "ps4000aGetCommonModeOverflow", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aSetFrequencyCounter ( int16_t handle, PS4000A_CHANNEL channel, int16_t enabled, PS4000A_FREQUENCY_COUNTER_RANGE range, int16_t thresholdMajor, int16_t thresholdMinor ); """ ps4000a.make_symbol("_SetFrequencyCounter", "ps4000aSetFrequencyCounter", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int16, c_int16], doc) doc = """ PICO_STATUS ps4000aOpenUnitWithResolution ( int16_t *handle, int8_t *serial, PS4000A_DEVICE_RESOLUTION resolution ); """ ps4000a.make_symbol("_OpenUnitWithResolution", "ps4000aOpenUnitWithResolution", c_uint32, [c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps4000aGetDeviceResolution ( int16_t handle, PS4000A_DEVICE_RESOLUTION *resolution ); """ ps4000a.make_symbol("_GetResolution", "ps4000aGetDeviceResolution", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps4000aSetDeviceResolution ( int16_t handle, PS4000A_DEVICE_RESOLUTION resolution ); """ ps4000a.make_symbol("_SetResolution", "ps4000aSetDeviceResolution", c_uint32, [c_int16, c_int32], doc) doc = """ PICO_STATUS ps4000aSetProbeInteractionCallback ( int16_t handle, ps4000aProbeInteractions callback ); """ ps4000a.make_symbol("_SetProbeInteractionCallback", "ps4000aSetProbeInteractionCallback", c_uint32, [c_int16, c_void_p], doc) doc = """ void *ps4000aProbeInteractions ( int16_t handle, PICO_STATUS status, PS4000A_USER_PROBE_INTERACTIONS * probes, uint32_t nProbes ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps4000a.ps4000aProbeInteractions = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, POINTER(PS4000A_USER_PROBE_INTERACTIONS), c_uint32 ) ps4000a.ps4000aProbeInteractions.__doc__ = doc ================================================ FILE: picosdk/ps5000.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps5000Api.h C header file for PicoScope 5000 Series oscilloscopes using the ps5000 driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class Ps5000lib(Library): def __init__(self): super(Ps5000lib, self).__init__("ps5000") ps5000 = Ps5000lib() ps5000.PS5000_CHANNEL = make_enum([ "PS5000_CHANNEL_A", "PS5000_CHANNEL_B", "PS5000_CHANNEL_C", "PS5000_CHANNEL_D", ("PS5000_MAX_CHANNELS", "PS5000_EXTERNAL"), "PS5000_TRIGGER_AUX", "PS5000_MAX_TRIGGER_SOURCES", ]) ps5000.PS5000_RANGE = make_enum([ "PS5000_10MV", "PS5000_20MV", "PS5000_50MV", "PS5000_100MV", "PS5000_200MV", "PS5000_500MV", "PS5000_1V", "PS5000_2V", "PS5000_5V", "PS5000_10V", "PS5000_20V", "PS5000_50V", "PS5000_MAX_RANGES", ]) ps5000.PS5000_TIME_UNITS = make_enum([ "PS5000_FS", "PS5000_PS", "PS5000_NS", "PS5000_US", "PS5000_MS", "PS5000_S", "PS5000_MAX_TIME_UNITS", ]) class PWQ_CONDITIONS (Structure): _pack_ = 1 _fields_ = [("channelA", c_int32), ("channelB", c_int32), ("channelC", c_int32), ("channelD", c_int32), ("external", c_int32), ("aux", c_int32)] ps5000.PWQ_CONDITIONS = PWQ_CONDITIONS class TRIGGER_CONDITIONS (Structure): _pack_ = 1 _fields_ = [("channelA", c_int32), ("channelB", c_int32), ("channelC", c_int32), ("channelD", c_int32), ("external", c_int32), ("aux", c_int32), ("pulseWidthQualifier", c_int32)] ps5000.TRIGGER_CONDITIONS = TRIGGER_CONDITIONS class TRIGGER_CHANNEL_PROPERTIES (Structure): _pack_ = 1 _fields_ = [("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int32), ("thresholdMode", c_int32)] ps5000.TRIGGER_CHANNEL_PROPERTIES = TRIGGER_CHANNEL_PROPERTIES doc = """ PICO_STATUS ps5000CloseUnit ( short handle ); """ ps5000.make_symbol("_CloseUnit", "ps5000CloseUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps5000FlashLed ( short handle, short start ); """ ps5000.make_symbol("_FlashLed", "ps5000FlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps5000GetMaxDownSampleRatio ( short handle, unsigned long noOfUnaggregatedSamples, unsigned long *maxDownSampleRatio, short downSampleRatioMode, unsigned short segmentIndex ); """ ps5000.make_symbol("_GetMaxDownSampleRatio", "ps5000GetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int16, c_uint16], doc) doc = """ PICO_STATUS ps5000GetStreamingLatestValues ( short handle, ps5000StreamingReady lpPs5000Ready, void *pParameter ); """ ps5000.make_symbol("_GetStreamingLatestValues", "ps5000GetStreamingLatestValues", c_uint16, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000GetTimebase ( short handle, unsigned long timebase, long noSamples, long *timeIntervalNanoseconds, short oversample, long *maxSamples, unsigned short segmentIndex ); """ ps5000.make_symbol("_GetTimebase", "ps5000GetTimebase", c_uint16, [c_int16, c_uint32, c_int32, c_void_p, c_int16, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps5000GetTriggerTimeOffset ( short handle, unsigned long *timeUpper, unsigned long *timeLower, PS5000_TIME_UNITS *timeUnits, unsigned short segmentIndex ); """ ps5000.make_symbol("_GetTriggerTimeOffset", "ps5000GetTriggerTimeOffset", c_uint16, [c_int16, c_void_p, c_void_p, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps5000GetTriggerTimeOffset64 ( short handle, int64_t *time, PS5000_TIME_UNITS *timeUnits, unsigned short segmentIndex ); """ ps5000.make_symbol("_GetTriggerTimeOffset64", "ps5000GetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps5000GetUnitInfo ( short handle, char *string, short stringLength, short *requiredSize, PICO_INFO info ); """ ps5000.make_symbol("_GetUnitInfo", "ps5000GetUnitInfo", c_uint32, [c_int16, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps5000GetValues ( short handle, unsigned long startIndex, unsigned long *noOfSamples, unsigned long downSampleRatio, short downSampleRatioMode, unsigned short segmentIndex, short *overflow ); """ ps5000.make_symbol("_GetValues", "ps5000GetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int16, c_uint16, c_void_p], doc) doc = """ PICO_STATUS ps5000GetValuesAsync ( short handle, unsigned long startIndex, unsigned long noOfSamples, unsigned long downSampleRatio, short downSampleRatioMode, unsigned short segmentIndex, void *lpDataReady, void *pParameter ); """ ps5000.make_symbol("_GetValuesAsync", "ps5000GetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int16, c_uint16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000GetValuesBulk ( short handle, unsigned long *noOfSamples, unsigned short fromSegmentIndex, unsigned short toSegmentIndex, short *overflow ); """ ps5000.make_symbol("_GetValuesBulk", "ps5000GetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint16, c_uint16, c_void_p], doc) doc = """ PICO_STATUS ps5000GetValuesTriggerTimeOffsetBulk ( short handle, unsigned long *timesUpper, unsigned long *timesLower, PS5000_TIME_UNITS *timeUnits, unsigned short fromSegmentIndex, unsigned short toSegmentIndex ); """ ps5000.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps5000GetValuesTriggerTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint16, c_uint16], doc) doc = """ PICO_STATUS ps5000GetValuesTriggerTimeOffsetBulk64 ( short handle, _int64 *times, PS5000_TIME_UNITS *timeUnits, unsigned short fromSegmentIndex, unsigned short toSegmentIndex ); """ ps5000.make_symbol("_GetValuesTriggerTimeOffsetBulk64", "ps5000GetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint16, c_int16], doc) doc = """ PICO_STATUS ps5000IsLedFlashing ( short handle, short *status ); """ ps5000.make_symbol("_IsLedFlashing", "ps5000IsLedFlashing", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000IsReady ( short handle, short *ready ); """ ps5000.make_symbol("_IsReady", "ps5000IsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000IsTriggerOrPulseWidthQualifierEnabled ( short handle, short *triggerEnabled, short *pulseWidthQualifierEnabled ); """ ps5000.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps5000IsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000MemorySegments ( short handle, unsigned short nSegments, long *nMaxSamples ); """ ps5000.make_symbol("_MemorySegments", "ps5000MemorySegments", c_uint32, [c_int16, c_uint16, c_void_p], doc) doc = """ PICO_STATUS ps5000NoOfStreamingValues ( short handle, unsigned long *noOfValues ); """ ps5000.make_symbol("_NoOfStreamingValues", "ps5000NoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000OpenUnit ( short *handle ); """ ps5000.make_symbol("_OpenUnit", "ps5000OpenUnit", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS ps5000OpenUnitAsync ( short *status ); """ ps5000.make_symbol("_OpenUnitAsync", "ps5000OpenUnitAsync", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS ps5000OpenUnitProgress ( short *handle, short *progressPercent, short *complete ); """ ps5000.make_symbol("_OpenUnitProgress", "ps5000OpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000RunBlock ( short handle, long noOfPreTriggerSamples, long noOfPostTriggerSamples, unsigned long timebase, short oversample, long *timeIndisposedMs, unsigned short segmentIndex, ps5000BlockReady lpReady, void *pParameter ); """ ps5000.make_symbol("_RunBlock", "ps5000RunBlock", c_uint32, [c_int16, c_int32, c_int32, c_uint32, c_int16, c_void_p, c_uint16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000RunStreaming ( short handle, unsigned long *sampleInterval, PS5000_TIME_UNITS sampleIntervalTimeUnits, unsigned long maxPreTriggerSamples, unsigned long maxPostTriggerSamples, short autoStop, unsigned long downSampleRatio, unsigned long overviewBufferSize ); """ ps5000.make_symbol("_RunStreaming", "ps5000RunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps5000SetChannel ( short handle, PS5000_CHANNEL channel, short enabled, short dc, PS5000_RANGE range ); """ ps5000.make_symbol("_SetChannel", "ps5000SetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000SetDataBuffer ( short handle, PS5000_CHANNEL channel, short *buffer, long buggerLth ); """ ps5000.make_symbol("_SetDataBuffer", "ps5000SetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps5000SetDataBufferBulk ( short handle, PS5000_CHANNEL channel, short *buffer, long bufferLth, unsigned short waveform ); """ ps5000.make_symbol("_SetDataBufferBulk", "ps5000SetDataBufferBulk", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_uint16], doc) doc = """ PICO_STATUS ps5000SetDataBuffers ( short handle, PS5000_CHANNEL channel, short *bufferMax, short *bufferMin, long bufferLth ); """ ps5000.make_symbol("_SetDataBuffers", "ps5000SetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps5000SetEts ( short handle, PS5000_ETS_MODE mode, short etsCycles, short etsInterleave, long *sampleTimePicoseconds ); """ ps5000.make_symbol("_SetEts", "ps5000SetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000SetEtsTimeBuffer ( short handle, _int64 *buffer, long bufferLth ); """ ps5000.make_symbol("_SetEtsTimeBuffer", "ps5000SetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps5000SetEtsTimeBuffers ( short handle, unsigned long *timeUpper, unsigned long *timeLower, long bufferLth ); """ ps5000.make_symbol("_SetEtsTimeBuffers", "ps5000SetEtsTimeBuffers", c_uint32, [c_int16, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps5000SetNoOfCaptures ( short handle, unsigned short nCaptures ); """ ps5000.make_symbol("_SetNoOfCaptures", "ps5000SetNoOfCaptures", c_uint32, [c_int16, c_uint16], doc) doc = """ PICO_STATUS ps5000SetPulseWidthQualifier ( short handle, struct PWQ_CONDITIONS *conditions, short nConditions, THRESHOLD_DIRECTION direction, unsigned long lower, unsigned long upper, PULSE_WIDTH_TYPE type ); """ ps5000.make_symbol("_SetPulseWidthQualifier", "ps5000SetPulseWidthQualifier", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps5000SetSigGenArbitrary ( short handle, long offsetVoltage, unsigned long pkToPk, unsigned long startDeltaPhase, unsigned long stopDeltaPhase, unsigned long deltaPhaseIncrement, unsigned long dwellCount, short *arbitaryWaveform long arbitaryWaveformSize, SWEEP_TYPE sweepType, short whiteNoise, INDEX_MODE indexMode, unsigned long shots, unsigned long sweeps, SIGGEN_TRIG_TYPE triggerType, SIGGEN_TRIG_SOURCE triggerSource, short extInThreshold ); """ ps5000.make_symbol("_SetSigGenArbitrary", "ps5000SetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int16, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps5000SetSigGenBuiltIn ( short handle, long offsetVoltage, unsigned long pkToPk, short waveType, float startFrequency, float stopFrequency, float increment, float dwellTime, SWEEP_TYPE sweepType, short whiteNoise, unsigned long shots, unsigned long sweeps, SIGGEN_TRIG_TYPE triggerType, SIGGEN_TRIG_SOURCE triggerSource, short extInThreshold ); """ ps5000.make_symbol("_SetSigGenBuiltIn", "ps5000SetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_int64, c_int64, c_int64, c_int64, c_int64, c_int32, c_int16, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps5000SetSimpleTrigger ( short handle, short enable, PS5000_CHANNEL source, short threshold, THRESHOLD_DIRECTION direction, unsigned long delay, short autoTrigger_ms ); """ ps5000.make_symbol("_SetSimpleTrigger", "ps5000SetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps5000SetTriggerChannelConditions ( short handle, struct TRIGGER_CONDITIONS *conditions, short nConditions ); """ ps5000.make_symbol("_SetTriggerChannelConditions", "ps5000SetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps5000SetTriggerChannelDirections ( short handle, THRESHOLD_DIRECTION channelA, THRESHOLD_DIRECTION channelB, THRESHOLD_DIRECTION channelC, THRESHOLD_DIRECTION channelD, THRESHOLD_DIRECTION ext, THRESHOLD_DIRECTION aux ); """ ps5000.make_symbol("_SetTriggerChannelDirections", "ps5000SetTriggerChannelDirections", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps5000SetTriggerChannelProperties ( short handle, struct TRIGGER_CHANNEL_PROPERTIES *channelProperties, short nChannelProperties, short auxOutputEnable, long autoTriggerMilliseconds ); """ ps5000.make_symbol("_SetTriggerChannelProperties", "ps5000SetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000SetTriggerDelay ( short handle, unsigned long delay ); """ ps5000.make_symbol("_SetTriggerDelay", "ps5000SetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps5000SigGenSoftwareControl ( short handle, short state ); """ ps5000.make_symbol("_SigGenSoftwareControl", "ps5000SigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps5000Stop ( short handle ); """ ps5000.make_symbol("_Stop", "ps5000Stop", c_uint32, [c_int16], doc) doc = """ void ps5000BlockReady ( short handle, PICO_STATUS status, void *pParameter ); """ ps5000.BlockReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p) ps5000.BlockReadyType.__doc__ = doc doc = """ void (CALLBACK *ps5000DataReady) ( short handle, long noOfSamples, short overflow, unsigned long triggerAt, short triggered, void *pParameter ); """ ps5000.DataReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_int16, c_uint32, c_int16, c_void_p) ps5000.DataReadyType.__doc__ = doc doc = """ void (CALLBACK *ps5000StreamingReady) ( short handle, long noOfSamples, unsigned long startIndex, short overflow, unsigned long triggerAt, short triggered, short autoStop, void *pParameter ); """ ps5000.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps5000.StreamingReadyType.__doc__ = doc ================================================ FILE: picosdk/ps5000a.py ================================================ # # Copyright (C) 2014-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps5000aApi.h C header file for PicoScope 5000 Series oscilloscopes using the ps5000a driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class Ps5000alib(Library): def __init__(self): super(Ps5000alib, self).__init__("ps5000a") ps5000a = Ps5000alib() ps5000a.PS5000A_DEVICE_RESOLUTION = make_enum([ "PS5000A_DR_8BIT", "PS5000A_DR_12BIT", "PS5000A_DR_14BIT", "PS5000A_DR_15BIT", "PS5000A_DR_16BIT", ]) ps5000a.DEFAULT_RESOLUTION = ps5000a.PS5000A_DEVICE_RESOLUTION["PS5000A_DR_8BIT"] ps5000a.PS5000A_COUPLING = make_enum([ 'PS5000A_AC', 'PS5000A_DC', ]) # Just use AC and DC. ps5000a.PICO_COUPLING = {k[-2:]: v for k, v in ps5000a.PS5000A_COUPLING.items()} ps5000a.PS5000A_BANDWIDTH_LIMITER = make_enum([ 'PS5000A_BW_FULL', 'PS5000A_BW_20MHZ', ]) def _define_channel(): PS5000A_CHANNEL_A = 0 PS5000A_CHANNEL_B = 1 PS5000A_CHANNEL_C = 2 PS5000A_CHANNEL_D = 3 PS5000A_EXTERNAL = PS5000A_MAX_CHANNELS = 4 PS5000A_TRIGGER_AUX = 5 PS5000A_MAX_TRIGGER_SOURCE = 6 PS5000A_DIGITAL_PORT0 = 0x80 PS5000A_DIGITAL_PORT1 = PS5000A_DIGITAL_PORT0 + 1 PS5000A_DIGITAL_PORT2 = PS5000A_DIGITAL_PORT0 + 2 PS5000A_DIGITAL_PORT3 = PS5000A_DIGITAL_PORT0 + 3 PS5000A_PULSE_WIDTH_SOURCE = 0x10000000 return {k.upper(): v for k, v in locals().items() if k.startswith("PS5000A")} ps5000a.PS5000A_CHANNEL = _define_channel() # only include the normal analog channels for now: ps5000a.PICO_CHANNEL = {k[-1]: v for k, v in ps5000a.PS5000A_CHANNEL.items() if "PS5000A_CHANNEL_" in k} ps5000a.PS5000A_RANGE = make_enum([ "PS5000A_10MV", "PS5000A_20MV", "PS5000A_50MV", "PS5000A_100MV", "PS5000A_200MV", "PS5000A_500MV", "PS5000A_1V", "PS5000A_2V", "PS5000A_5V", "PS5000A_10V", "PS5000A_20V", "PS5000A_50V", "PS5000A_MAX_RANGES", ]) ps5000a.PS5000A_THRESHOLD_DIRECTION = make_enum([ ("PS5000A_ABOVE", "PS5000A_INSIDE"), ("PS5000A_BELOW", "PS5000A_OUTSIDE"), ("PS5000A_RISING", "PS5000A_ENTER", "PS5000A_NONE"), ("PS5000A_FALLING", "PS5000A_EXIT"), ("PS5000A_RISING_OR_FALLING", "PS5000A_ENTER_OR_EXIT"), "PS5000A_ABOVE_LOWER", "PS5000A_BELOW_LOWER", "PS5000A_RISING_LOWER", "PS5000A_FALLING_LOWER", "PS5000A_POSITIVE_RUNT", "PS5000A_NEGATIVE_RUNT", ]) ps5000a.PICO_VOLTAGE_RANGE = { v: float(k.split('_')[1][:-1]) if k[-2] != 'M' else (0.001 * float(k.split('_')[1][:-2])) for k, v in ps5000a.PS5000A_RANGE.items() if k != "PS5000A_MAX_RANGES" } ps5000a.PS5000A_DIGITAL_CHANNEL = make_enum([ "PS5000A_DIGITAL_CHANNEL_0", "PS5000A_DIGITAL_CHANNEL_1", "PS5000A_DIGITAL_CHANNEL_2", "PS5000A_DIGITAL_CHANNEL_3", "PS5000A_DIGITAL_CHANNEL_4", "PS5000A_DIGITAL_CHANNEL_5", "PS5000A_DIGITAL_CHANNEL_6", "PS5000A_DIGITAL_CHANNEL_7", "PS5000A_DIGITAL_CHANNEL_8", "PS5000A_DIGITAL_CHANNEL_9", "PS5000A_DIGITAL_CHANNEL_10", "PS5000A_DIGITAL_CHANNEL_11", "PS5000A_DIGITAL_CHANNEL_12", "PS5000A_DIGITAL_CHANNEL_13", "PS5000A_DIGITAL_CHANNEL_14", "PS5000A_DIGITAL_CHANNEL_15", "PS5000A_DIGITAL_CHANNEL_16", "PS5000A_DIGITAL_CHANNEL_17", "PS5000A_DIGITAL_CHANNEL_18", "PS5000A_DIGITAL_CHANNEL_19", "PS5000A_DIGITAL_CHANNEL_20", "PS5000A_DIGITAL_CHANNEL_21", "PS5000A_DIGITAL_CHANNEL_22", "PS5000A_DIGITAL_CHANNEL_23", "PS5000A_DIGITAL_CHANNEL_24", "PS5000A_DIGITAL_CHANNEL_25", "PS5000A_DIGITAL_CHANNEL_26", "PS5000A_DIGITAL_CHANNEL_27", "PS5000A_DIGITAL_CHANNEL_28", "PS5000A_DIGITAL_CHANNEL_29", "PS5000A_DIGITAL_CHANNEL_30", "PS5000A_DIGITAL_CHANNEL_31", "PS5000A_MAX_DIGITAL_CHANNELS" ]) ps5000a.PS5000A_DIGITAL_DIRECTION = make_enum([ "PS5000A_DIGITAL_DONT_CARE", "PS5000A_DIGITAL_DIRECTION_LOW", "PS5000A_DIGITAL_DIRECTION_HIGH", "PS5000A_DIGITAL_DIRECTION_RISING", "PS5000A_DIGITAL_DIRECTION_FALLING", "PS5000A_DIGITAL_DIRECTION_RISING_OR_FALLING", "PS5000A_DIGITAL_MAX_DIRECTION" ]) def _define_conditionsInfo(): PS5000A_CLEAR = 0x00000001 PS5000A_ADD = 0x00000002 return {k.upper(): v for k, v in locals().items() if k.startswith("PS5000A")} ps5000a.PS5000AConditionsInfo = _define_conditionsInfo() ps5000a.PS5000A_THRESHOLD_MODE = make_enum([ "PS5000A_LEVEL", "PS5000A_WINDOW" ]) ps5000a.PS5000A_TRIGGER_STATE = make_enum([ "PS5000A_CONDITION_DONT_CARE", "PS5000A_CONDITION_TRUE", "PS5000A_CONDITION_FALSE", "PS5000A_CONDITION_MAX" ]) ps5000a.PS5000A_RATIO_MODE = { 'PS5000A_RATIO_MODE_NONE': 0, 'PS5000A_RATIO_MODE_AGGREGATE': 1, 'PS5000A_RATIO_MODE_DECIMATE': 2, 'PS5000A_RATIO_MODE_AVERAGE': 4, } ps5000a.PICO_RATIO_MODE = {k[19:]: v for k, v in ps5000a.PS5000A_RATIO_MODE.items()} ps5000a.PS5000A_TIME_UNITS = make_enum([ 'PS5000A_FS', 'PS5000A_PS', 'PS5000A_NS', 'PS5000A_US', 'PS5000A_MS', 'PS5000A_S', 'PS5000A_MAX_TIME_UNITS', ]) ps5000a.PS5000A_PULSE_WIDTH_TYPE = make_enum([ 'PS5000A_PW_TYPE_NONE', 'PS5000A_PW_TYPE_LESS_THAN', 'PS5000A_PW_TYPE_GREATER_THAN', 'PS5000A_PW_TYPE_IN_RANGE', 'PS5000A_PW_TYPE_OUT_OF_RANGE', ]) class PS5000A_TRIGGER_INFO(Structure): _pack_ = 1 _fields_ = [("status", c_uint32), ("segmentIndex", c_uint32), ("triggerIndex", c_uint32), ("triggerTime", c_int64), ("timeUnits", c_int16), ("reserved0", c_int16), ("timeStampCounter", c_uint64)] ps5000a.PS5000A_TRIGGER_INFO = PS5000A_TRIGGER_INFO class PS5000A_DIGITAL_CHANNEL_DIRECTIONS(Structure): _pack_ = 1 _fields_ = [("channel", c_int32), ("direction", c_int32)] ps5000a.PS5000A_DIGITAL_CHANNEL_DIRECTIONS = PS5000A_DIGITAL_CHANNEL_DIRECTIONS class PS5000A_DIRECTION(Structure): _pack_ = 1 _fields_ = [("channel", c_int32), ("direction", c_int32), ("mode", c_int32)] ps5000a.PS5000A_DIRECTION = PS5000A_DIRECTION class PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(Structure): _pack_ = 1 _fields_ = [("thresholdUpper", c_int16), ("thresholdUpperHysteresis", c_uint16), ("thresholdLower", c_int16), ("thresholdLowerHysteresis", c_uint16), ("channel", c_int32)] ps5000a.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2 = PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2 class PS5000A_CONDITION (Structure): _pack_ = 1 _fields_ = [("source", c_int32), ("condition", c_int32)] ps5000a.PS5000A_CONDITION = PS5000A_CONDITION class PS5000A_PWQ_CONDITIONS (Structure): _pack_ = 1 _fields_ = [("channelA", c_int16), ("channelB", c_int16), ("channelC", c_int16), ("channelD", c_int16), ("external", c_int16), ("aux", c_int16)] ps5000a.PS5000A_PWQ_CONDITIONS = PS5000A_PWQ_CONDITIONS doc = """ PICO_STATUS (ps5000aOpenUnit) ( int16_t *handle, int8_t *serial, PS5000A_DEVICE_RESOLUTION resolution ); """ ps5000a.make_symbol("_OpenUnit", "ps5000aOpenUnit", c_uint32, [c_void_p, c_char_p, c_int32], doc) doc = """ PICO_STATUS ps5000aOpenUnitAsync ( int16_t *status, int8_t *serial, PS5000A_DEVICE_RESOLUTION resolution ); """ ps5000a.make_symbol("_OpenUnitAsync", "ps5000aOpenUnitAsync", c_uint32, [c_void_p, c_char_p, c_int32], doc) doc = """ PICO_STATUS ps5000aOpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps5000a.make_symbol("_OpenUnitProgress", "ps5000aOpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps5000a.make_symbol("_GetUnitInfo", "ps5000aGetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps5000aFlashLed ( int16_t handle, int16_t start ); """ ps5000a.make_symbol("_FlashLed", "ps5000aFlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps5000aIsLedFlashing ( int16_t handle, int16_t *status ); """ ps5000a.make_symbol("_IsLedFlashing", "ps5000aIsLedFlashing", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aCloseUnit ( int16_t handle ); """ ps5000a.make_symbol("_CloseUnit", "ps5000aCloseUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps5000aMemorySegments ( int16_t handle, uint32_t nSegments, int32_t *nMaxSamples ); """ ps5000a.make_symbol("_MemorySegments", "ps5000aMemorySegments", c_uint32, [c_int16, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps5000aSetChannel ( int16_t handle, PS5000a_CHANNEL channel, int16_t enabled, PS5000a_COUPLING type, PS5000a_RANGE range, float analogOffset ); """ ps5000a.make_symbol("_SetChannel", "ps5000aSetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int32, c_float], doc) doc = """ PICO_STATUS ps5000aSetBandwidthFilter ( int16_t handle, PS5000A_CHANNEL channel, PS5000A_BANDWIDTH_LIMITER bandwidth ); """ ps5000a.make_symbol("_SetBandwidthFilter", "ps5000aSetBandwidthFilter", c_uint32, [c_int16, c_int32, c_int32], doc) doc = """ PICO_STATUS ps5000aGetTimebase ( int16_t handle, uint32_t timebase, int32_t noSamples, int32_t *timeIntervalNanoseconds, int32_t *maxSamples, uint32_t segmentIndex ); """ ps5000a.make_symbol("_GetTimebase", "ps5000aGetTimebase", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps5000aGetTimebase2 ( int16_t handle, uint32_t timebase, int32_t noSamples, float *timeIntervalNanoseconds, int32_t *maxSamples, uint32_t segmentIndex ); """ ps5000a.make_symbol("_GetTimebase2", "ps5000aGetTimebase2", c_uint32, [c_int16, c_uint32, c_int32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps5000aSetSigGenArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, int16_t *arbitraryWaveform, int32_t arbitraryWaveformSize, PS5000A_SWEEP_TYPE sweepType, PS5000A_EXTRA_OPERATIONS operation, PS5000A_INDEX_MODE indexMode, uint32_t shots, uint32_t sweeps, PS5000A_SIGGEN_TRIG_TYPE triggerType, PS5000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps5000a.make_symbol("_SetSigGenArbitrary", "ps5000aSetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps5000aSetSigGenBuiltInV2 ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, PS5000A_WAVE_TYPE waveType, double startFrequency, double stopFrequency, double increment, double dwellTime, PS5000A_SWEEP_TYPE sweepType, PS5000A_EXTRA_OPERATIONS operation, uint32_t shots, uint32_t sweeps, PS5000A_SIGGEN_TRIG_TYPE triggerType, PS5000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps5000a.make_symbol("_SetSigGenBuiltIn", "ps5000aSetSigGenBuiltInV2", c_uint32, [c_int16, c_int32, c_uint32, c_int32, c_double, c_double, c_double, c_double, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps5000aSetSigGenPropertiesArbitrary ( int16_t handle, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, PS5000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS5000A_SIGGEN_TRIG_TYPE triggerType, PS5000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps5000a.make_symbol("_SetSigGenPropertiesArbitrary", "ps5000aSetSigGenPropertiesArbitrary", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps5000aSetSigGenPropertiesBuiltIn ( int16_t handle, double startFrequency, double stopFrequency, double increment, double dwellTime, PS5000A_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS5000A_SIGGEN_TRIG_TYPE triggerType, PS5000A_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps5000a.make_symbol("_SetSigGenPropertiesBuiltIn", "ps5000aSetSigGenPropertiesBuiltIn", c_uint32, [c_int16, c_double, c_double, c_double, c_double, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps5000aSigGenFrequencyToPhase ( int16_t handle, double frequency, PS5000A_INDEX_MODE indexMode, uint32_t bufferLength, uint32_t *phase ); """ ps5000a.make_symbol("_SigGenFrequencyToPhase", "ps5000aSigGenFrequencyToPhase", c_uint32, [c_int16, c_double, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps5000aSigGenArbitraryMinMaxValues ( int16_t handle, int16_t *minArbitraryWaveformValue, int16_t *maxArbitraryWaveformValue, uint32_t *minArbitraryWaveformSize, uint32_t *maxArbitraryWaveformSize ); """ ps5000a.make_symbol("_SigGenArbitraryMinMaxValues", "ps5000aSigGenArbitraryMinMaxValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aSigGenSoftwareControl ( int16_t handle, int16_t state ); """ ps5000a.make_symbol("_SigGenSoftwareControl", "ps5000aSigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps5000aSetEts ( int16_t handle, PS5000A_ETS_MODE mode, int16_t etsCycles, int16_t etsInterleave, int32_t *sampleTimePicoseconds ); """ ps5000a.make_symbol("_SetEts", "ps5000aSetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aSetTriggerChannelProperties ( int16_t handle, PS5000A_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, int32_t autoTriggerMilliseconds ); """ ps5000a.make_symbol("_SetTriggerChannelProperties", "ps5000aSetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000aSetTriggerChannelPropertiesV2 ( int16_t handle, PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2 *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, ); """ ps5000a.make_symbol("_SetTriggerChannelPropertiesV2", "ps5000aSetTriggerChannelPropertiesV2", c_uint32, [c_int16, c_void_p, c_int16, c_int16], doc) doc = """ PICO_STATUS ps5000aSetAutoTriggerMicroSeconds ( int16_t handle, uint64_t autoTriggerMicroseconds, ); """ ps5000a.make_symbol("_SetAutoTriggerMicroSeconds", "ps5000aSetAutoTriggerMicroSeconds", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS ps5000aSetTriggerChannelConditions ( int16_t handle, PS5000A_TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps5000a.make_symbol("_SetTriggerChannelConditions", "ps5000aSetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps5000aSetTriggerChannelConditionsV2 ( int16_t handle, PS5000A_CONDITION *conditions, int16_t nConditions PS5000A_CONDITIONS_INFO info ); """ ps5000a.make_symbol("_SetTriggerChannelConditionsV2", "ps5000aSetTriggerChannelConditionsV2", c_uint32, [c_int16, c_void_p, c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000aSetTriggerChannelDirections ( int16_t handle, PS5000A_THRESHOLD_DIRECTION channelA, PS5000A_THRESHOLD_DIRECTION channelB, PS5000A_THRESHOLD_DIRECTION channelC, PS5000A_THRESHOLD_DIRECTION channelD, PS5000A_THRESHOLD_DIRECTION ext, PS5000A_THRESHOLD_DIRECTION aux ); """ ps5000a.make_symbol("_SetTriggerChannelDirections", "ps5000aSetTriggerChannelDirections", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps5000aSetTriggerChannelDirectionsV2 ( int16_t handle, PS5000A_DIRECTION *directions uint16_t nDirections ); """ ps5000a.make_symbol("_SetTriggerChannelDirectionsV2", "ps5000aSetTriggerChannelDirectionsV2", c_uint32, [c_int16, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps5000aSetSimpleTrigger ( int16_t handle, int16_t enable, PS5000A_CHANNEL source, int16_t threshold, PS5000A_THRESHOLD_DIRECTION direction, uint32_t delay, int16_t autoTrigger_ms ); """ ps5000a.make_symbol("_SetSimpleTrigger", "ps5000aSetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps5000aSetTriggerDelay ( int16_t handle, uint32_t delay ); """ ps5000a.make_symbol("_SetTriggerDelay", "ps5000aSetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps5000aSetPulseWidthQualifier ( int16_t handle, PS5000A_PWQ_CONDITIONS *conditions, int16_t nConditions, PS5000A_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS5000A_PULSE_WIDTH_TYPE type ); """ ps5000a.make_symbol("_SetPulseWidthQualifier", "ps5000aSetPulseWidthQualifier", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps5000aIsTriggerOrPulseWidthQualifierEnabled ( int16_t handle, int16_t *triggerEnabled, int16_t *pulseWidthQualifierEnabled ); """ ps5000a.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps5000aIsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetTriggerTimeOffset64 ( int16_t handle, int64_t *time, PS5000A_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps5000a.make_symbol("_GetTriggerTimeOffset", "ps5000aGetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps5000aGetValuesTriggerTimeOffsetBulk64 ( int16_t handle, int64_t *times, PS5000A_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps5000a.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps5000aGetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps5000aSetDataBuffers ( int16_t handle, PS5000A_CHANNEL channel, int16_t *bufferMax, int16_t *bufferMin, int32_t bufferLth, uint32_t segmentIndex, PS5000A_RATIO_MODE mode ); """ ps5000a.make_symbol("_SetDataBuffers", "ps5000aSetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps5000aSetDataBuffer ( int16_t handle, PS5000A_CHANNEL channel, int16_t *buffer, int32_t bufferLth, uint32_t segmentIndex, PS5000A_RATIO_MODE mode ); """ ps5000a.make_symbol("_SetDataBuffer", "ps5000aSetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_int32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps5000aSetEtsTimeBuffer ( int16_t handle, int64_t *buffer, int32_t bufferLth ); """ ps5000a.make_symbol("_SetEtsTimeBuffer", "ps5000aSetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps5000aIsReady ( int16_t handle, int16_t *ready ); """ ps5000a.make_symbol("_IsReady", "ps5000aIsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aRunBlock ( int16_t handle, int32_t noOfPreTriggerSamples, int32_t noOfPostTriggerSamples, uint32_t timebase, int32_t *timeIndisposedMs, uint32_t segmentIndex, ps5000aBlockReady lpReady, void *pParameter ); """ ps5000a.make_symbol("_RunBlock", "ps5000aRunBlock", c_uint32, [c_int16, c_int32, c_int32, c_uint32, c_void_p, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aRunStreaming ( int16_t handle, uint32_t *sampleInterval, PS5000A_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostPreTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, PS5000A_RATIO_MODE downSampleRatioMode, uint32_t overviewBufferSize ); """ ps5000a.make_symbol("_RunStreaming", "ps5000aRunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps5000aGetStreamingLatestValues ( int16_t handle, ps5000aStreamingReady lpPs5000aReady, void *pParameter ); """ ps5000a.make_symbol("_GetStreamingLatestValues", "ps5000aGetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ void *ps5000aStreamingReady ( int16_t handle, int32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void *pParameter ); define a python function which accepts the correct arguments, and pass it to the constructor of this type. """ ps5000a.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps5000a.StreamingReadyType.__doc__ = doc doc = """void *ps5000aBlockReady ( int16_t handle, PICO_STATUS status, void *pParameter ); """ ps5000a.BlockReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int32, c_void_p) ps5000a.BlockReadyType.__doc__ = doc doc = """ PICO_STATUS ps5000aNoOfStreamingValues ( int16_t handle, uint32_t *noOfValues ); """ ps5000a.make_symbol("_NoOfStreamingValues", "ps5000aNoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetMaxDownSampleRatio ( int16_t handle, uint32_t noOfUnaggreatedSamples, uint32_t *maxDownSampleRatio, PS5000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex ); """ ps5000a.make_symbol("_GetMaxDownSampleRatio", "ps5000aGetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps5000aGetValues ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS5000a_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps5000a.make_symbol("_GetValues", "ps5000aGetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetValuesAsync ( int16_t handle, uint32_t startIndex, uint32_t noOfSamples, uint32_t downSampleRatio, PS5000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, void *lpDataReady, void *pParameter ); """ ps5000a.make_symbol("_GetValuesAsync", "ps5000aGetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetValuesBulk ( int16_t handle, uint32_t *noOfSamples, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, uint32_t downSampleRatio, PS5000A_RATIO_MODE downSampleRatioMode, int16_t *overflow ); """ ps5000a.make_symbol("_GetValuesBulk", "ps5000aGetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32, c_uint32, c_int32, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetValuesOverlapped ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS5000A_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps5000a.make_symbol("_GetValuesOverlapped", "ps5000aGetValuesOverlapped", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetValuesOverlappedBulk ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS5000A_RATIO_MODE downSampleRatioMode, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, int16_t *overflow ); """ ps5000a.make_symbol("_GetValuesOverlappedBulk", "ps5000aGetValuesOverlappedBulk", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps5000aTriggerWithinPreTriggerSamples ( int16_t handle, PS5000A_TRIGGER_WITHIN_PRE_TRIGGER state ); """ ps5000a.make_symbol("_TriggerWithinPreTriggerSamples", "ps5000aTriggerWithinPreTriggerSamples", c_uint32, [c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000aGetTriggerInfoBulk ( int16_t handle, PS5000A_TRIGGER_INFO *triggerInfo, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps5000a.make_symbol("_GetTriggerInfoBulk", "ps5000aGetTriggerInfoBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps5000aEnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps5000a.make_symbol("_EnumerateUnits", "ps5000aEnumerateUnits", c_uint32, [c_void_p, c_char_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetChannelInformation ( int16_t handle, PS5000A_CHANNEL_INFO info, int32_t probe, int32_t *ranges, int32_t *length, int32_t channels ); """ ps5000a.make_symbol("_GetChannelInformation", "ps5000aGetChannelInformation", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p, c_int32], doc) doc = """ PICO_STATUS ps5000aMaximumValue ( int16_t handle, int16_t *value ); """ ps5000a.make_symbol("_MaximumValue", "ps5000aMaximumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aMinimumValue ( int16_t handle, int16_t *value ); """ ps5000a.make_symbol("_MinimumValue", "ps5000aMinimumValue", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetAnalogueOffset ( int16_t handle, PS5000A_RANGE range, PS5000A_COUPLING coupling, float *maximumVoltage, float *minimumVoltage ); """ ps5000a.make_symbol("_GetAnalogueOffset", "ps5000aGetAnalogueOffset", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetMaxSegments ( int16_t handle, uint32_t *maxSegments ); """ ps5000a.make_symbol("_GetMaxSegments", "ps5000aGetMaxSegments", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aChangePowerSource ( int16_t handle, PICO_STATUS powerState ); """ ps5000a.make_symbol("_ChangePowerSource", "ps5000aChangePowerSource", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps5000aCurrentPowerSource ( int16_t handle ); """ ps5000a.make_symbol("_CurrentPowerSource", "ps5000aCurrentPowerSource", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps5000aStop ( int16_t handle ); """ ps5000a.make_symbol("_Stop", "ps5000aStop", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps5000aPingUnit ( int16_t handle ); """ ps5000a.make_symbol("_PingUnit", "ps5000aPingUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps5000aSetNoOfCaptures ( int16_t handle, uint32_t nCaptures ); """ ps5000a.make_symbol("_SetNoOfCaptures", "ps5000aSetNoOfCaptures", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps5000aGetNoOfCaptures ( int16_t handle, uint32_t *nCaptures ); """ ps5000a.make_symbol("_GetNoOfCaptures", "ps5000aGetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aGetNoOfProcessedCaptures ( int16_t handle, uint32_t *nProcessedCaptures ); """ ps5000a.make_symbol("_GetNoOfProcessedCaptures", "ps5000aGetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aSetDeviceResolution ( int16_t handle, PS5000A_DEVICE_RESOLUTION resolution ); """ ps5000a.make_symbol("_SetDeviceResolution", "ps5000aSetDeviceResolution", c_uint32, [c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000aGetDeviceResolution ( int16_t handle, PS5000A_DEVICE_RESOLUTION *resolution ); """ ps5000a.make_symbol("_GetDeviceResolution", "ps5000aGetDeviceResolution", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps5000aSetDigitalPort ( int16_t handle, PS5000A_CHANNEL port, int16_t enabled, int16_t logicLevel ); """ ps5000a.make_symbol("_SetDigitalPort", "ps5000aSetDigitalPort", c_uint32, [c_int16, c_int32, c_int16, c_int16], doc) doc = """ PICO_STATUS ps5000aSetPulseWidthDigitalPortProperties ( int16_t handle, PS5000A_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps5000a.make_symbol("_SetPulseWidthDigitalPortProperties", "ps5000aSetPulseWidthDigitalPortProperties", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps5000aSetTriggerDigitalPortProperties ( int16_t handle, PS5000A_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps5000a.make_symbol("_SetTriggerDigitalPortProperties", "ps5000aSetTriggerDigitalPortProperties", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps5000aSetPulseWidthQualifierProperties ( int16_t handle, uint32_t lower, uint32_t upper, PS5000A_PULSE_WIDTH_TYPE type ); """ ps5000a.make_symbol("_SetPulseWidthQualifierProperties", "ps5000aSetPulseWidthQualifierProperties", c_uint32, [c_int16, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps5000aSetPulseWidthQualifierConditions ( int16_t handle, PS5000A_CONDITION *conditions, int16_t nConditions, PS5000A_CONDITIONS_INFO info ); """ ps5000a.make_symbol("_SetPulseWidthQualifierConditions", "ps5000aSetPulseWidthQualifierConditions", c_uint32, [c_int16, c_void_p, c_int16, c_int32], doc) doc = """ PICO_STATUS ps5000aSetPulseWidthQualifierDirections ( int16_t handle, PS5000A_DIRECTION *directions, int16_t nDirections ); """ ps5000a.make_symbol("_SetPulseWidthQualifierDirections", "ps5000aSetPulseWidthQualifierDirections", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps5000aGetMinimumTimebaseStateless ( int16_t handle, PS5000A_CHANNEL_FLAGS enabledChannelOrPortFlags, uint32_t *timebase, double *timeInterval, PS5000A_DEVICE_RESOLUTION resolution ); """ ps5000a.make_symbol("_GetMinimumTimebaseStateless", "ps5000aGetMinimumTimebaseStateless", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_uint32], doc) ================================================ FILE: picosdk/ps6000.py ================================================ # # Copyright (C) 2014-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps6000Api.h C header file for PicoScope 6000 Series oscilloscopes using the ps6000 driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.constants import make_enum class Ps6000lib(Library): def __init__(self): super(Ps6000lib, self).__init__("ps6000") ps6000 = Ps6000lib() ps6000.PS6000_RANGE = make_enum([ "PS6000A_10MV", "PS6000_20MV", "PS6000_50MV", "PS6000_100MV", "PS6000_200MV", "PS6000_500MV", "PS6000_1V", "PS6000_2V", "PS6000_5V", "PS6000_10V", "PS6000_20V", "PS6000_50V", "PS6000_MAX_RANGES", ]) ps6000.PS6000_CHANNEL = make_enum([ "PS6000_CHANNEL_A", "PS6000_CHANNEL_B", "PS6000_CHANNEL_C", "PS6000_CHANNEL_D", ("PS6000_EXTERNAL", "PS6000_MAX_CHANNELS"), "PS6000_TRIGGER_AUX", "PS6000_MAX_TRIGGER_SOURCES", ]) ps6000.PS6000_COUPLING = make_enum([ "PS6000_AC", "PS6000_DC_1M", "PS6000_DC_50R", ]) ps6000.PS6000_BANDWIDTH_LIMITER = make_enum([ "PS6000_BW_FULL", "PS6000_BW_20MHZ", "PS6000_BW_25MHZ", ]) ps6000.PS6000_RATIO_MODE = { "PS6000_RATIO_MODE_NONE" : 0, "PS6000_RATIO_MODE_AGGREGATE" : 1, "PS6000_RATIO_MODE_AVERAGE" : 2, "PS6000_RATIO_MODE_DECIMATE" : 4, "PS6000_RATIO_MODE_DISTRIBUTION" : 8, } ps6000.PS6000_TIME_UNITS = make_enum([ "PS6000_FS", "PS6000_PS", "PS6000_NS", "PS6000_US", "PS6000_MS", "PS6000_S", "PS6000_MAX_TIME_UNITS", ]) ps6000.PS6000_TRIGGER_STATE = make_enum([ "PS6000_CONDITION_DONT_CARE", "PS6000_CONDITION_TRUE", "PS6000_CONDITION_FALSE", "PS6000_CONDITION_MAX", ]) ps6000.PS6000_THRESHOLD_DIRECTION = make_enum([ ("PS6000_ABOVE", "PS6000_INSIDE"), ("PS6000_BELOW", "PS6000_BELOW"), ("PS6000_RISING", "PS6000_ENTER", "PS6000_NONE"), ("PS6000_FALLING", "PS6000_EXIT"), ("PS6000_RISING_OR_FALLING", "PS6000_ENTER_OR_EXIT"), "PS6000_ABOVE_LOWER", "PS6000_BELOW_LOWER", "PS6000_RISING_LOWER", "PS6000_FALLING_LOWER", "PS6000_POSITIVE_RUNT", "PS6000_NEGATIVE_RUNT", ]) ps6000.PS6000_THRESHOLD_MODE = make_enum([ "PS6000_LEVEL", "PS6000_WINDOW", ]) ps6000.PS6000_PULSE_WIDTH_TYPE = make_enum([ "PS6000_PW_TYPE_NONE", "PS6000_PW_TYPE_LESS_THAN", "PS6000_PW_TYPE_GREATER_THAN", "PS6000_PW_TYPE_IN_RANGE", "PS6000_PW_TYPE_OUT_OF_RANGE" ]) ps6000.PICO_INFO = { "PICO_DRIVER_VERSION" : 0, "PICO_USB_VERSION" : 1, "PICO_HARDWARE_VERSION" : 2, "PICO_VARIANT_INFO" : 3, "PICO_BATCH_AND_SERIAL" : 4, "PICO_CAL_DATE" : 5, "PICO_KERNAL_VERSION" : 6, "PICO_DIGITAL_HARDWARE_VERSION" : 7, "PICO_ANALOGUE_HARDWARE_VERSION" : 8, "PICO_FIRMWARE_VERSION_1" : 9, "PICO_FIREWARE_VERSION_2" : 'A' } class PS6000_TRIGGER_CONDITIONS (Structure): _pack_ = 1 _fields_ = [("channelA", c_uint32), ("channelB", c_uint32), ("channelC", c_uint32), ("channelD", c_uint32), ("external", c_uint32), ("aux", c_uint32), ("pulseWidthQualifier", c_uint32)] ps6000.PS6000_TRIGGER_CONDITIONS = PS6000_TRIGGER_CONDITIONS class PS6000_TRIGGER_CHANNEL_PROPERTIES (Structure): _pack_ = 1 _fields_ = [("thresholdUpper", c_int16), ("hysteresisUpper", c_uint16), ("thresholdLower", c_int16), ("hysteresisLower", c_uint16), ("channel", c_uint32), ("thresholdMode", c_uint32)] ps6000.PS6000_TRIGGER_CHANNEL_PROPERTIES = PS6000_TRIGGER_CHANNEL_PROPERTIES class PS6000_PWQ_CONDITIONS (Structure): _pack_ = 1 _fields_ = [("channelA", c_uint32), ("channelB", c_uint32), ("channelC", c_uint32), ("channelD", c_uint32), ("external", c_uint32), ("aux", c_uint32)] ps6000.PS6000_PWQ_CONDITIONS = PS6000_PWQ_CONDITIONS class PS6000_TRIGGER_INFO (Structure): _pack_ = 1 _fields_ = [("status", c_uint32), ("segmentIndex", c_uint32), ("triggerIndex", c_uint32), ("triggerTime", c_uint64), ("timeUnits", c_uint16), ("reserved0", c_uint16), ("timeStampCounter", c_uint64)] ps6000.PS6000_TRIGGER_INFO = PS6000_TRIGGER_INFO # some ps6000 scopes have 2GS of memory. ps6000.MAX_MEMORY = 2**31 doc = """ PICO_STATUS ps6000OpenUnit ( int16_t *handle, int8_t *serial ); """ ps6000.make_symbol("_OpenUnit", "ps6000OpenUnit", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps6000OpenUnitAsync ( int16_t *status, int8_t *serial ); """ ps6000.make_symbol("_OpenUnitAsync", "ps6000OpenUnitAsync", c_uint32, [c_void_p, c_char_p], doc) doc = """ PICO_STATUS ps6000OpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps6000.make_symbol("_OpenUnitProgress", "ps6000OpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000GetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps6000.make_symbol("_GetUnitInfo", "ps6000GetUnitInfo", c_uint32, [c_int16, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000FlashLed ( int16_t handle, int16_t start ); """ ps6000.make_symbol("_FlashLed", "ps6000FlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps6000CloseUnit ( int16_t handle ); """ ps6000.make_symbol("_CloseUnit", "ps6000CloseUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps6000MemorySegments ( int16_t handle, uint32_t nSegments, uint32_t *nMaxSamples ); """ ps6000.make_symbol("_MemorySegments", "ps6000MemorySegments", c_uint32, [c_int16, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000SetChannel ( int16_t handle, PS6000_CHANNEL channel, int16_t enabled, PS6000_COUPLING type, PS6000_RANGE range, float analogueOffset, PS6000_BANDWIDTH_LIMITER bandwidth ); """ ps6000.make_symbol("_SetChannel", "ps6000SetChannel", c_uint32, [c_int16, c_int32, c_int16, c_int32, c_int32, c_float, c_int32], doc) doc = """ PICO_STATUS ps6000GetTimebase ( int16_t handle, uint32_t timebase, uint32_t noSamples, int32_t *timeIntervalNanoseconds, int16_t oversample, uint32_t *maxSamples, uint32_t segmentIndex ); """ ps6000.make_symbol("_GetTimebase", "ps6000GetTimebase", c_uint32, [c_int16, c_uint32, c_uint32, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000GetTimebase2 ( int16_t handle, uint32_t timebase, uint32_t noSamples, float *timeIntervalNanoseconds, int16_t oversample, uint32_t *maxSamples, uint32_t segmentIndex ); """ ps6000.make_symbol("_GetTimebase2", "ps6000GetTimebase2", c_uint32, [c_int16, c_uint32, c_uint32, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000SetSigGenArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, int16_t *arbitraryWaveform, int32_t arbitraryWaveformSize, PS6000_SWEEP_TYPE sweepType, PS6000_EXTRA_OPERATIONS operation, PS6000_INDEX_MODE indexMode, uint32_t shots, uint32_t sweeps, PS6000_SIGGEN_TRIG_TYPE triggerType, PS6000_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps6000.make_symbol("_SetSigGenArbitrary", "ps6000SetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_void_p, c_int32, c_int32, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps6000SetSigGenBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t waveType, float startFrequency, float stopFrequency, float increment, float dwellTime, PS6000_SWEEP_TYPE sweepType, PS6000_EXTRA_OPERATIONS operation, uint32_t shots, uint32_t sweeps, PS6000_SIGGEN_TRIG_TYPE triggerType, PS6000_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps6000.make_symbol("_SetSigGenBuiltIn", "ps6000SetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_float, c_float, c_float, c_float, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps6000SetSigGenBuiltInV2 ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t waveType, double startFrequency, double stopFrequency, double increment, double dwellTime, PS6000_SWEEP_TYPE sweepType, PS6000_EXTRA_OPERATIONS operation, uint32_t shots, uint32_t sweeps, PS6000_SIGGEN_TRIG_TYPE triggerType, PS6000_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps6000.make_symbol("_SetSigGenBuiltInV2", "ps6000SetSigGenBuiltInV2", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_double, c_double, c_double, c_double, c_int32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps6000SetSigGenPropertiesArbitrary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, uint32_t startDeltaPhase, uint32_t stopDeltaPhase, uint32_t deltaPhaseIncrement, uint32_t dwellCount, PS6000_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS6000_SIGGEN_TRIG_TYPE triggerType, PS6000_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps6000.make_symbol("_SigGenPropertiesArbitrary", "ps6000SetSigGenPropertiesArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_uint32, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps6000SetSigGenPropertiesBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, double startFrequency, double stopFrequency, double increment, double dwellTime, PS6000_SWEEP_TYPE sweepType, uint32_t shots, uint32_t sweeps, PS6000_SIGGEN_TRIG_TYPE triggerType, PS6000_SIGGEN_TRIG_SOURCE triggerSource, int16_t extInThreshold ); """ ps6000.make_symbol("_SetSigGenPropertiesBuiltIn", "ps6000SetSigGenPropertiesBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_double, c_double, c_double, c_double, c_int32, c_uint32, c_uint32, c_int32, c_int32, c_int16], doc) doc = """ PICO_STATUS ps6000SigGenFrequencyToPhase ( int16_t handle, double frequency, PS6000_INDEX_MODE indexMode, uint32_t bufferLength, uint32_t *phase ); """ ps6000.make_symbol("_SigGenFrequencyToPhase", "ps6000SigGenFrequencyToPhase", c_uint32, [c_int16, c_double, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000SigGenArbitraryMinMaxValues ( int16_t handle, int16_t *minArbitraryWaveformValue, int16_t *maxArbitraryWaveformValue, uint32_t *minArbitraryWaveformSize, uint32_t *maxArbitraryWaveformSize ); """ ps6000.make_symbol("_SigGenArbitraryMinMaxValues", "ps6000SigGenArbitraryMinMaxValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000SigGenSoftwareControl ( int16_t handle, int16_t state ); """ ps6000.make_symbol("_SigGenSoftwareControl", "ps6000SigGenSoftwareControl", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps6000SetSimpleTrigger ( int16_t handle, int16_t enable, PS6000_CHANNEL source, int16_t threshold, PS6000_THRESHOLD_DIRECTION direction, uint32_t delay, int16_t autoTrigger_ms ); """ ps6000.make_symbol("_SetSimpleTrigger", "ps6000SetSimpleTrigger", c_uint32, [c_int16, c_int16, c_int32, c_int16, c_int32, c_uint32, c_int16], doc) doc = """ PICO_STATUS ps6000SetEts ( int16_t handle, PS6000_ETS_MODE mode, int16_t etsCycles, int16_t etsInterleave, int32_t *sampleTimePicoseconds ); """ ps6000.make_symbol("_SetEts", "ps6000SetEts", c_uint32, [c_int16, c_int32, c_int16, c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000SetTriggerChannelProperties ( int16_t handle, PS6000_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, int32_t autoTriggerMilliseconds ); """ ps6000.make_symbol("_SetTriggerChannelProperties", "ps6000SetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_int32], doc) doc = """ PICO_STATUS ps6000SetTriggerChannelConditions ( int16_t handle, PS6000_TRIGGER_CONDITIONS *conditions, int16_t nConditions ); """ ps6000.make_symbol("_SetTriggerChannelConditions", "ps6000SetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps6000SetTriggerChannelDirections ( int16_t handle, PS6000_THRESHOLD_DIRECTION channelA, PS6000_THRESHOLD_DIRECTION channelB, PS6000_THRESHOLD_DIRECTION channelC, PS6000_THRESHOLD_DIRECTION channelD, PS6000_THRESHOLD_DIRECTION ext, PS6000_THRESHOLD_DIRECTION aux ); """ ps6000.make_symbol("_SetTriggerChannelDirections", "ps6000SetTriggerChannelDirections", c_uint32, [c_int16, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32], doc) doc = """ PICO_STATUS ps6000SetTriggerDelay ( int16_t handle, uint32_t delay ); """ ps6000.make_symbol("_SetTriggerDelay", "ps6000SetTriggerDelay", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000SetPulseWidthQualifier ( int16_t handle, PS6000_PWQ_CONDITIONS *conditions, int16_t nConditions, PS6000_THRESHOLD_DIRECTION direction, uint32_t lower, uint32_t upper, PS6000_PULSE_WIDTH_TYPE type ); """ ps6000.make_symbol("_SetPulseWidthQualifier", "ps6000SetPulseWidthQualifier", c_uint32, [c_int16, c_void_p, c_int16, c_int32, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps6000IsTriggerOrPulseWidthQualifierEnabled ( int16_t handle, int16_t *triggerEnabled, int16_t *pulseWidthQualifierEnabled ); """ ps6000.make_symbol("_IsTriggerOrPulseWidthQualifierEnabled", "ps6000IsTriggerOrPulseWidthQualifierEnabled", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000GetTriggerTimeOffset ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, PS6000_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps6000.make_symbol("_GetTriggerTimeOffset", "ps6000GetTriggerTimeOffset", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000GetTriggerTimeOffset64 ( int16_t handle, int64_t *time, PS6000_TIME_UNITS *timeUnits, uint32_t segmentIndex ); """ ps6000.make_symbol("_GetTriggerTimeOffset64", "ps6000GetTriggerTimeOffset64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000GetValuesTriggerTimeOffsetBulk ( int16_t handle, uint32_t *timesUpper, uint32_t *timesLower, PS6000_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps6000.make_symbol("_ps6000GetValuesTriggerTimeOffsetBulk", "ps6000GetValuesTriggerTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps6000GetValuesTriggerTimeOffsetBulk64 ( int16_t handle, int64_t *times, PS6000_TIME_UNITS *timeUnits, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps6000.make_symbol("_GetValuesTriggerTimeOffsetBulk64", "ps6000GetValuesTriggerTimeOffsetBulk64", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps6000SetDataBuffers ( int16_t handle, PS6000_CHANNEL channel, int16_t *bufferMax, int16_t *bufferMin, uint32_t bufferLth, PS6000_RATIO_MODE downSampleRatioMode ); """ ps6000.make_symbol("_SetDataBuffers", "ps6000SetDataBuffers", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps6000SetDataBuffer ( int16_t handle, PS6000_CHANNEL channel, int16_t *buffer, uint32_t bufferLth, PS6000_RATIO_MODE downSampleRatioMode ); """ ps6000.make_symbol("_SetDataBuffer", "ps6000SetDataBuffer", c_uint32, [c_int16, c_int32, c_void_p, c_uint32, c_int32], doc) doc = """ PICO_STATUS (ps6000SetDataBufferBulk) ( int16_t handle, PS6000_CHANNEL channel, int16_t *buffer, uint32_t bufferLth, uint32_t waveform, PS6000_RATIO_MODE downSampleRatioMode ); """ ps6000.make_symbol("_SetDataBufferBulk", "ps6000SetDataBufferBulk", c_uint32, [c_int16, c_int32, c_void_p, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps6000SetDataBuffersBulk ( int16_t handle, PS6000_CHANNEL channel, int16_t *bufferMax, int16_t *bufferMin, uint32_t bufferLth, uint32_t waveform, PS6000_RATIO_MODE downSampleRatioMode ); """ ps6000.make_symbol("_SetDataBuffersBulk", "ps6000SetDataBuffersBulk", c_uint32, [c_int16, c_int32, c_void_p, c_void_p, c_uint32, c_uint32, c_int32], doc) doc = """ PICO_STATUS ps6000SetEtsTimeBuffer ( int16_t handle, int64_t *buffer, uint32_t bufferLth ); """ ps6000.make_symbol("_SetEtsTimeBuffer", "ps6000SetEtsTimeBuffer", c_uint32, [c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000SetEtsTimeBuffers ( int16_t handle, uint32_t *timeUpper, uint32_t *timeLower, uint32_t bufferLth ); """ ps6000.make_symbol("_SetEtsTimeBuffers", "ps6000SetEtsTimeBuffers", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000RunBlock ( int16_t handle, uint32_t noOfPreTriggerSamples, uint32_t noOfPostTriggerSamples, uint32_t timebase, int16_t oversample, int32_t *timeIndisposedMs, uint32_t segmentIndex, ps6000BlockReady lpReady, void *pParameter ); """ ps6000.make_symbol("_RunBlock", "ps6000RunBlock", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int16, c_void_p, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000IsReady ( int16_t handle, int16_t *ready ); """ ps6000.make_symbol("_IsReady", "ps6000IsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000RunStreaming ( int16_t handle, uint32_t *sampleInterval, PS6000_TIME_UNITS sampleIntervalTimeUnits, uint32_t maxPreTriggerSamples, uint32_t maxPostPreTriggerSamples, int16_t autoStop, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t overviewBufferSize ); """ ps6000.make_symbol("_RunStreaming", "ps6000RunStreaming", c_uint32, [c_int16, c_void_p, c_int32, c_uint32, c_uint32, c_int16, c_uint32, c_int32, c_uint32], doc) doc = """ void ps6000BlockReady ( int16_t handle, PICO_STATUS status, void *pParameter ); """ ps6000.BlockReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p) ps6000.BlockReadyType.__doc__ = doc doc = """ void ps6000DataReadyType ( int16_t handle, PICO_STATUS status, uint32_t noOfSamples, int16_t overflow, void *pParameter ); """ ps6000.DataReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_uint32, c_int16, c_void_p) ps6000.DataReadyType.__doc__ = doc doc = """ void ps6000StreamingReady ( int16_t handle, uint32_t noOfSamples, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, void *pParameter ); """ ps6000.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps6000.StreamingReadyType.__doc__ = doc doc = """ PICO_STATUS ps6000GetStreamingLatestValues ( int16_t handle, ps6000StreamingReady lpPs6000Ready, void *pParameter ); """ ps6000.make_symbol("_GetStreamingLatestValues", "ps6000GetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000NoOfStreamingValues ( int16_t handle, uint32_t *noOfValues ); """ ps6000.make_symbol("_NoOfStreamingValues", "ps6000NoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000GetMaxDownSampleRatio ( int16_t handle, uint32_t noOfUnaggreatedSamples, uint32_t *maxDownSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex ); """ ps6000.make_symbol("_GetMaxDownSampleRatio", "ps6000GetMaxDownSampleRatio", c_uint32, [c_int16, c_uint32, c_void_p, c_int32, c_uint32], doc) doc = """ PICO_STATUS ps6000GetValues ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps6000.make_symbol("_GetValues", "ps6000GetValues", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000GetValuesBulk ( int16_t handle, uint32_t *noOfSamples, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, int16_t *overflow ); """ ps6000.make_symbol("_GetValuesBulk", "ps6000GetValuesBulk", c_uint32, [c_int16, c_void_p, c_uint32, c_uint32, c_uint32, c_int32, c_void_p], doc) doc = """ PICO_STATUS ps6000GetValuesAsync ( int16_t handle, uint32_t startIndex, uint32_t noOfSamples, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, void *lpDataReady, void *pParameter ); """ ps6000.make_symbol("_GetValuesAsync", "ps6000GetValuesAsync", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000GetValuesOverlapped ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t segmentIndex, int16_t *overflow ); """ ps6000.make_symbol("_GetValuesOverlapped", "ps6000GetValuesOverlapped", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000GetValuesOverlappedBulk ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, int16_t *overflow ); """ ps6000.make_symbol("_GetValuesOverlappedBulk", "ps6000GetValuesOverlappedBulk", c_uint32, [c_int16, c_uint32, c_void_p, c_uint32, c_int32, c_uint32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000GetValuesBulkAsyc ( int16_t handle, uint32_t startIndex, uint32_t *noOfSamples, uint32_t downSampleRatio, PS6000_RATIO_MODE downSampleRatioMode, uint32_t fromSegmentIndex, uint32_t toSegmentIndex, int16_t *overflow ); """ ps6000.make_symbol("_GetValuesBulkAsyc", "ps6000GetValuesBulkAsyc", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_int32, c_uint32, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000GetNoOfCaptures ( int16_t handle, uint32_t *nCaptures ); """ ps6000.make_symbol("_GetNoOfCaptures", "ps6000GetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000GetNoOfProcessedCaptures ( int16_t handle, uint32_t *nProcessedCaptures ); """ ps6000.make_symbol("_GetNoOfProcessedCaptures", "ps6000GetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) """ PICO_STATUS ps6000Stop ( int16_t handle ); """ ps6000.make_symbol("_Stop", "ps6000Stop", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps6000SetNoOfCaptures ( int16_t handle, uint32_t nCaptures ); """ ps6000.make_symbol("_SetNoOfCaptures", "ps6000SetNoOfCaptures", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000SetWaveformLimiter ( int16_t handle, uint32_t nWaveformsPerSecond ); """ ps6000.make_symbol("_SetWaveformLimiter", "ps6000SetWaveformLimiter", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000EnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps6000.make_symbol("_EnumerateUnits", "ps6000EnumerateUnits", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000SetExternalClock ( int16_t handle, PS6000_EXTERNAL_FREQUENCY frequency, int16_t threshold ); """ ps6000.make_symbol("_SetExternalClock", "ps6000SetExternalClock", c_uint32, [c_int16, c_int32, c_int16], doc) doc = """ PICO_STATUS ps6000PingUnit ( int16_t handle ); """ ps6000.make_symbol("_PingUnit", "ps6000PingUnit", c_uint32, [c_int16, ], doc) doc = """ PICO_STATUS ps6000GetAnalogueOffset ( int16_t handle, PS6000_RANGE range, PS6000_COUPLING coupling, float *maximumVoltage, float *minimumVoltage ); """ ps6000.make_symbol("_GetAnalogueOffset", "ps6000GetAnalogueOffset", c_uint32, [c_int16, c_int32, c_int32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000GetTriggerInfoBulk ( int16_t handle, PS6000_TRIGGER_INFO *triggerInfo, uint32_t fromSegmentIndex, uint32_t toSegmentIndex ); """ ps6000.make_symbol("_GetTriggerInfoBulk", "ps6000GetTriggerInfoBulk", c_uint16, [c_int16, c_void_p, c_uint32, c_uint32], doc) ================================================ FILE: picosdk/ps6000a.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the ps6000aApi.h C header file for PicoScope 6000 A Series oscilloscopes using the ps6000a driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.constants import make_enum from picosdk.PicoDeviceEnums import picoEnum as enums class Ps6000alib(Library): def __init__(self): super(Ps6000alib, self).__init__("ps6000a") ps6000a = Ps6000alib() ps6000a.DEFAULT_RESOLUTION = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] doc = """ void ps6000aExternalReferenceInteractions ( int16_t handle, PICO_STATUS status, PICO_CLOCK_REFERENCE reference ); """ ps6000a.ExternalReferenceInteractionsReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_uint32) ps6000a.ExternalReferenceInteractionsReadyType.__doc__ = doc doc = """ void ps6000aBlockReady ( int16_t handle, PICO_STATUS status, PICO_POINTER pParameter ); """ ps6000a.BlockReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p) ps6000a.BlockReadyType.__doc__ = doc doc = """ void ps6000aStreamingReady ( int16_t handle, int64_t noOfSamples, uint64_t bufferIndex, uint32_t startIndex, int16_t overflow, uint32_t triggerAt, int16_t triggered, int16_t autoStop, PICO_POINTER pParameter ); """ ps6000a.StreamingReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_int64, c_uint64, c_uint32, c_int16, c_uint32, c_int16, c_int16, c_void_p) ps6000a.StreamingReadyType.__doc__ = doc doc = """ void ps6000aDataReady ( int16_t handle, PICO_STATUS status, uint64_t noOfSamples, int16_t overflow, PICO_POINTER pParameter ); """ ps6000a.DataReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_uint64, c_int16, c_void_p) ps6000a.DataReadyType.__doc__ = doc doc = """ void ps6000aProbeInteractions ( int16_t handle, PICO_STATUS status, PICO_USER_PROBE_INTERACTIONS *probes, uint32_t nProbes ); """ ps6000a.ProbeInteractionsType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p, c_uint32) ps6000a.ProbeInteractionsType.__doc__ = doc doc = """ void ps6000aDigitalPortInteractions ( int16_t handle, PICO_STATUS status, PICO_DIGITAL_PORT_INTERACTIONS *ports, uint32_t nPorts ); """ ps6000a.DigitalPortInteractionsType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p, c_uint32) ps6000a.DigitalPortInteractionsType.__doc__ = doc doc = """ PICO_STATUS ps6000aOpenUnit ( int16_t *handle, int8_t *serial PICO_DEVICE_RESOLUTION resolution ); """ ps6000a.make_symbol("_OpenUnit", "ps6000aOpenUnit", c_uint32, [c_void_p, c_char_p, c_int32], doc) doc = """ PICO_STATUS ps6000aOpenUnitAsync ( int16_t *handle, int8_t *serial, PICO_DEVICE_RESOLUTION resolution ); """ ps6000a.make_symbol("_OpenUnitAsync", "ps6000aOpenUnitAsync", c_uint32, [c_void_p, c_char_p, c_int32], doc) doc = """ PICO_STATUS ps6000aOpenUnitProgress ( int16_t *handle, int16_t *progressPercent, int16_t *complete ); """ ps6000a.make_symbol("_OpenUnitProgress", "ps6000aOpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ ps6000a.make_symbol("_GetUnitInfo", "ps6000aGetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000aCloseUnit ( int16_t handle ); """ ps6000a.make_symbol("_CloseUnit", "ps6000aCloseUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps6000aFlashLed ( int16_t handle, int16_t start ); """ ps6000a.make_symbol("_FlashLed", "ps6000aFlashLed", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps6000aMemorySegments ( int16_t handle, uint64_t nSegments, uint64_t *nMaxSegments ); """ ps6000a.make_symbol("_MemorySegments", "ps6000aMemorySegments", c_uint32, [c_int16, c_uint64, c_void_p], doc) doc = """ PICO_STATUS ps6000aMemorySegmentsBySamples ( int16_t handle, uint64_t nSamples, uint64_t *nMaxSegments ); """ ps6000a.make_symbol("_MemorySegmentsBySamples", "ps6000aMemorySegmentsBySamples", c_uint32, [c_int16, c_uint64, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetMaximumAvailableMemory ( int16_t handle, uint64_t *nMaxSamples, PICO_DEVICE_RESOLUTION resolution ); """ ps6000a.make_symbol("_GetMaximumAvailableMemory", "ps6000aGetMaximumAvailableMemory", c_uint32, [c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000aQueryMaxSegmentsBySamples ( int16_t handle, uint64_t nSamples, uint32_t nChannelsEnabled, uint64_t *nMaxSegments, PICO_DEVICE_RESOLUTION resolution ); """ ps6000a.make_symbol("_QueryMaxSegmentsBySamples", "ps6000aQueryMaxSegmentsBySamples", c_uint32, [c_int16, c_uint64, c_int32, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetChannelOn ( int16_t handle, PICO_CHANNEL channel, PICO_COUPLING coupling, PICO_CONNECT_PROBE_RANGE range, double analogueOffset, PICO_BANDWIDTH_LIMITER bandwidth ); """ ps6000a.make_symbol("_SetChannelOn", "ps6000aSetChannelOn", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32, c_double, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetChannelOff ( int16_t handle, PICO_CHANNEL channel ); """ ps6000a.make_symbol("_SetChannelOff", "ps6000aSetChannelOff", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetDigitalPortOn ( int16_t handle, PICO_CHANNEL port, int16_t *logicThresholdLevel, int16_t logicThresholdLevelLength PICO_DIGITAL_PORT_HYSTERESIS hysteresis ); """ ps6000a.make_symbol("_SetDigitalPortOn", "ps6000aSetDigitalPortOn", c_uint32, [c_int16, c_uint32, c_void_p, c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetDigitalPortOff ( int16_t handle, PICO_CHANNEL port ); """ ps6000a.make_symbol("_SetDigitalPortOff", "ps6000aSetDigitalPortOff", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aGetTimebase ( int16_t handle, uint32_t timebase, uint64_t noSamples, double *timeIntervalNanoseconds, uint64_t *maxSamples, uint64_t segmentIndex ); """ ps6000a.make_symbol("_GetTimebase", "ps6000aGetTimebase", c_uint32, [c_int16, c_uint32, c_uint64, c_void_p, c_void_p, c_uint64], doc) doc = """ PICO_STATUS ps6000aSigGenWaveform ( int16_t handle, PICO_WAVE_TYPE wavetype, int16_t *buffer, uint16 bufferLength ); """ ps6000a.make_symbol("_SigGenWaveform", "ps6000aSigGenWaveform", c_uint32, [c_int16, c_uint32, c_void_p, c_uint16], doc) doc = """ PICO_STATUS ps6000aSignGenRange ( int16_t handle, double peakToPeakVolts, double offsetVolts ); """ ps6000a.make_symbol("_SigGenRange", "ps6000aSigGenRange", c_uint32, [c_int16, c_double, c_double], doc) doc = """ PICO_STATUS ps6000aSigGenWaveformDutyCycle ( int16_t handle, double dutyCyclePercent ); """ ps6000a.make_symbol("_SigGenWaveformDutyCycle", "ps6000aSigGenWaveformDutyCycle", c_uint32, [c_int16, c_double], doc) doc = """ PICO_STATUS ps6000aSigGenTrigger ( int16_t handle, PICO_SIGGEN_TRIG_TYPE triggerType, PICO_SIGGEN_TRIG_SOURCE triggerSource, uint64_t cycles, uint64_t autoTriggerPicoSeconds ); """ ps6000a.make_symbol("_SigGenTrigger", "ps6000aSigGenTrigger", c_uint32, [c_int16, c_uint32, c_uint32, c_uint64, c_uint64], doc) doc = """ PICO_STATUS ps6000aSigGenFilter ( int16_t handle, PICO_SIGGEN_FILTER_STATE filterState ); """ ps6000a.make_symbol("_SigGenFilter", "ps6000aSigGenFilter", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSigGenFrequency ( int16_t handle, double frequencyHz ); """ ps6000a.make_symbol("_SigGenFrequency", "ps6000aSigGenFrequency", c_uint32, [c_int16, c_double], doc) doc = """ PICO_STATUS ps6000aSigGenFrequencySweep ( int16_t handle, double stopFrequencyHz, double frequencyIncrement, double dwellTimeSeconds, PICO_SWEEP_TYPE sweepType ); """ ps6000a.make_symbol("_SigGenFrequencySweep", "ps6000aSigGenFrequencySweep", c_uint32, [c_int16, c_double, c_double, c_double, c_uint32], doc) doc = """ PICO_STATUS ps6000aSigGenPhase ( int16_t handle, uint64_t deltaPhase ); """ ps6000a.make_symbol("_SigGenPhase", "ps6000aSigGenPhase", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS ps6000aSigGenPhaseSweep ( int16_t handle, uint64_t stopDeltaPhase, uint64_t deltaPhaseIncrement, uint64_t dwellCount, PICO_SWEEP_TYPE sweepType ); """ ps6000a.make_symbol("_SigGenPhaseSweep", "ps6000aSigGenPhaseSweep", c_uint32, [c_int16, c_uint64, c_uint64, c_uint64, c_uint32], doc) doc = """ PICO_STATUS ps6000aSigGenClockManual ( int16_t handle, double dacClockFrequency, uint64_t prescaleRatio ); """ ps6000a.make_symbol("_SigGenClockManual", "ps6000aSigGenClockManual", c_uint32, [c_int16, c_double, c_uint64], doc) doc = """ PICO_STATUS ps6000aSigGenSoftwareTriggerControl ( int16_t handle, PICO_SIGGEN_TRIG_TYPE triggerState ); """ ps6000a.make_symbol("_SigGenSoftwareTriggerControl", "ps6000aSigGenSoftwareTriggerControl", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSigGenApply ( int16_t handle, int16_t sigGenEnabled, int16_t sweepEnabled, int16_t triggerEnabled, int16_t automaticClockOptimisationEnabled, int16_t overrideAutomaticClockAndPrescale, double *frequency, double *stopFrequency, double *frequencyIncrement, double *dwellTime ); """ ps6000a.make_symbol("_SigGenApply", "ps6000aSigGenApply", c_uint32, [c_int16, c_int16, c_int16, c_int16, c_int16, c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aSigGenLimits ( int16_t handle, PICO_SIGGEN_PARAMETER parameter, double *minimumPermissibleValue, double *maximumPermissibleValue, double *step ); """ ps6000a.make_symbol("_SigGenLimits", "ps6000aSigGenLimits", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aSigGenFrequencyLimits ( int16_t handle, PICO_WAVE_TYPE waveType, uint64_t *numSamples, double *startFrequency, int16_t sweepEnabled, double *manualDacClockFrequency, uint64_t *manualPrescaleRatio, double *maxStopFrequencyOut, double *minFrequencyStepOut, double *maxFrequencyStepOut, double *minDwellTimeOut, double *maxDwellTimeOut ); """ ps6000a.make_symbol("_SigGenFrequencyLimits", "ps6000aSigGenFrequencyLimits", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aSigGenPause ( int16_t handle ); """ ps6000a.make_symbol("_SigGenPause", "ps6000aSigGenPause", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps6000aSigGenRestart ( int16_t handle ); """ ps6000a.make_symbol("_SigGenRestart", "ps6000aSigGenRestart", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps6000aSetSimpleTrigger ( int16_t handle int16_t enable, PICO_CHANNEL source, int16_t threshold, PICO_THRESHOLD_DIRECTION direction, uint64_t delay, uint32_t autoTriggerMicroSeconds ); """ ps6000a.make_symbol("_SetSimpleTrigger", "ps6000aSetSimpleTrigger", c_uint32, [c_int16, c_int16, c_uint32, c_int16, c_uint32, c_uint64, c_uint32], doc) doc = """ PICO_STATUS ps6000aTriggerWithinPreTriggerSamples ( int16_t handle, PICO_TRIGGER_WITHIN_PRE_TRIGGER state ); """ ps6000a.make_symbol("_TriggerWithinPreTriggerSamples", "ps6000aTriggerWithinPreTriggerSamples", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetTriggerChannelProperties ( int16_t handle, PICO_TRIGGER_CHANNEL_PROPERTIES *channelProperties, int16_t nChannelProperties, int16_t auxOutputEnable, uint32_t autoTriggerMicroSeconds ); """ ps6000a.make_symbol("_SetTriggerChannelProperties", "ps6000aSetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetTriggerChannelConditions ( int16_t handle, PICO_CONDITION *conditions, int16_t nConditions, PICO_ACTION action ); """ ps6000a.make_symbol("_SetTriggerChannelConditions", "ps6000aSetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetTriggerChannelDirections ( int16_t handle, PICO_DIRECTION *directions, int16_t nDirections ); """ ps6000a.make_symbol("_SetTriggerChannelDirections", "ps6000aSetTriggerChannelDirections", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps6000aSetTriggerDelay ( int16_t handle, uint64_t delay ); """ ps6000a.make_symbol("_SetTriggerDelay", "ps6000aSetTriggerDelay", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS ps6000aSetPulseWidthQualifierProperties ( int16_t handle, uint32_t lower, uint32_t upper, PICO_PULSE_WIDTH_TYPE type ); """ ps6000a.make_symbol("_SetPulseWidthQualifierProperties", "ps6000aSetPulseWidthQualifierProperties", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetPulseWidthQualifierConditions ( int16_t handle, PICO_CONDITION *conditions, int16_t nConditions, PICO_ACTION action ); """ ps6000a.make_symbol("_SetPulseWidthQualifierConditions", "ps6000aSetPulseWidthQualifierConditions", c_uint32, [c_int16, c_void_p, c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetPulseWidthQualifierDirections ( int16_t handle, PICO_DIRECTION *directions, int16_t nDirections ); """ ps6000a.make_symbol("_SetPulseWidthQualifierDirections", "ps6000aSetPulseWidthQualifierDirections", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps6000aSetTriggerDigitalPortProperties ( int16_t handle, PICO_CHANNEL port, PICO_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps6000a.make_symbol("_SetTriggerDigitalPortProperties", "ps6000aSetTriggerDigitalPortProperties", c_uint32, [c_int16, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps6000aSetPulseWidthDigitalPortProperties ( int16_t handle, PICO_CHANNEL port, PICO_DIGITAL_CHANNEL_DIRECTIONS *directions, int16_t nDirections ); """ ps6000a.make_symbol("_SetPulseWidthDigitalPortProperties", "ps6000aSetPulseWidthDigitalPortProperties", c_uint32, [c_int16, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps6000aGetTriggerTimeOffset ( int16_t handle, int64_t *time, PICO_TIME_UNITS *timeUnits, uint64_t segmentIndex ); """ ps6000a.make_symbol("_GetTriggerTimeOffset", "ps6000aGetTriggerTimeOffset", c_uint32, [c_int16, c_void_p, c_void_p, c_uint64], doc) doc = """ PICO_STATUS ps6000aGetValuesTriggerTimeOffsetBulk ( int16_t handle, int64_t *time, PICO_TIME_UNITS *timeUnits, uint64_t fromSegementIndex, uint64_t toSegmentIndex ); """ ps6000a.make_symbol("_GetValuesTriggerTimeOffsetBulk", "ps6000aGetValuesTriggerTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_uint64, c_uint64], doc) doc = """ PICO_STATUS ps6000aSetDataBuffer ( int16_t handle, PICO_CHANNEL channel, PICO_POINTER buffer, int32_t nSamples, PICO_DATA_TYPE dataType, uint64_t waveform, PICO_RATIO_MODE downSampleRatioMode, PICO_ACTION action ); """ ps6000a.make_symbol("_SetDataBuffer", "ps6000aSetDataBuffer", c_uint32, [c_int16, c_uint32, c_void_p, c_int32, c_uint32, c_uint64, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetDataBuffers ( int16_t handle, PICO_CHANNEL channel, PICO_POINTER bufferMax, PICO_POINTER bufferMin, int32_t nSamples, PICO_DATA_TYPE dataType, uint64_t waveform, PICO_RATIO_MODE downSampleRatioMode, PICO_ACTION action ); """ ps6000a.make_symbol("_SetDataBuffers", "ps6000aSetDataBuffers", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_int32, c_uint32, c_uint64, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps6000aRunBlock ( int16_t handle, uint64_t noOfPreTriggerSamples, uint64_t noOfPostTriggerSamples, uint32_t timebase, double *timeIndisposedMs, uint64_t segmentIndex, ps6000aBlockReady lpReady, PICO_POINTER pParameter ); """ ps6000a.make_symbol("_RunBlock", "ps6000aRunBlock", c_uint32, [c_int16, c_uint64, c_uint64, c_uint32, c_void_p, c_uint64, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aIsReady ( int16_t handle, int16_t *ready ); """ ps6000a.make_symbol("_IsReady", "ps6000aIsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aRunStreaming ( int16_t handle, double *sampleInterval, PICO_TIME_UNITS sampleIntervalTimeUnits, uint64_t maxPreTriggerSamples, uint64_t maxPostTriggerSamples, int16_t autoStop, uint64_t downSampleRatio, PICO_RATIO_MODE downSampelRatioMode ): """ ps6000a.make_symbol("_RunStreaming", "ps6000aRunStreaming", c_uint32, [c_int16, c_void_p, c_uint32, c_uint64, c_uint64, c_int16, c_uint64, c_uint32], doc) doc = """ PICO_STATUS ps6000aGetStreamingLatestValues ( int16_t handle, PICO_STREAMING_DATA_INFO *streamingDataInfo, uint64_t nStreamingDataInfos, PICO_STREAMING_DATA_TRIGGER_INFO *triggerInfo ); """ ps6000a.make_symbol("_GetStreamingLatestValues", "ps6000aGetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_uint64, c_void_p], doc) doc = """ PICO_STATUS ps6000aNoOfStreamingValues ( int16_t handle, uint64_t *noOfValues ); """ ps6000a.make_symbol("_NoOfStreamingValues", "ps6000aNoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetValues ( int16_t handle, uint64_t startIndex, uint64_t *noOfSamples, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, uint64_t segmentIndex, int16_t *overflow ); """ ps6000a.make_symbol("_GetValues", "ps6000aGetValues", c_uint32, [c_int16, c_uint64, c_void_p, c_uint64, c_uint32, c_uint64, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetValuesBulk ( int16_t handle, uint64_t startIndex, uint64_t *noOfSamples, uint64_t fromSegmentIndex, uint64_t toSegmentIndex, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, int16_t *overflow ); """ ps6000a.make_symbol("_GetValuesBulk", "ps6000aGetValuesBulk", c_uint32, [c_int16, c_uint64, c_void_p, c_uint64, c_uint64, c_uint64, c_uint32, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetTriggerInfo ( int16_t handle, PICO_TRIGGER_INFO *startIndex, uint64_t firstSegmentIndex, uint64_t segmentCount, ); """ ps6000a.make_symbol("_GetTriggerInfo", "ps6000aGetTriggerInfo", c_uint32, [c_int16, c_void_p, c_uint64, c_uint64], doc) doc = """ PICO_STATUS ps6000aGetValuesAsync ( int16_t handle, uint64_t startIndex, uint64_t noOfSamples, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, uint64_t segmentIndex, PICO_POINTER lpDataReady, PICO_POINTER pParameter ); """ ps6000a.make_symbol("_GetValuesAsync", "ps6000aGetValuesAsync", c_uint32, [c_int16, c_uint64, c_uint64, c_uint64, c_uint32, c_uint64, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetValuesBulkAsync ( int16_t handle, uint64_t startIndex, uint64_t noOfSamples, uint64_t fromSegmentIndex, uint64_t toSegmentIndex, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, PICO_POINTER lpDataReady, PICO_POINTER pParameter ); """ ps6000a.make_symbol("_GetValuesBulkAsync", "ps6000aGetValuesBulkAsync", c_uint32, [c_int16, c_uint64, c_uint64, c_uint64, c_uint64, c_uint64, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetValuesOverlapped ( int16_t handle, uint64_t startIndex, uint64_t *noOfSamples, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, uint64_t fromSegementIndex, uint64_t toSegmentIndex, int16_t *overflow ); """ ps6000a.make_symbol("_GetValuesOverlapped", "ps6000aGetValuesOverlapped", c_uint32, [c_int16, c_uint64, c_void_p, c_uint64, c_uint32, c_uint64, c_uint64, c_void_p], doc) doc = """ PICO_STATUS ps6000aStopUsingGetValuesOverlapped ( int16_t handle ); """ ps6000a.make_symbol("_StopUsingGetValuesOverlapped", "ps6000aStopUsingGetValuesOverlapped", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps6000aGetNoOfCaptures ( int16_t handle, uint64_t *nCaptures ); """ ps6000a.make_symbol("_GetNoOfCaptures", "ps6000aGetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetNoOfProcessedCaptures ( int16_t handle, uint64_t *nProcessedCaptures ); """ ps6000a.make_symbol("_GetNoOfProcessedCaptures", "ps6000aGetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aStop ( int16_t handle, ); """ ps6000a.make_symbol("_Stop", "ps6000aStop", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps6000aSetNoOfCaptures ( int16_t handle, uint64_t nCaptures ); """ ps6000a.make_symbol("_SetNoOfCaptures", "ps6000aSetNoOfCaptures", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS ps6000aGetTriggerInfo ( int16_t handle, PICO_TRIGGER_INFO *triggerInfo, uint64_t firstSegmentIndex, uint64_t segmentCount ); """ ps6000a.make_symbol("_getTriggerInfo", "ps6000aGetTriggerInfo", c_uint32, [c_int16, c_void_p, c_uint64, c_uint64], doc) doc = """ PICO_STATUS ps6000aEnumerateUnits ( int16_t *count, int8_t *serials, int16_t *serialLth ); """ ps6000a.make_symbol("_EnumerateUnits", "ps6000aEnumerateUnits", c_uint32, [c_void_p, c_char_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aPingUnit ( int16_t handle ); """ ps6000a.make_symbol("_PingUnit", "ps6000aPingUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS ps6000aGetAnalogueOffsetLimits ( int16_t handle, PICO_CONNECT_PROBE_RANGE range, PICO_COUPLING coupling, double *maximumVoltage, double *minimumVoltage ); """ ps6000a.make_symbol("_GetAnalogueOffsetLimits", "ps6000aGetAnalogueOffsetLimits", c_uint32, [c_int16, c_uint32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aGetMinimumTimebaseStateless ( int16_t handle, PICO_CHANNEL_FLAGS enabledChannelFlags, uint32_t *timebase, double *timeInterval, PICO_DEVICE_RESOLUTION resolution ); """ ps6000a.make_symbol("_GetMinimumTimebaseStateless", "ps6000aGetMinimumTimebaseStateless", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS ps6000aNearestSampleIntervalStateless ( int16_t handle, PICO_CHANNEL_FLAGS enabledChannelFlags, double timeIntervalRequested, PICO_DEVICE_RESOLUTION resolution, uint32_t *timebase, double *timeIntervalAvailable ); """ ps6000a.make_symbol("_NearestSampleIntervalStateless", "ps6000aNearestSampleIntervalStateless", c_uint32, [c_int16, c_uint32, c_double, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aChannelCombinationsStateless ( int16_t handle, PICO_CHANNEL_FLAGS *channelFlagsCombinations, uint32_t *nChannelCombinations, PICO_DEVICE_RESOLUTION resolution, uint32_t timebase ); """ ps6000a.make_symbol("_ChannelCombinationsStateless", "ps6000aChannelCombinationsStateless", c_uint32, [c_int16, c_void_p, c_void_p, c_uint32, c_uint32], doc) doc = """ PICO_STATUS ps6000aSetDeviceResolution ( int16_t handle, PICO_DEVICE_RESOLUTION resolution ); """ ps6000a.make_symbol("_SetDeviceResolution", "ps6000aSetDeviceResolution", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS ps6000aGetDeviceResolution ( int16_t handle, PICO_DEVICE_RESOLUTION *resolution ); """ ps6000a.make_symbol("_GetDeviceResolution", "ps6000aGetDeviceResolution", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aQueryOutputEdgeDetect ( int16_t handle, int16_t *state ); """ ps6000a.make_symbol("_QueryOutputEdgeDetect", "ps6000aQueryOutputEdgeDetect", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aSetOutputEdgeDetect ( int16_t handle, int16_t state ); """ ps6000a.make_symbol("_SetOutputEdgeDetect", "ps6000aSetOutputEdgeDetect", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS ps6000aGetScalingValues ( int16_t handle, PICO_SCALING_FACTORS_VALUES *scalingValues, int16_t nChannels ); """ ps6000a.make_symbol("_GetScalingValues", "ps6000aGetScalingValues", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS ps6000aGetAdcLimits ( int16_t handle, PICO_DEVICE_RESOLUTION resolution, int16_t *minValue, int16_t *maxValue ); """ ps6000a.make_symbol("_GetAdcLimits", "ps6000aGetAdcLimits", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aCheckForUpdate ( int16_t handle, PICO_VERSION *current, PICO_VERSION *update, uint16_t *updateRequired ); """ ps6000a.make_symbol("_CheckForUpdate", "ps6000aCheckForUpdate", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS ps6000aStartFirmwareUpdate ( int16_t handle, PicoUpdateFirmwareProgress progress ); """ ps6000a.make_symbol("_StartFirmwareUpdate", "ps6000aStartFirmwareUpdate", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aSetProbeInteractionCallback ( int16_t handle, PicoProbeInteractions callback ); """ ps6000a.make_symbol("_SetProbeInteractionCallback", "ps6000aSetProbeInteractionCallback", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aSetExternalReferenceInteractionCallback ( int16_t handle, PicoExternalReferenceInteractions callback ); """ ps6000a.make_symbol("_SetExternalReferenceInteractionCallback", "ps6000aSetExternalReferenceInteractionCallback", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aSetAWGOverrangeInteractionCallback ( int16_t handle, PicoAWGOverrangeInteractions callback ); """ ps6000a.make_symbol("_SetAWGOVerrangeInteractionCallback", "ps6000aSetAWGOverrangeInteractionCallback", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aSetTemperatureSensorInteractioNCallback ( int16_t handle, PicoTemperatureSensorInteractions callback ); """ ps6000a.make_symbol("_SetTemperatureSensroInteractionCallback", "ps6000aSetTemperatureSensorInteractionCallback", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS ps6000aSetAuxIoMode ( int16_t handle, PICO_AUXIO_MODE auxIoMode ); """ ps6000a.make_symbol("_SetAuxIoMode", "ps6000aSetAuxIoMode", c_uint32, [c_int16, c_uint32], doc) ================================================ FILE: picosdk/psospa.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the psospaApi.h C header file for PicoScope 3000 A Series oscilloscopes using the psospa driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.constants import make_enum from picosdk.PicoDeviceEnums import picoEnum as enums class Psospalib(Library): def __init__(self): super(Psospalib, self).__init__("psospa") psospa = Psospalib() doc = """ void psospaBlockReady ( int16_t handle, PICO_STATUS status, PICO_POINTER pParameter ); """ psospa.BlockReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_void_p) psospa.BlockReadyType.__doc__ = doc doc = """ void psospaDataReady ( int16_t handle, PICO_STATUS status, uint64_t noOfSamples, int16_t overflow, PICO_POINTER pParameter ); """ psospa.DataReadyType = C_CALLBACK_FUNCTION_FACTORY(None, c_int16, c_uint32, c_uint64, c_int16, c_void_p) psospa.DataReadyType.__doc__ = doc doc = """ PICO_STATUS psospaOpenUnit ( int16_t* handle, int8_t* serial, PICO_DEVICE_RESOLUTION resolution, PICO_USB_POWER_DETAILS* powerDetails ); """ psospa.make_symbol("_OpenUnit","psospaOpenUnit", c_uint32, [c_void_p, c_char_p, c_int32, c_void_p], doc) doc = """ PICO_STATUS psospaCloseUnit ( int16_t handle ); """ psospa.make_symbol("_CloseUnit", "psospaCloseUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS psospaGetUnitInfo ( int16_t handle, int8_t* string, int16_t stringLength, int16_t* requiredSize, PICO_INFO info ); """ psospa.make_symbol("_GetUnitInfo","psospaGetUnitInfo", c_uint32, [c_int16, c_char_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS psospaGetVariantDetails ( const int8_t* variantName, int16_t variantNameLength, int8_t* outputString, int32_t* outputStringLength, PICO_TEXT_FORMAT textFormat ); """ psospa.make_symbol("_GetVariantDetails", "psospaGetVariantDetails", c_uint32, [c_char_p, c_int16, c_char_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS psospaMemorySegments ( int16_t handle, uint64_t nSegments, uint64_t* nMaxSamples ); """ psospa.make_symbol("_MemorySegments","psospaMemorySegments", c_uint32,[c_int16, c_uint64, c_void_p], doc) doc = """ PICO_STATUS psospaMemorySegmentsBySamples ( int16_t handle, uint64_t nSamples, uint64_t* nMaxSegments ); """ psospa.make_symbol("_MemorySegmentsBySamples","psospaMemorySegmentsBySamples", c_uint32, [c_int16, c_uint64, c_void_p], doc) # doc = """ PICO_STATUS psospaGetMaximumAvaliableMemory # ( # int16_t handle, # uint64_t* nMaxSamples, # PICO_DEVICE_RESOLUTION resolution # ); """ # psospa.make_symbol("_GetMaximumAvaliableMemory","psospaGetMaximumAvaliableMemory", c_uint32, [c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS psospaQueryMaxSegmentsBySamples ( int16_t handle, uint64_t nSamples, uint32_t nChannelEnabled, uint64_t* nMaxSegments, PICO_DEVICE_RESOLUTION resolution ); """ psospa.make_symbol("_QUeryMaxSegmentsBySamples","psospaQueryMaxSegmentsBySamples", c_uint32, [c_int16, c_uint64, c_uint32, c_void_p, c_uint32], doc) doc = """ PICO_STATUS psospaSetChannelOn ( int16_t handle, PICO_CHANNEL channel, PICO_COUPLING coupling, int64_t rangeMin, int64_t rangeMax PICO_PROBE_RANGE_INFO rangeType, double analogueOffset, PICO_BANDWIDTH_LIMITER bandwidth ); """ psospa.make_symbol("_SetChannelOn","psospaSetChannelOn", c_uint32, [c_int16, c_uint32, c_uint32, c_int64, c_int64, c_uint32, c_double, c_uint32], doc) doc = """ PICO_STATUS psospaSetChannelOff ( int16_t handle, PICO_CHANNEL channel ); """ psospa.make_symbol("_SetChannelOff","psospaSetChannelOff", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaSetDigitalPortOn ( int16_t handle, PICO_CHANNEL port, int16_t* logicThresholdLevel, int16_t* logicThresholdLengthLevel, PICO_DIGITAL_PORT_HYSTERESIS hysteresis ); """ psospa.make_symbol("_SetDigitalPortOn","psospaSetDigitalPortOn", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS psospaSetDigitalPortOff ( int16_t handle, PICO_CHANNEL port ); """ psospa.make_symbol("_SetDigitalPortOff","psospaSetDigitalPortOff", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaGetTimebase ( int16_t handle, uint32_t timebase, uint64_t noSamples, double* timeIntervalNanoseconds, uint64_t* maxSamples, uint64_t segmentIndex ); """ psospa.make_symbol("_GetTimebase","psospaGetTimebase", c_uint32, [c_int16, c_uint32, c_uint64, c_void_p, c_void_p, c_uint64], doc) doc = """ PICO_STATUS psospaSigGenWaveform ( int16_t handle, PICO_WAVE_TYPE waveType, int16_t* buffer, uint64_t bufferLength ); """ psospa.make_symbol("_SigGenWaveform","psospaSigGenWaveform", c_uint32, [c_int16, c_uint32, c_void_p, c_uint64], doc) doc = """ PICO_STATUS psospaSigGenRange ( int16_t handle, double peakToPeakVolts, double offsetVolts ); """ psospa.make_symbol("_SigGenRange","psospaSigGenRange", c_uint32, [c_int16, c_double, c_double], doc) doc = """ PICO_STATUS psospaSigGenWaveformDutyCycle ( int16_t handle, double dutyCyclePercent ); """ psospa.make_symbol("_SigGenWaveformDutyCycle","psospaSigGenWaveformDutyCycle", c_uint32, [c_int16, c_double], doc) doc = """ PICO_STATUS psospaSigGenTrigger ( int16_t handle, PICO_SIGGEN_TRIG_TYPE triggerType, PICO_SIGGEN_TRIG_SOURCE triggerSource, uint64_t cycles, uint64_t autoTriggerPicoSeconds ); """ psospa.make_symbol("_SigGenTrigger","psospaSigGenTrigger", c_uint32, [c_int16, c_uint32, c_uint32, c_uint64, c_uint64], doc) doc = """ PICO_STATUS psospaSigGenFrequency ( int16_t handle, double frequencyHz ); """ psospa.make_symbol("_SigGenFrequency","psospaSigGenFrequency", c_uint32, [c_int16, c_double], doc) doc = """ PICO_STATUS psospaSigGenFrequencySweep ( int16_t handle, double stopFrequencyHz, double frequencyIncrement, double dwellTimeSeconds, PICO_SWEEP_TYPE sweepType ); """ psospa.make_symbol("_SigGenFrequencySweep","psospaSigGenFrequencySweep", c_uint32, [c_int16, c_double, c_double, c_double, c_uint32], doc) doc = """ PICO_STATUS psospaSigGenPhase ( int16_t handle, uint64_t deltaPhase ); """ psospa.make_symbol("_SigGenPhase","psospaSigGenPhase", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS psospaSigGenPhaseSweep ( int16_t handle, uint64_t stopDeltaPhase, uint64_t deltaPhaseIncrement, uint64_t dwellCount, PICO_SWEEP_TYPE sweepType ); """ psospa.make_symbol("_SigGenPhaseSweep","psospaSigGenPhaseSweep", c_uint32, [c_int16, c_uint64, c_uint64, c_uint64, c_uint32], doc) doc = """ PICO_STATUS psospaSigGenSoftwareTriggerControl ( int16_t handle, PICO_SIGGEN_TRIG_TYPE triggerState ); """ psospa.make_symbol("_SigGenSoftwareTriggerControl","psospaSigGenSoftwareTriggerControl", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaSigGenApply ( int16_t handle, int16_t sigGenEnabled, int16_t sweepEnabled, int16_t triggerEnabled, double* frequency double* stopFrequency, double* frequencyIncrement, double* dwellTime, ); """ psospa.make_symbol("_SigGenApply","psospaSigGenApply", c_uint32, [c_int16, c_int16, c_int16, c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaSigGenLimits ( int16_t handle, PICO_SIGGEN_PARAMETER parameter, double* minimumPermissibleValue, double* maximumPermissibleValue, double* step ); """ psospa.make_symbol("_SigGenLimits","psospaSigGenLimits", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaSigGenFrequencyLimits ( int16_t handle, PICO_WAVE_TYPE waveType, uint64_t* numSamples, double* minFrequencyOut, double* maxFrequencyOut, double* minFrequencyStepOut, double* maxFrequencyStepOut, double* mindDwellTimeOut, double* maxDwellTimeOut ); """ psospa.make_symbol("_SigGenFrequencyLimits","psospaSigGenFrequencyLimits", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaSigGenPause ( int16_t handle, ); """ psospa.make_symbol("_SigGenPause","psospaSigGenPause", c_uint32, [c_int16], doc) doc = """ PICO_STATUS psospaSigGenRestart ( int16_t handle ); """ psospa.make_symbol("_SigGenRestart","psospaSigGenRestart", c_uint32, [c_int16], doc) doc = """ PICO_STATUS psospaSetSimpleTrigger ( int16_t handle, int16_t enable, PICO_CHANNEL source, int16_t threshold, PICO_THRESHOLD_DIRECTION direction, uint64_t delay, uint32_t autoTriggerMicroSeconds ); """ psospa.make_symbol("_SetSimpleTrigger","psospaSetSimpleTrigger", c_uint32, [c_int16, c_int16, c_uint32, c_int16, c_uint32, c_uint64, c_uint32], doc) doc = """ PICO_STATUS psospaTriggerWithinPreTriggerSamples ( int16_t handle, PICO_TRIGGER_WITHIN_PRE_TRIGGER state ); """ psospa.make_symbol("_TriggerWithinPreTriggerSamples","psospaTriggerWithinPreTriggerSamples", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaSetTriggerChannelProperties ( int16_t handle, PICO_TRIGGER_CHANNEL_PROPERTIES* channelProperties, int16_t nChannelProperties, uint32_t autoTriggerMicroSeconds ); """ psospa.make_symbol("_SetTriggerChannelProperties","psospaSetTriggerChannelProperties", c_uint32, [c_int16, c_void_p, c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaSetTriggerChannelConditions ( int16_t handle, PICO_CONDITION* conditions, int16_t nConditions, PICO_ACTION action ); """ psospa.make_symbol("_SetTriggerChannelConditions","psospaSetTriggerChannelConditions", c_uint32, [c_int16, c_void_p, c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaSetTriggerChannelDirections ( int16_t handle, PICO_DIRECTION* directions, int16_t nDirections ); """ psospa.make_symbol("_SetTriggerChannelDirections","psospaSetTriggerChannelDirections", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS psospaSetTriggerDelay ( int16_t handle, uint64_t delay ); """ psospa.make_symbol("_SetTriggerDelay","psospaSetTriggerDelay", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS psospaSetTriggerHoldoffCounterBySamples ( int16_t handle, uint64_t holdoffSamples ); """ psospa.make_symbol("_SetTriggerHoldoffCounterBySamples","psospaSetTriggerHoldoffCounterBySamples", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS psospaSetPulseWidthQualifierProperties ( int16_t handle, uint32_t lower, uint32_t upper, PICO_PULSE_WIDTH_TYPE type ); """ psospa.make_symbol("_SetPulseWidthQualifierProperties","psospaSetPulseWidthQualifierProperties", c_uint32, [c_int16, c_uint32, c_uint32, c_uint32], doc) doc = """ PICO_STATUS psospaSetPulseWidthQualifierConditions ( int16_t handle, PICO_CONDITION* conditions, int16_t nConditions, PICO_ACTION action ); """ psospa.make_symbol("_SetPulseWidthQualifierConditions","psospaSetPulseWidthQualifierConditions", c_uint32, [c_int16, c_void_p, c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaSetPulseWidthQualifierDirections ( int16_t handle, PICO_DIRECTION* directions, int16_t nDirections ); """ psospa.make_symbol("_SetPulseWidthQualifierDirections","psospaSetPulseWidthQualifierDirections", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS psospaSetTriggerDigitalPortProperties ( int16_t handle, PICO_CHANNEL port, PICO_DIGITAL_CHANNEL_DIRECTIONS* directions, int16_t nDirections ); """ psospa.make_symbol("_SetTriggerDigitalPortProperties","psospaSetTriggerDigitalPortProperties", c_uint32, [c_int16, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS psospaGetTriggerTimeOffset ( int16_t handle, int64_t* time, PICO_TIME_UNITS* timeUnits, uint64_t segmentIndex ); """ psospa.make_symbol("_GetTriggerTimeOffset","psospaGetTriggerTimeOffset", c_uint32, [c_int16, c_void_p, c_void_p, c_uint64], doc) doc = """ PICO_STATUS psospaGetValuesTriggerTimeOffsetBulk ( int16_t handle, int64_t* times, PICO_TIME_UNITS* timeUnits, uint64_t fromSegmentIndex, uint64_t toSegmentIndex ); """ psospa.make_symbol("_GetValuesTriggerTimeOffsetBulk","psospaGetValuesTriggerTimeOffsetBulk", c_uint32, [c_int16, c_void_p, c_void_p, c_uint64, c_uint64], doc) doc = """ PICO_STATUS psospaSetDataBuffer ( int16_t handle, PICO_CHANNEL channel, PICO_POINTER buffer, int64_t nSamples, PICO_DATA_TYPE dataType, uint64_t waveform, PICO_RATIO_MODE downSampleRationMode, PICO_ACTION action ); """ psospa.make_symbol("_SetDataBuffer","psospaSetDataBuffer", c_uint32, [c_int16, c_uint32, c_void_p, c_uint64, c_uint32, c_uint64, c_uint32, c_uint32], doc) doc = """ PICO_STATUS psospaSetDataBuffers ( int16_t handle, PICO_CHANNEL channel, PICO_POINTER bufferMax, PICO_POINTER bufferMin, int64_t nSamples, PICO_DATA_TYPE dataType, uint64_t waveform, PICO_RATIO_MODE downSampleRatioMode, PICO_ACTION action ); """ psospa.make_symbol("_SetDataBuffers","psospaSetDataBuffers", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_int64, c_uint32, c_uint64, c_uint32, c_uint32], doc) doc = """ PICO_STATUS psospaRunBlock ( int16_t handle, uint64_t noOfPreTriggerSamples, uint64_t noOfPostTriggerSamples, uint32_t timebase, double* timeIndisposedMs, uint64_t segmentIndex, psospaBlockReady lpReady, PICO_POINTER pParameter ); """ psospa.make_symbol("_RunBlock","psospaRunBlock", c_uint32, [c_int16, c_uint64, c_uint64, c_uint32, c_void_p, c_uint64, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaIsReady ( int16_t handle, int16_t* ready ); """ psospa.make_symbol("_IsReady","psospaIsReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS psospaRunStreaming ( int16_t handle, double* sampleInterval, PICO_TIME_UNITS sampleIntervalTimeUnits, uint64_t maxPreTriggerSamples, uint64_t maxPostPreTriggerSamples, int16_t autoStop, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode ); """ psospa.make_symbol("_RunStreaming","psospaRunStreaming", c_uint32, [c_int16, c_void_p, c_uint32, c_uint64, c_uint64, c_int16, c_uint64, c_uint32], doc) doc = """ PICO_STATUS psospaGetStreamingLatestValues ( int16_t handle, PICO_STREAMING_DATA_INFO* streamingDataInfo, uint64_t nStreamingDataInfos, PICO_STREAMING_DATA_TRIGGER_INFO* triggerInfo ); """ psospa.make_symbol("_GetStreamingLatestValues","psospaGetStreamingLatestValues", c_uint32, [c_int16, c_void_p, c_uint64, c_void_p], doc) doc = """ PICO_STATUS psospaNoOfStreamingValues ( int16_t handle, uint64_t* noOfValues ); """ psospa.make_symbol("_NoOfStreamingValues","psospaNoOfStreamingValues", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS psospaGetValues ( int16_t handle, uint64_t startIndex, uint64_t* noOfSamples, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, uint64_t segmentIndex, int16_t* overflow ); """ psospa.make_symbol("_GetValues","psospaGetValues", c_uint32, [c_int16, c_uint64, c_void_p, c_uint64, c_uint32, c_uint64, c_void_p], doc) doc = """ PICO_STATUS psospaGetValuesBulk ( int16_t handle, uint64_t startIndex, uint64_t* noOfSamples, uint64_t fromSegmentIndex, uint64_t toSegmentIndex, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, int16_t* overflow ); """ psospa.make_symbol("_GetValuesBulk","psospaGetValuesBulk", c_uint32, [c_int16, c_uint64, c_void_p, c_uint64, c_uint64, c_uint64, c_uint32, c_void_p], doc) doc = """ PICO_STATUS psospaGetValuesAsync ( int16_t handle, uint64_t startIndex, uint64_t noOfSamples, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, uint64_t segmentIndex, PICO_POINTER lpDataReady, PICO_POINTER pParameter ); """ psospa.make_symbol("_GetValuesAsync","psospaGetValuesAsync", c_uint32, [c_int16, c_uint64, c_uint64, c_uint64, c_uint32, c_uint64, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaGetValuesBulkAsync ( int16_t handle, uint64_t startIndex, uint64_t noOfSamples, uint64_t fromSegmentIndex, uint64_t toSegmentIndex, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, PICO_POINTER lpDataReady, PICO_POINTER pParameter ); """ psospa.make_symbol("_GetValuesBulkAsync","psospaGetValuesBulkAsync", c_uint32, [c_int16, c_uint64, c_uint64, c_uint64, c_uint64, c_uint64, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaGetValuesOverlapped ( int16_t handle, uint64_t startIndex, uint64_t* noOfSamples, uint64_t downSampleRatio, PICO_RATIO_MODE downSampleRatioMode, uint64_t fromSegmentIndex, uint64_t toSegmentIndex, int16_t* overflow ); """ psospa.make_symbol("_GetValuesOverlapped","psospaGetValuesOverlapped", c_uint32, [c_int16, c_uint64, c_void_p, c_uint64, c_uint32, c_uint64, c_uint64, c_void_p], doc) doc = """ PICO_STATUS psospaStopUsingGetValuesOverlapped ( int16_t handle ); """ psospa.make_symbol("_StopUsingGetValuesOverlapped","psospaStopUsingGetValuesOverlapped", c_uint32, [c_int16], doc) doc = """ PICO_STATUS psospaGetNoOfCaptures ( int16_t handle, uint64_t* nCaptures ); """ psospa.make_symbol("_GetNoOfCaptures","psospaGetNoOfCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS psospaGetNoOfProcessedCaptures ( int16_t handle, uint64_t* nProcessedCaptures ); """ psospa.make_symbol("_GetNoOfProcessedCaptures","psospaGetNoOfProcessedCaptures", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS psospaStop ( int16_t handle ); """ psospa.make_symbol("_Stop","psospaStop", c_uint32, [c_int16], doc) doc = """ PICO_STATUS psospaSetNoOfCaptures ( int16_t handle, uint64_t nCaptures ); """ psospa.make_symbol("_SetNoOfCaptures","psospaSetNoOfCaptures", c_uint32, [c_int16, c_uint64], doc) doc = """ PICO_STATUS psospaGetTriggerInfo ( int16_t handle, PICO_TRIGGER_INFO* triggerInfo, uint64_t firstSegmentIndex, uint64_t segmentIndex ); """ psospa.make_symbol("_GetTriggerInfo","psospaGetTriggerInfo", c_uint32, [c_int16, c_void_p, c_uint64, c_uint64], doc) doc = """ PICO_STATUS psospaEnumerateUnits ( int16_t* count, int8_t* serials, int16_t* serialLth ); """ psospa.make_symbol("_EnumerateUnits","psospaEnumerateUnits", c_uint32, [c_void_p, c_char_p, c_void_p], doc) doc = """ PICO_STATUS psospaPingUnit ( int16_t handle ); """ psospa.make_symbol("_PingUnit","psospaPingUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS psospaGetAnalogueOffsetLimits ( int16_t handle, int64_t rangeMin, int64_t rangeMax, PICO_PROBE_RANGE_INFO rangeType, PICO_COUPLING coupling, double* maximumVoltage, double* minimumVoltage ); """ psospa.make_symbol("_GetAnalogueOffsetLimits","psospaGetAnalogueOffsetLimits", c_uint32, [c_int16, c_int64, c_int64, c_uint32, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaGetMinimumTimebaseStateless ( int16_t handle, PICO_CHANNEL_FLAGS enabledChannelFlags, uint32_t* timebase, double* timeInterval, PICO_DEVICE_RESOLUTION resolution ); """ psospa.make_symbol("_GetMinimumTimebaseStateless","psospaGetMinimumTimebaseStateless", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS psospaNearestSampleIntervalStateless ( int16_t handle, PICO_CHANNEL_FLAGS enabledChannelFlags, double timeIntervalRequested, uint8_t roundFaster, PICO_DEVICE_RESOLUTION resolution, uint32_t* timebase, double* timeIntervalAvailable ); """ psospa.make_symbol("_NearestSampleIntervalStateless","psospaNearestSampleIntervalStateless", c_uint32, [c_int16, c_uint32, c_double, c_char,c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaSetDeviceResolution ( int16_t handle, PICO_DEVICE_RESOLUTION resolution ); """ psospa.make_symbol("_SetDeviceResolution","psospaSetDeviceResolution", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaGetDeviceResolution ( int16_t handle, PICO_DEVICE_RESOLUTION* resolution ); """ psospa.make_symbol("_GetDeviceResolution","psospaGetDeviceResolution", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS psospaQueryOutputEdgeDetect ( int16_t handle, int16_t* state ); """ psospa.make_symbol("_QueryOutputEdgeDetect","psospaQueryOutputEdgeDetect", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS psospaSetOutputEdgeDetect ( int16_t handle int16_t state ); """ psospa.make_symbol("_SetOutputEdgeDetect","psospaSetOutputEdgeDetect", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS psospaGetScalingValues ( int16_t handle, PICO_SCALING_FACTORS_FOR_RANGE_TYPES_VALUES* scalingValues, int16_t nChannels ); """ psospa.make_symbol("_GetScalingValues","psospaGetScalingValues", c_uint32, [c_int16, c_void_p, c_int16], doc) doc = """ PICO_STATUS psospaGetAdcLimits ( int16_t handle, PICO_DEVICE_RESOLUTION resolution, int16_t* minValue, int16_t* maxValue ); """ psospa.make_symbol("_GetAdcLimits","psospaGetAdcLimits", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaCheckForUpdate ( int16_t handle, PICO_FIRMWARE_INFO* firmwareInfos, int16_t* nFirmwareInfos, uint16_t* updatesRequired ); """ psospa.make_symbol("_CheckForUpdate","psospaCheckForUpdate", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS psospaStartFirmwareUpdate ( int16_t handle, PicoUpdateFirmwareProgree progress ); """ psospa.make_symbol("_StartFirmwareUpdate","psospaStartFirmwareUpdate", c_uint32, [c_int16, c_uint32], doc) doc = """ PICO_STATUS psospaResetChannelsAndReportAllChannelsOvervoltageTripStatus ( int16_t handle, PICO_CHANNEL_OVERVOLTAGE_TRIPPED* allChannelsTriggedStatus, uint8_t nChannelTrippedStatus ); """ psospa.make_symbol("_ResetChannelsAndReportAllChannelsOVervoltageTripStatus","psospaResetChannelsAndReportAllChannelsOvervoltageTripStatus", c_uint32, [c_int16, c_void_p, c_char], doc) doc = """ PICO_STATUS psospaReportAllChannelsOvervoltageTripStatus ( int16_t handle, PICO_CHANNEL_OVERVOLTAGE_TRIPPED* allChannelsTriggedStatus, uint8_t nChannelTrippedStatus ); """ psospa.make_symbol("_ReportAllChannelsOvervoltageTripStatus","psospaReportAllChannelsOvervoltageTripStatus", c_uint32, [c_int16, c_void_p, c_char], doc) ================================================ FILE: picosdk/psospaBlockExample.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # # PSOSPA BLOCK MODE EXAMPLE # This example opens a psospa 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.psospa import psospa as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as structs # from picosdk.PicoConnectProbes import picoConnectProbes as probes import matplotlib.pyplot as plt from picosdk.functions import adc2mVV2, mV2adcV2, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open a psospa driver device # returns handle for future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openUnit"] = ps.psospaOpenUnit(ctypes.byref(chandle), None, resolution, None) assert_pico_ok(status["openUnit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC"] rangeMax = 2000000000 #nV rangeMin = -rangeMax #nV rangeType = 0 #probes.PICO_PROBE_RANGE_INFO["PICO_PROBE_NONE_NV"] analogueOffset = 0 bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.psospaSetChannelOn(chandle, channelA, coupling, rangeMin, rangeMax, rangeType, analogueOffset, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-D off for x in range (1, 3, 1): channel = x status["setChannel",x] = ps.psospaSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.psospaGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.psospaSetSimpleTrigger(chandle, 1, source, mV2adcV2(100,rangeMax,maxADC), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.psospaGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.psospaRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using psospaIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.psospaIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.psospaGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # # convert ADC counts data to mV adc2mVChAMax = adc2mVV2(bufferAMax, rangeMax, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, bufferAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the psospa driver device status["closeUnit"] = ps.psospaCloseUnit(chandle) assert_pico_ok(status["closeUnit"]) print(status) ================================================ FILE: picosdk/usbDrDaq.py ================================================ # # Copyright (C) 2014-2020 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the usbDrDaqApi.h C header file for DrDaq Data Logger using the usbDrDaq driver API functions. """ from ctypes import * from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.library import Library from picosdk.constants import make_enum class UsbDrDaqlib(Library): def __init__(self): super(UsbDrDaqlib, self).__init__("usbDrDaq") usbDrDaq = UsbDrDaqlib() usbDrDaq.USB_DRDAQ_INPUTS = { "USB_DRDAQ_CHANNEL_EXT1": 1, "USB_DRDAQ_CHANNEL_EXT2": 2, "USB_DRDAQ_CHANNEL_EXT3": 3, "USB_DRDAQ_CHANNEL_SCOPE": 4, "USB_DRDAQ_CHANNEL_PH": 5, "USB_DRDAQ_CHANNEL_RES": 6, "USB_DRDAQ_CHANNEL_LIGHT": 7, "USB_DRDAQ_CHANNEL_TEMP": 8, "USB_DRDAQ_CHANNEL_MIC_WAVE": 9, ("USB_DRDAQ_CHANNEL_MIC_LEVEL", "USB_DRDAQ_MAX_CHANNELS"): 10, } usbDrDaq.USB_DRDAQ_GPIO = { "USB_DRDAQ_GPIO_1":1, "USB_DRDAQ_GPIO_2":2, "USB_DRDAQ_GPIO_3":3, "USB_DRDAQ_GPIO_4":4 } usbDrDaq.USB_DRDAQ_SCOPE_RANGE = make_enum([ "USB_DRDAQ_1V25", "USB_DRDAQ_2V5", "USB_DRDAQ_5V", "USB_DRDAQ_10V" ]) usbDrDaq.USB_DRDAQ_WAVE = make_enum([ "USB_DRDAQ_SINE", "USB_DRDAQ_SQUARE", "USB_DRDAQ_TRIANGLE", "USB_DRDAQ_RAMP_UP", "USB_DRDAQ_RAMP_DOWN", "USB_DRDAQ_DC" ]) usbDrDaq.USB_DRDAQ_BLOCK_METHOD = make_enum([ "BM_SINGLE", "BM_WINDOW", "BM_STREAM" ]) doc = """ PICO_STATUS UsbDrDaqCloseUnit ( int16_t handle ); """ usbDrDaq.make_symbol("_CloseUnit", "UsbDrDaqCloseUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS UsbDrDaqEnabledRGBLED ( int16_t handle, int16_t enabled ); """ usbDrDaq.make_symbol("_EnableRGBLED", "UsbDrDaqEnableRGBLED", c_uint32, [c_int16, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqGetChannelInfo ( int16_t handle, float *min, float *max, int16_t *places, int16_t *divider, USB_DRDAQ_INPUTS channel ); """ usbDrDaq.make_symbol("_GetChannelInfo", "UsbDrDaqGetChannelInfo", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS UsbDrDaqGetInput ( int16_t handle, USB_DRDAQ_GPIO IOChannel, int16_t pullUp, int16_t *value ); """ usbDrDaq.make_symbol("_GetInput", "UsbDrDaqGetInput", c_uint32, [c_int16, c_uint32, c_int16, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqGetPulseCount ( int16_t handle, USB_DRDAQ_GPIO IOChannel, int16_t *count ); """ usbDrDaq.make_symbol("_GetPulseCount", "UsbDrDaqGetPulseCount", c_uint32, [c_int16, c_uint32, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqGetScalings ( int16_t handle, USB_DRDAQ_INPUTS channel, int16_t *nScales int16_t *currentScale, int8_t *names int16_t namesSize ); """ usbDrDaq.make_symbol("_GetScalings", "UsbDrDaqGetScalings", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p, c_void_p, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqGetSingle ( int16_t handle, USB_DRDAQ_INPUTS channel, int16_t *value, uint16_t *overflow ); """ usbDrDaq.make_symbol("_GetSingle", "UsbDrDaqGetSingle", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqGetSingleF ( int16_t handle, USB_DRDAQ_INPUTS channel, float *value, uint16_t *overflow ); """ usbDrDaq.make_symbol("_getSingleF", "UsbDrDaqGetSingleF", c_uint32, [c_int16, c_uint32, c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqGetTriggerTimeOffestNs ( int16_t handle, int64_t *time ); """ usbDrDaq.make_symbol("_GetTriggerTimeOffsetNs", "UsbDrDaqGetTriggerTimeOffsetNs", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqGetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ usbDrDaq.make_symbol("_GetUnitInfo", "UsbDrDaqGetUnitInfo", c_uint32, [c_int16, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS UsbDrDaqGetValues ( int16_t handle, int16_t *values, uint32_t *noOfValues, uint16_t *overflow, uint32_t *triggerIndex ); """ usbDrDaq.make_symbol("_GetValues", "UsbDrDaqGetValues", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqGetValuesF ( int16_t handle, float *values, uint32_t *noOfValues, uint16_t *overflow, uint32_t *triggerIndex ); """ usbDrDaq.make_symbol("_GetValuesF", "UsbDrDaqGetValuesF", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqOpenUnit ( int16_t *handle ); """ usbDrDaq.make_symbol("_OpenUnit", "UsbDrDaqOpenUnit", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqOpenUnitAsync ( int16_t *handle ); """ usbDrDaq.make_symbol("_OpenUnitAsync", "UsbDrDaqOpenUnitAsync", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqOpenUnitProgress ( int16_t *handle, int16_t *progress, int16_t *complete ); """ usbDrDaq.make_symbol("_OpenUnitProgress", "UsbDrDaqOpenUnitProgress", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqPhTemperatureCompensation ( int16_t handle, uint16_t enabled ); """ usbDrDaq.make_symbol("_PhTemperatureCompensation", "UsbDrDaqPhTemperatureCompensation", c_uint32, [c_int16, c_uint16], doc) doc = """ PICO_STATUS UsbDrDaqPingUnit ( int16_t *handle ); """ usbDrDaq.make_symbol("_PingUnit", "UsbDrDaqPingUnit", c_uint32, [c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqReady ( int16_t handle, int16_t *ready ); """ usbDrDaq.make_symbol("_Ready", "UsbDrDaqReady", c_uint32, [c_int16, c_void_p], doc) doc = """ PICO_STATUS UsbDrDaqRun ( int16_t handle, uint32_t no_of_values, BLOCK_METHOD method ); """ usbDrDaq.make_symbol("_Run", "UsbDrDaqRun", c_uint32, [c_int16, c_uint32, c_uint32], doc) doc = """ PICO_STATUS UsbDrDaqSetDO ( int16_t handle, USB_DRDAQ_GPIO IOChannel, int16_t value ); """ usbDrDaq.make_symbol("_SetDO", "UsbDrDaqSetDO", c_uint32, [c_int16, c_uint32, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqSetInterval ( int16_t handle, uint32_t *us_for_block, uint32_t ideal_no_of_samples, USB_DRDAQ_INPUTS *channels, int16_t no_of_channels ); """ usbDrDaq.make_symbol("_SetInterval", "UsbDrDaqSetInterval", c_uint32, [c_int16, c_void_p, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqSetIntervalF ( int16_t handle, float *us_for_block, uint32_t ideal_no_of_samples, USB_DRDAQ_INPUTS *channels, int16_t no_of_channels ); """ usbDrDaq.make_symbol("_SetIntervalF", "UsbDrDaqSetIntervalF", c_uint32, [c_int16, c_void_p, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqSetPWM ( int16_t handle, USB_DRDAQ_GPIO IOChannel, uint16_t period, uint8_t cycle ); """ usbDrDaq.make_symbol("_SetPWM", "UsbDrDaqSetPWM", c_uint32, [c_int16, c_uint32, c_uint16, c_uint8], doc) doc = """ PICO_STATUS UsbDrDaqSetRGBLED ( int16_t handle, uint16_t red, uint16_t green, uint16_t blue ); """ usbDrDaq.make_symbol("_SetRGBLED", "UsbDrDaqSetRGBLED", c_uint32, [c_int16, c_uint16, c_uint16, c_uint16], doc) doc = """ PICO_STATUS UsbDrDaqSetScalings ( int16_t handle, USB_DRDAQ_INPUTS channel, int16_t scalingNumber ); """ usbDrDaq.make_symbol("_SetScalings", "UsbDrDaqSetScalings", c_uint32, [c_int16, c_uint32, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqSetSigGenArbitary ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t *arbitaryWaveform, int16_t arbitaryWaveformSize, int32_t updateRate ); """ usbDrDaq.make_symbol("_SetSigGenArbitary", "UsbDrDaqSetSigGenArbitrary", c_uint32, [c_int16, c_int32, c_uint32, c_void_p, c_int16, c_int32], doc) doc = """ PICO_STATUS UsbDrDaqSetSigGenBuiltIn ( int16_t handle, int32_t offsetVoltage, uint32_t pkToPk, int16_t frequency, USB_DRDAQ_WAVE waveType ); """ usbDrDaq.make_symbol("_SetSigGenBuiltIn", "UsbDrDaqSetSigGenBuiltIn", c_uint32, [c_int16, c_int32, c_uint32, c_int16, c_uint32], doc) doc = """ PICO_STATUS UsbDrDaqSetTrigger ( int16_t handle, uint16_t enabled, uint16_t auto_trigger, uint16_t auto_ms, uint16_t channel, uint16_t dir, int16_t threshold, uint16_t hysteresis, float delay ); """ usbDrDaq.make_symbol("_SetTrigger", "UsbDrDaqSetTrigger", c_uint32, [c_int16, c_uint16, c_uint16, c_uint16, c_uint16, c_uint16,c_int16, c_uint16, c_float], doc) doc = """ PICO_STATUS UsbDrDaqStartPulseCount ( int16_t handle, USB_DRDAQ_GPIO IOChannel, int16_t direction ); """ usbDrDaq.make_symbol("_StartPulseCount", "UsbDrDaqStartPulseCount", c_uint32, [c_int16, c_uint32, c_int16], doc) doc = """ PICO_STATUS UsbDrDaqStop ( int16_t handle ); """ usbDrDaq.make_symbol("_Stop", "UsbDrDaqStop", c_uint32, [c_int16], doc) doc = """ PICO_STATUS UsbDrDaqStopSigGen ( int16_t handle ); """ usbDrDaq.make_symbol("_StopSigGen", "UsbDrDaqStopSigGen", c_uint32, [c_int16], doc) ================================================ FILE: picosdk/usbPT104.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the usbPT104Api.h C header file for Pico USB PT-104 datalogger using the usb PT104 driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from picosdk.constants import make_enum class usbpt104lib(Library): def __init__(self): super(usbpt104lib, self).__init__("usbpt104") usbPt104 = usbpt104lib() usbPt104.PT104_CHANNELS = { 'USBPT104_CHANNEL_1' : 1, 'USBPT104_CHANNEL_2' : 2, 'USBPT104_CHANNEL_3' : 3, 'USBPT104_CHANNEL_4' : 4, 'USBPT104_CHANNEL_5' : 5, 'USBPT104_CHANNEL_6' : 6, 'USBPT104_CHANNEL_7' : 7, 'USBPT104_CHANNEL_8' : 8, 'USBPT104_MAX_CHANNELS' : 8 } usbPt104.PT104_DATA_TYPE = make_enum([ 'USBPT104_OFF', 'USBPT104_PT100', 'USBPT104_PT1000', 'USBPT104_RESISTANCE_TO_375R', 'USBPT104_RESISTANCE_TO_10K', 'USBPT104_DIFFERENTIAL_TO_115MV', 'USBPT104_DIFFERENTIAL_TO_2500MV', 'USBPT104_SINGLE_ENDED_TO_115MV', 'USBPT104_SINGLE_ENDED_TO_2500MV', 'USBPT104_MAX_DATA_TYPES' ]) usbPt104.IP_DETAILS_TYPE = make_enum([ 'IDT_GET' 'IDT_SET' ]) def _define_communication_type(): CT_USB = 0x00000001 CT_ETHERNET = 0x00000002 CT_ALL = 0xFFFFFFFF return {k.upper(): v for k, v in locals().items() if k.startswith("CT")} usbPt104.COMMUNICATION_TYPE = _define_communication_type() doc = """ PICO_STATUS UsbPt104CloseUnit ( int16_t handle ); """ usbPt104.make_symbol("_CloseUnit", "UsbPt104CloseUnit", c_uint32, [c_int16], doc) doc = """ PICO_STATUS UsbPt104Enumerate ( int8_t *details, uint32_t *length, COMMUNICATION_TYPE type ); """ usbPt104.make_symbol("_Enumerate", "UsbPt104Enumerate", c_uint32, [c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS UsbPt104GetUnitInfo ( int16_t handle, int8_t *string, int16_t stringLength, int16_t *requiredSize, PICO_INFO info ); """ usbPt104.make_symbol("_GetUnitInfo", "UsbPt104GetUnitInfo", c_uint32, [c_int16, c_void_p, c_int16, c_void_p, c_uint32], doc) doc = """ PICO_STATUS UsbPt104GetValue ( int16_t handle, USBPT104_CHANNELS channel, int32_t *value, int16_t filtered ); """ usbPt104.make_symbol("_GetValue", "UsbPt104GetValue", c_uint32, [c_int16, c_uint32, c_void_p, c_int16], doc) doc = """ PICO_STATUS UsbPt104IpDetails ( int16_t handle, int16_t *enabled, int8_t *ipaddress, uint16_t *length, uint16_t *listeningPort, IP_DETAILS_TYPE type ); """ usbPt104.make_symbol("_IpDetails", "UsbPt104IpDetails", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32], doc) doc = """ PICO_STATUS UsbPt104OpenUnit ( int16_t *handle, int8_t *serial ); """ usbPt104.make_symbol("_OpenUnit", "UsbPt104OpenUnit", c_uint32, [c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbPt104OpenUnitViaIp ( int16_t *handle, int8_t *serial, int8_t *ipAddress ); """ usbPt104.make_symbol("_OpenUnitViaIp", "UsbPt104OpenUnitViaIp", c_uint32, [c_void_p, c_void_p, c_void_p], doc) doc = """ PICO_STATUS UsbPt104SetChannel ( int16_t handle, USBPT104_CHANNELS channel, USBPT104_DATA_TYPES type, int16_t noOfWires ); """ usbPt104.make_symbol("_SetChannel", "UsbPt104SetChannel", c_uint32, [c_int16, c_uint32, c_uint32, c_int16], doc) doc = """ PICO_STATUS UsbPt104SetMains ( int16_t handle, uint16_t sixty_hertz ); """ usbPt104.make_symbol("_SetMains", "UsbPt104SetMains", c_uint32, [c_int16, c_uint16], doc) ================================================ FILE: picosdk/usbtc08.py ================================================ # # Copyright (C) 2015-2018 Pico Technology Ltd. See LICENSE file for terms. # """ This is a Python module defining the functions from the usbtc08.h C header file for TC-08 Thermocouple Data Logger using the usbtc08 driver API functions. """ from ctypes import * from picosdk.library import Library from picosdk.errors import ArgumentOutOfRangeError from picosdk.constants import make_enum class usbtc08lib(Library): def __init__(self): super(usbtc08lib, self).__init__("usbtc08") usbtc08 = usbtc08lib() usbtc08.USBTC08_UNITS = make_enum([ "USBTC08_UNITS_CENTIGRADE", "USBTC08_UNITS_FAHRENHEIT", "USBTC08_UNITS_KELVIN", "USBTC08_UNITS_RANKINE", ]) class USBTC08_INFO(Structure): _pack_ = 1 _fields_ = [("size", c_int16), ("DriverVersion", c_char * 12), ("PicoppVersion", c_int16), ("HardwareVersion", c_int16), ("Variant", c_int16), ("szSerial[USBTC08_MAX_SERIAL_CHAR]", c_char * 11), ("szCalDate[USBTC08_MAX_DATE_CHARS]", c_char * 9)] doc = """ int16_t usb_tc08_open_unit ( void ); """ usbtc08.make_symbol("_open_unit_","usb_tc08_open_unit", c_int16, [], doc) doc = """ int16_t usb_tc08_open_unit_async ( void ); """ usbtc08.make_symbol("_open_unit_async_","usb_tc08_open_unit_async", c_int16, [], doc) doc = """ int16_t usb_tc08_open_unit_progress ( int16_t *handle, int16_t *progress ); """ usbtc08.make_symbol("_open_unit_progress_","usb_tc08_open_unit_progress", c_int16, [c_void_p, c_void_p], doc) doc = """ int16_t usb_tc08_close_unit ( int16_t handle ); """ usbtc08.make_symbol("_close_unit_","usb_tc08_close_unit", c_int16, [c_int16], doc) doc = """ int16_t usb_tc08_stop ( int16_t handle ); """ usbtc08.make_symbol("_stop_","usb_tc08_stop", c_int16, [c_int16], doc) doc = """ int16 usb_tc08_set_mains ( int16_t handle, int16_t sixty_hertz ); """ usbtc08.make_symbol("_set_mains_","usb_tc08_set_mains", c_int16, [c_int16, c_int16], doc) doc = """ int32_t usb_tc08_get_minimum_interval_ms ( int16_t handle ); """ usbtc08.make_symbol("_get_minimum_interval_ms_","usb_tc08_get_minimum_interval_ms", c_int16, [c_int16], doc) doc = """ int16_t usb_tc08_get_unit_info ( int16_t handle USBTC08_INFO *info ); """ usbtc08.make_symbol("_get_unit_info_","usb_tc08_get_unit_info", c_int16, [c_int16, c_void_p], doc) doc = """ int16_t usb_tc08_get_unit_info2 ( int16_t handle, int8_t *string, int16_t string_length, int16_t line ); """ usbtc08.make_symbol("_get_unit_info2_","usb_tc08_get_unit_info2", c_int16, [c_int16, c_void_p, c_int16, c_int16], doc) doc = """ int16_t usb_tc08_get_formatted_info ( int16_t handle, int8_t *unit_info, int16_t string_length ); """ usbtc08.make_symbol("_get_formatted_info_","usb_tc08_get_formatted_info", c_int16, [c_int16, c_void_p, c_int16], doc) doc = """ int16_t usb_tc08_get_last_error ( int16_t handle ); """ usbtc08.make_symbol("_get_last_error_","usb_tc08_get_last_error", c_int16, [c_int16], doc) doc = """ int16_t usb_tc08_set_channel ( int16_t handle, int16_t channel, int8_t tc_type ); """ usbtc08.make_symbol("_set_channel_","usb_tc08_set_channel", c_int16, [c_int16, c_int16, c_int8], doc) doc = """ int32_t usb_tc08_run ( int16_t handle, int32_t interval ); """ usbtc08.make_symbol("_run_","usb_tc08_run", c_int16, [c_int16, c_int32], doc) doc = """ int16_t usb_tc08_get_single ( int16_t handle, float *temp, int16_t *overflow_flags, int16_t units ); """ usbtc08.make_symbol("_get_single_","usb_tc08_get_single", c_int16, [c_int16, c_void_p, c_void_p, c_int16], doc) doc = """ int32_t usb_tc08_get_temp ( int16_t handle, float *temp_buffer, int32_t *times_ms_buffer, int32_t buffer_length, int16_t *overflow, int16_t channel, int16_t units, int16_t fill_missing ); """ usbtc08.make_symbol("_get_temp_","usb_tc08_get_temp", c_int16, [c_int16, c_void_p, c_void_p, c_int32, c_void_p, c_void_p, c_int16, c_int16], doc) doc = """ int32_t usb_tc08_get_temp_deskew ( int16_t handle, float *temp_buffer, int32_t *times, int32_t buffer_length, int16_t *overflow, int16_t channel, int16_t units, int16_t fill_missing ); """ usbtc08.make_symbol("_get_temp_deskew_","usb_tc08_get_temp_deskew", c_int16, [c_int16, c_void_p, c_void_p, c_int32, c_void_p, c_int16, c_int16, c_int16], doc) ================================================ FILE: picosynthExamples/picosynthFrequencySweepExample.py ================================================ # # Copyright (C) 2022 Pico Technology Ltd. See LICENSE file for terms. # # PicoSource AS108 Agile Synthesizer Example # This example demonstrates how to use the PicoSource AS108 picosynth driver API functions to set up the signal generator to output a frequency sweep. # import ctypes from picosdk.picosynth import picosynth as ps import time from picosdk.functions import assert_pico_ok # setup needed variables status = {} chandle = ctypes.c_uint32() # open AS108 device status["openunit"] = ps.picosynthOpenUnit(ps.PICO_SOURCE_MODEL["PICO_SYNTH"], ctypes.byref(chandle),0) assert_pico_ok(status["openunit"]) # set up a frequency sweep # handle = chandle startFreqHz = 300000 #Hz stopFreqHz = 1000000 #Hz startLevel = 2 stopLevel = 2 levelUnit = 1 # VoltsPkToPk dwellTimeUs = 100 pointsInSweep = 1000 mode = 0 #SweepAndFlyback triggerMode = 0 # InternalTrigger status["setFrequencyAndLevelSweep"] = ps.picosynthSetFrequencyAndLevelSweep(chandle,startFreqHz,stopFreqHz,startLevel,stopLevel,levelUnit,dwellTimeUs,pointsInSweep,mode,triggerMode) assert_pico_ok(status["setFrequencyAndLevelSweep"]) time.sleep(10) # close AS108 device status["closeunit"] = ps.picosynthCloseUnit(chandle) assert_pico_ok(status["closeunit"]) time.sleep(20) # open AS108 device status["openunit"] = ps.picosynthOpenUnit(ps.PICO_SOURCE_MODEL["PICO_SYNTH"], ctypes.byref(chandle),0) assert_pico_ok(status["openunit"]) # set output off status["setOutputOff"] = ps.picosynthSetOutputOff(chandle) # close AS108 device status["closeunit"] = ps.picosynthCloseUnit(chandle) assert_pico_ok(status["closeunit"]) # Displays the status returns print(status) ================================================ FILE: pl1000Examples/pl1000SingleModeExample.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # PL1000 SINGLE MODE EXAMPLE # This example opens a pl1000 device, sets up the device for capturing data from channel 1. # Then this example collect a sample from channel 1 and displays it on the console. import ctypes import numpy as np from picosdk.pl1000 import pl1000 as pl import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open PicoLog 1000 device status["openUnit"] = pl.pl1000OpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openUnit"]) value = ctypes.c_int16() # get a single ADC count value from channel 1 status["getSingle"] = pl.pl1000GetSingle(chandle, pl.PL1000Inputs["PL1000_CHANNEL_1"], ctypes.byref(value)) assert_pico_ok(status["getSingle"]) print(value.value) # close PicoLog 1000 device status["closeUnit"] = pl.pl1000CloseUnit(chandle) assert_pico_ok(status["closeUnit"]) # display status returns print(status) ================================================ FILE: pl1000Examples/pl1000StreamingModeExample.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # PL1000 STREAMING MODE EXAMPLE # This example opens a PicoLog 1000 device, configures streaming mode to capture data from channel 1 at # a sampling rate of 100 kS/s for 10 seconds, retrieves the data, and displays it on a plot. import ctypes import numpy as np from picosdk.pl1000 import pl1000 as pl import matplotlib.pyplot as plt from picosdk.functions import adc2mVpl1000, assert_pico_ok from time import sleep # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # open PicoLog 1000 device status["openUnit"] = pl.pl1000OpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openUnit"]) # set sampling interval usForBlock = ctypes.c_uint32(10000000) noOfValues = ctypes.c_uint32(1000000) channels = ctypes.c_int16(1) status["setInterval"] = pl.pl1000SetInterval(chandle, ctypes.byref(usForBlock), noOfValues, ctypes.byref(channels), 1) assert_pico_ok(status["setInterval"]) # start streaming mode = pl.PL1000_BLOCK_METHOD["BM_STREAM"] status["run"] = pl.pl1000Run(chandle, 1000000, mode) assert_pico_ok(status["run"]) sleep(usForBlock.value / 1000000) values = (ctypes.c_uint16 * noOfValues.value)() oveflow = ctypes.c_uint16() status["getValues"] = pl.pl1000GetValues(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(oveflow), None) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV maxADC = ctypes.c_uint16() status["maxValue"] = pl.pl1000MaxValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maxValue"]) inputRange = 2500 mVValues = adc2mVpl1000(values, inputRange, maxADC) # create time data interval = (0.001 * usForBlock.value)/(noOfValues.value * 1) timeMs = np.linspace(0, (len(mVValues) -1) * interval, len(mVValues)) # plot data plt.plot(timeMs, mVValues[:]) plt.xlabel('Time (ms)') plt.ylabel('Voltage (mV)') plt.show() # close PicoLog 1000 device status["closeUnit"] = pl.pl1000CloseUnit(chandle) assert_pico_ok(status["closeUnit"]) # display status returns print(status) ================================================ FILE: pl1000Examples/pl1000StreamingModeMultiChannelExample.py ================================================ # # Copyright (C) 2025 Pico Technology Ltd. See LICENSE file for terms. # # PL1000 STREAMING MODE MULTICHANNEL EXAMPLE # This example opens a PicoLog 1000 device, configures streaming mode to capture data from N channels # at the set sample rate, retrieves the data, and displays it on a plot. import ctypes import time from typing import Optional import numpy import picosdk.pl1000 import matplotlib.pyplot as plt from picosdk.functions import assert_pico_ok, adc2mVpl1000 # Setup channels values and arrays channel_list=(1,2,3,4,5,6,7,8,9,10,11,12) # Enable Chs 1-12, Max channels (1012) # channel_list=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16) # Enable Chs 1-16, Max channels (1216) n_channels = len(channel_list) print(f"{n_channels} channels") channel_array = (ctypes.c_int16 * len(channel_list))() for i, ch in enumerate(channel_list): channel_array[i] = picosdk.pl1000.pl1000.PL1000Inputs[f"PL1000_CHANNEL_{ch}"] # Max streaming sample rate for # 1012 - with all 12 channels on is = 100k /12 = 8333S/s # 1216 - with all 16 channels on is = 100k /16 = 6250S/s us_for_block = ctypes.c_uint32(1_000_000) # 1 seconds in microseconds ideal_no_of_samples = 6250 # Max sample rate for both 1012/1216 with 12 Chs on # As us_for_block is set to 1M, "ideal_no_of_samples" becomes the sample rate per channel (in Samples/second) read_buffer_size = ideal_no_of_samples * n_channels read_sample_count = ctypes.c_uint32(read_buffer_size) # reserve memory read_buffer = (ctypes.c_uint16 * read_buffer_size)() # reserve memory for read_buffer captured_samples=numpy.zeros(shape=(0,n_channels), dtype=numpy.uint16) leftover_sample_buffer = numpy.zeros(shape=(0,), dtype=numpy.uint16) leftover_sample_counter = 0 # Datatypes for Addition capture Info overflow = ctypes.c_uint16() triggerIndex = ctypes.c_uint32() # Open the device handle = ctypes.c_int16() assert_pico_ok(picosdk.pl1000.pl1000.pl1000OpenUnit(ctypes.byref(handle))) # Configure sampling interval assert_pico_ok( picosdk.pl1000.pl1000.pl1000SetInterval( handle, ctypes.byref(us_for_block), ctypes.c_uint32(ideal_no_of_samples), channel_array, len(channel_list) ) ) print(f'ideal_no_of_samples: {ideal_no_of_samples}') print(f'read_buffer_size: {read_buffer_size}') print(f'us_for_block: {us_for_block}') # start acquisition assert_pico_ok( picosdk.pl1000.pl1000.pl1000Run( handle, ctypes.c_uint32(read_buffer_size), picosdk.pl1000.pl1000.PL1000_BLOCK_METHOD["BM_STREAM"] ) ) # Check device is ready using IsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: assert_pico_ok( picosdk.pl1000.pl1000.pl1000Ready(handle, ctypes.byref(ready)) ) # start download loop: for iteration_idx in range(9): time.sleep(0.1) # wait to part fill the buffer (never let it fill up!!) read_sample_count = ctypes.c_uint32((int)(read_buffer_size // n_channels)) assert_pico_ok( picosdk.pl1000.pl1000.pl1000GetValues( handle, ctypes.byref(read_buffer), ctypes.byref(read_sample_count), # gets modified on return (per channel) ctypes.byref(overflow), # Channel voltage over range bit flags (LSB is Ch0) ctypes.byref(triggerIndex) ) ) # check how many samples have actually been captured: print(f"iteration {iteration_idx}: readout {read_sample_count.value} samples across {n_channels} channels") read_samples_numpy_varsized = numpy.array(read_buffer[:read_sample_count.value * n_channels]) # get only the valid samples out of the read_buffer print(f' - read_samples_numpy_varsized.shape: {read_samples_numpy_varsized.shape}') # now, we can reshape the running buffer, which is now well sized, to a 2D array: channelized_samples = read_samples_numpy_varsized.reshape((-1,n_channels)) # Append to final Array captured_samples = numpy.vstack((captured_samples,channelized_samples)) # Debug - list array sizes # print(f' - channelized_samples.shape: {channelized_samples.shape}') # print(f' - captured_samples.shape: {captured_samples.shape}') # print('---') # Close unit assert_pico_ok(picosdk.pl1000.pl1000.pl1000CloseUnit(handle)) # Display data print(f'Final captured_samples (Samples, NoOfChannels): {captured_samples.shape}') print(f'Channel_list: {channel_list}') samples_per_s = (ideal_no_of_samples * us_for_block.value / 1_000_000) interval = 1 / samples_per_s print(f" { interval }s Sample Interval = { samples_per_s }Samples/sec ") time_s = numpy.linspace(0, (len(captured_samples[:,0]) -1) * interval, len(captured_samples[:,0])) plt.plot(time_s, captured_samples[:,0]) plt.plot(time_s, captured_samples[:,1]) plt.plot(time_s, captured_samples[:,2]) # 3 channels plt.plot(time_s, captured_samples[:,3]) plt.plot(time_s, captured_samples[:,4]) plt.plot(time_s, captured_samples[:,5]) # 6 channels plt.plot(time_s, captured_samples[:,6]) plt.plot(time_s, captured_samples[:,7]) plt.plot(time_s, captured_samples[:,8]) # 9 channels plt.plot(time_s, captured_samples[:,9]) plt.plot(time_s, captured_samples[:,10]) plt.plot(time_s, captured_samples[:,11]) # 12 Max channels (1012) #plt.plot(time_s, captured_samples[:,12]) #plt.plot(time_s, captured_samples[:,13]) #plt.plot(time_s, captured_samples[:,14]) #plt.plot(time_s, captured_samples[:,15]) # 16 Max channels (1216) plt.xlabel('Time (s)') plt.ylabel('ADC counts') plt.show() ================================================ FILE: ps2000Examples/advanced triggers/trigger_read_dropout.py ================================================ from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 from time import sleep import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 PRESAMPLE = 80.0 ADC_THRESHOLD = 1000 THRESHOLD_DIRECTION = { 'PS2000_ABOVE': 0, 'PS2000_BELOW': 1, 'PS2000_ADV_RISING': 2, 'PS2000_ADV_FALLING': 3, 'PS2000_ADV_RISING_OR_FALLING': 4, 'PS2000_INSIDE': 0, 'PS2000_OUTSIDE': 1, 'PS2000_ENTER': 2, 'PS2000_EXIT': 3, 'PS2000_ENTER_OR_EXIT': 4, 'PS2000_ADV_NONE': 2, } class TriggerConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ('pulseWidthQualifier', c_int32), ] class PwqConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ] class TriggerChannelProperties(Structure): _fields_ = [ ("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int16), ("thresholdMode", c_int16), ] def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, SAMPLES, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_500MV'] ) assert_pico2000_ok(res) trigger_conditions = TriggerConditions(0, 0, 0, 0, 0, 1) res = ps2000.ps2000SetAdvTriggerChannelConditions( device.handle, byref(trigger_conditions), 1 ) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerDelay(device.handle, 0, -PRESAMPLE) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerChannelDirections( device.handle, THRESHOLD_DIRECTION['PS2000_ADV_RISING_OR_FALLING'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'] ) assert_pico2000_ok(res) trigger_properties = TriggerChannelProperties( ADC_THRESHOLD, -ADC_THRESHOLD, 0, ps2000.PS2000_CHANNEL['PS2000_CHANNEL_A'], picoEnum.PICO_THRESHOLD_MODE['PICO_WINDOW'] ) res = ps2000.ps2000SetAdvTriggerChannelProperties(device.handle, byref(trigger_properties), 1, 0) assert_pico2000_ok(res) pwq_conditions = PwqConditions(1, 0, 0, 0, 0) res = ps2000.ps2000SetPulseWidthQualifier( device.handle, byref(pwq_conditions), 1, THRESHOLD_DIRECTION['PS2000_ENTER'], 200, 0, picoEnum.PICO_PULSE_WIDTH_TYPE['PICO_PW_TYPE_GREATER_THAN'] ) assert_pico2000_ok(res) # calculate timebase timebase_a, interval = get_timebase(device, 20_000) collection_time = c_int32() fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('ADC counts') res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) # wait for ready signal while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), None, None, None, None, 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) ax.plot(list(map(lambda x: x * 1e-6, times[:])), buffer_a[:]) ax.axvline(np.percentile(list(map(lambda x: x * 1e-6, times[:])), PRESAMPLE), color='red', linestyle='dotted') ps2000.ps2000_stop(device.handle) plt.show() ================================================ FILE: ps2000Examples/advanced triggers/trigger_read_interval.py ================================================ from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 from time import sleep import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 PRESAMPLE = 80.0 THRESHOLD_DIRECTION = { 'PS2000_ABOVE': 0, 'PS2000_BELOW': 1, 'PS2000_ADV_RISING': 2, 'PS2000_ADV_FALLING': 3, 'PS2000_ADV_RISING_OR_FALLING': 4, 'PS2000_INSIDE': 0, 'PS2000_OUTSIDE': 1, 'PS2000_ENTER': 2, 'PS2000_EXIT': 3, 'PS2000_ENTER_OR_EXIT': 4, 'PS2000_ADV_NONE': 2, } class TriggerConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ('pulseWidthQualifier', c_int32), ] class PwqConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ] class TriggerChannelProperties(Structure): _fields_ = [ ("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int16), ("thresholdMode", c_int16), ] def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, SAMPLES, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_500MV'] ) assert_pico2000_ok(res) trigger_conditions = TriggerConditions(1, 0, 0, 0, 0, 1) res = ps2000.ps2000SetAdvTriggerChannelConditions(device.handle, byref(trigger_conditions), 1) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerDelay(device.handle, 0, -PRESAMPLE) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerChannelDirections( device.handle, THRESHOLD_DIRECTION['PS2000_ADV_RISING_OR_FALLING'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'] ) assert_pico2000_ok(res) trigger_properties = TriggerChannelProperties( 32000, 2048, 328, ps2000.PS2000_CHANNEL['PS2000_CHANNEL_A'], picoEnum.PICO_THRESHOLD_MODE['PICO_WINDOW'] ) res = ps2000.ps2000SetAdvTriggerChannelProperties(device.handle, byref(trigger_properties), 1, 0) assert_pico2000_ok(res) pwq_conditions = PwqConditions(1, 0, 0, 0, 0) res = ps2000.ps2000SetPulseWidthQualifier( device.handle, byref(pwq_conditions), 1, THRESHOLD_DIRECTION['PS2000_ENTER_OR_EXIT'], 600, 0, picoEnum.PICO_PULSE_WIDTH_TYPE['PICO_PW_TYPE_GREATER_THAN'] ) assert_pico2000_ok(res) timebase_a, interval = get_timebase(device, 4_000) collection_time = c_int32() fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('ADC counts') res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), None, None, None, None, 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) ax.plot(list(map(lambda x: x * 1e-6, times[:])), buffer_a[:]) ax.axvline(np.percentile(list(map(lambda x: x * 1e-6, times[:])), PRESAMPLE), color='red', linestyle='dotted') ps2000.ps2000_stop(device.handle) plt.show() ================================================ FILE: ps2000Examples/advanced triggers/trigger_read_pwq.py ================================================ from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 from time import sleep import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 PRESAMPLE = 10.0 ADC_THRESHOLD = 8192 THRESHOLD_DIRECTION = { 'PS2000_ABOVE': 0, 'PS2000_BELOW': 1, 'PS2000_ADV_RISING': 2, 'PS2000_ADV_FALLING': 3, 'PS2000_ADV_RISING_OR_FALLING': 4, 'PS2000_INSIDE': 0, 'PS2000_OUTSIDE': 1, 'PS2000_ENTER': 2, 'PS2000_EXIT': 3, 'PS2000_ENTER_OR_EXIT': 4, 'PS2000_ADV_NONE': 2, } class TriggerConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ('pulseWidthQualifier', c_int32), ] class PwqConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ] class TriggerChannelProperties(Structure): _fields_ = [ ("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int16), ("thresholdMode", c_int16), ] def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, SAMPLES, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'] ) assert_pico2000_ok(res) trigger_conditions = TriggerConditions(1, 0, 0, 0, 0, 1) res = ps2000.ps2000SetAdvTriggerChannelConditions(device.handle, byref(trigger_conditions), 1) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerDelay(device.handle, 0, -PRESAMPLE) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerChannelDirections( device.handle, THRESHOLD_DIRECTION['PS2000_ADV_RISING_OR_FALLING'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'] ) assert_pico2000_ok(res) trigger_properties = TriggerChannelProperties( ADC_THRESHOLD, ADC_THRESHOLD, 328, ps2000.PS2000_CHANNEL['PS2000_CHANNEL_A'], picoEnum.PICO_THRESHOLD_MODE['PICO_LEVEL'] ) res = ps2000.ps2000SetAdvTriggerChannelProperties(device.handle, byref(trigger_properties), 1, 0) assert_pico2000_ok(res) pwq_conditions = PwqConditions(1, 0, 0, 0, 0) res = ps2000.ps2000SetPulseWidthQualifier( device.handle, byref(pwq_conditions), 1, THRESHOLD_DIRECTION['PS2000_ADV_RISING_OR_FALLING'], 1000, 0, picoEnum.PICO_PULSE_WIDTH_TYPE['PICO_PW_TYPE_GREATER_THAN'] ) assert_pico2000_ok(res) timebase_a, interval = get_timebase(device, 20_000) collection_time = c_int32() fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('ADC counts') res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), None, None, None, None, 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) ax.plot(list(map(lambda x: x * 1e-6, times[:])), buffer_a[:]) ax.plot(list(map(lambda x: x * 1e-6, times[:])), [ADC_THRESHOLD for _ in times[:]], color='red') ax.axvline(np.percentile(list(map(lambda x: x * 1e-6, times[:])), PRESAMPLE), color='red', linestyle='dotted') ps2000.ps2000_stop(device.handle) plt.show() ================================================ FILE: ps2000Examples/advanced triggers/trigger_read_runt.py ================================================ from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 from time import sleep import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 PRESAMPLE = 80.0 ADC_THRESHOLDS = (12000, 2048) THRESHOLD_DIRECTION = { 'PS2000_ABOVE': 0, 'PS2000_BELOW': 1, 'PS2000_ADV_RISING': 2, 'PS2000_ADV_FALLING': 3, 'PS2000_ADV_RISING_OR_FALLING': 4, 'PS2000_INSIDE': 0, 'PS2000_OUTSIDE': 1, 'PS2000_ENTER': 2, 'PS2000_EXIT': 3, 'PS2000_ENTER_OR_EXIT': 4, 'PS2000_ADV_NONE': 2, } class TriggerConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ('pulseWidthQualifier', c_int32), ] class PwqConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ] class TriggerChannelProperties(Structure): _fields_ = [ ("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int16), ("thresholdMode", c_int16), ] def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, SAMPLES, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_500MV'] ) assert_pico2000_ok(res) trigger_conditions = TriggerConditions(0, 0, 0, 0, 0, 1) res = ps2000.ps2000SetAdvTriggerChannelConditions(device.handle, byref(trigger_conditions), 1) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerDelay(device.handle, 0, -PRESAMPLE) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerChannelDirections( device.handle, THRESHOLD_DIRECTION['PS2000_EXIT'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'] ) assert_pico2000_ok(res) trigger_properties = TriggerChannelProperties( max(ADC_THRESHOLDS), min(ADC_THRESHOLDS), 328, ps2000.PS2000_CHANNEL['PS2000_CHANNEL_A'], picoEnum.PICO_THRESHOLD_MODE['PICO_WINDOW'] ) res = ps2000.ps2000SetAdvTriggerChannelProperties(device.handle, byref(trigger_properties), 1, 0) assert_pico2000_ok(res) pwq_conditions = PwqConditions(1, 0, 0, 0, 0) res = ps2000.ps2000SetPulseWidthQualifier( device.handle, byref(pwq_conditions), 1, THRESHOLD_DIRECTION['PS2000_ENTER'], 100, 0, picoEnum.PICO_PULSE_WIDTH_TYPE['PICO_PW_TYPE_GREATER_THAN'] ) assert_pico2000_ok(res) timebase_a, interval = get_timebase(device, 4_000) collection_time = c_int32() fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('ADC counts') res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), None, None, None, None, 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) ax.plot(list(map(lambda x: x * 1e-6, times[:])), buffer_a[:]) for threshold in ADC_THRESHOLDS: ax.plot(list(map(lambda x: x * 1e-6, times[:])), [threshold for _ in times[:]], color='red') ax.axvline(np.percentile(list(map(lambda x: x * 1e-6, times[:])), PRESAMPLE), color='red', linestyle='dotted') ps2000.ps2000_stop(device.handle) plt.show() ================================================ FILE: ps2000Examples/advanced triggers/trigger_read_window.py ================================================ from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 from time import sleep import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 PRESAMPLE = 25.0 ADC_THRESHOLD = 8192 THRESHOLD_DIRECTION = { 'PS2000_ABOVE': 0, 'PS2000_BELOW': 1, 'PS2000_ADV_RISING': 2, 'PS2000_ADV_FALLING': 3, 'PS2000_ADV_RISING_OR_FALLING': 4, 'PS2000_INSIDE': 0, 'PS2000_OUTSIDE': 1, 'PS2000_ENTER': 2, 'PS2000_EXIT': 3, 'PS2000_ENTER_OR_EXIT': 4, 'PS2000_ADV_NONE': 2, } class TriggerConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ('pulseWidthQualifier', c_int32), ] class PwqConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ] class TriggerChannelProperties(Structure): _fields_ = [ ("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int16), ("thresholdMode", c_int16), ] def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, SAMPLES, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'] ) assert_pico2000_ok(res) trigger_conditions = TriggerConditions(1, 0, 0, 0, 0, 0) res = ps2000.ps2000SetAdvTriggerChannelConditions(device.handle, byref(trigger_conditions), 1) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerDelay(device.handle, 0, -PRESAMPLE) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerChannelDirections( device.handle, THRESHOLD_DIRECTION['PS2000_EXIT'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'] ) assert_pico2000_ok(res) trigger_properties = TriggerChannelProperties( ADC_THRESHOLD, -ADC_THRESHOLD, 2, ps2000.PS2000_CHANNEL['PS2000_CHANNEL_A'], picoEnum.PICO_THRESHOLD_MODE['PICO_WINDOW'] ) res = ps2000.ps2000SetAdvTriggerChannelProperties(device.handle, byref(trigger_properties), 1, 0) assert_pico2000_ok(res) timebase_a, interval = get_timebase(device, 20_000) collection_time = c_int32() fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('ADC counts') res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), None, None, None, None, 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) ax.plot(list(map(lambda x: x * 1e-6, times[:])), buffer_a[:]) ax.plot(list(map(lambda x: x * 1e-6, times[:])), [ADC_THRESHOLD for _ in times[:]], color='red') ax.plot(list(map(lambda x: x * 1e-6, times[:])), [-ADC_THRESHOLD for _ in times[:]], color='red') ax.axvline(np.percentile(list(map(lambda x: x * 1e-6, times[:])), PRESAMPLE), color='red', linestyle='dotted') ps2000.ps2000_stop(device.handle) plt.show() ================================================ FILE: ps2000Examples/advanced triggers/trigger_read_wpwq.py ================================================ from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 from time import sleep import numpy as np from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 PRESAMPLE = 80.0 ADC_THRESHOLDS = (6553, 32000) THRESHOLD_DIRECTION = { 'PS2000_ABOVE': 0, 'PS2000_BELOW': 1, 'PS2000_ADV_RISING': 2, 'PS2000_ADV_FALLING': 3, 'PS2000_ADV_RISING_OR_FALLING': 4, 'PS2000_INSIDE': 0, 'PS2000_OUTSIDE': 1, 'PS2000_ENTER': 2, 'PS2000_EXIT': 3, 'PS2000_ENTER_OR_EXIT': 4, 'PS2000_ADV_NONE': 2, } class TriggerConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ('pulseWidthQualifier', c_int32), ] class PwqConditions(Structure): _fields_ = [ ('channelA', c_int32), ('channelB', c_int32), ('channelC', c_int32), ('channelD', c_int32), ('external', c_int32), ] class TriggerChannelProperties(Structure): _fields_ = [ ("thresholdMajor", c_int16), ("thresholdMinor", c_int16), ("hysteresis", c_uint16), ("channel", c_int16), ("thresholdMode", c_int16), ] def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, SAMPLES, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'] ) assert_pico2000_ok(res) trigger_conditions = TriggerConditions(0, 0, 0, 0, 0, 1) res = ps2000.ps2000SetAdvTriggerChannelConditions(device.handle, byref(trigger_conditions), 1) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerDelay(device.handle, 0, -PRESAMPLE) assert_pico2000_ok(res) res = ps2000.ps2000SetAdvTriggerChannelDirections( device.handle, THRESHOLD_DIRECTION['PS2000_ENTER'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'], THRESHOLD_DIRECTION['PS2000_ADV_NONE'] ) assert_pico2000_ok(res) trigger_properties = TriggerChannelProperties( max(ADC_THRESHOLDS), min(ADC_THRESHOLDS), 328, ps2000.PS2000_CHANNEL['PS2000_CHANNEL_A'], picoEnum.PICO_THRESHOLD_MODE['PICO_WINDOW'] ) res = ps2000.ps2000SetAdvTriggerChannelProperties(device.handle, byref(trigger_properties), 1, 0) assert_pico2000_ok(res) pwq_conditions = PwqConditions(1, 0, 0, 0, 0) res = ps2000.ps2000SetPulseWidthQualifier( device.handle, byref(pwq_conditions), 1, THRESHOLD_DIRECTION['PS2000_ENTER'], 195, 0, picoEnum.PICO_PULSE_WIDTH_TYPE['PICO_PW_TYPE_GREATER_THAN'] ) assert_pico2000_ok(res) timebase_a, interval = get_timebase(device, 20_000) collection_time = c_int32() fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('ADC counts') res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), None, None, None, None, 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) ax.plot(list(map(lambda x: x * 1e-6, times[:])), buffer_a[:]) for threshold in ADC_THRESHOLDS: ax.plot(list(map(lambda x: x * 1e-6, times[:])), [threshold for _ in times[:]], color='red') ax.axvline(np.percentile(list(map(lambda x: x * 1e-6, times[:])), PRESAMPLE), color='red', linestyle='dotted') ps2000.ps2000_stop(device.handle) plt.show() ================================================ FILE: ps2000Examples/block_read.py ================================================ from ctypes import byref, c_byte, c_int16, c_int32, sizeof from time import sleep from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok, adc2mV from picosdk.PicoDeviceEnums import picoEnum import matplotlib.pyplot as plt SAMPLES = 2000 OVERSAMPLING = 1 def get_timebase(device, wanted_time_interval): current_timebase = 1 old_time_interval = None time_interval = c_int32(0) time_units = c_int16() max_samples = c_int32() while ps2000.ps2000_get_timebase( device.handle, current_timebase, 2000, byref(time_interval), byref(time_units), 1, byref(max_samples)) == 0 \ or time_interval.value < wanted_time_interval: current_timebase += 1 old_time_interval = time_interval.value if current_timebase.bit_length() > sizeof(c_int16) * 8: raise Exception('No appropriate timebase was identifiable') return current_timebase - 1, old_time_interval with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_A'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_500MV'], ) assert_pico2000_ok(res) res = ps2000.ps2000_set_channel( device.handle, picoEnum.PICO_CHANNEL['PICO_CHANNEL_B'], True, picoEnum.PICO_COUPLING['PICO_DC'], ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], ) assert_pico2000_ok(res) timebase_a, interval = get_timebase(device, 4_000) collection_time = c_int32() res = ps2000.ps2000_run_block( device.handle, SAMPLES, timebase_a, OVERSAMPLING, byref(collection_time) ) assert_pico2000_ok(res) while ps2000.ps2000_ready(device.handle) == 0: sleep(0.1) times = (c_int32 * SAMPLES)() buffer_a = (c_int16 * SAMPLES)() buffer_b = (c_int16 * SAMPLES)() overflow = c_byte(0) res = ps2000.ps2000_get_times_and_values( device.handle, byref(times), byref(buffer_a), byref(buffer_b), None, None, byref(overflow), 2, SAMPLES, ) assert_pico2000_ok(res) channel_a_overflow = (overflow.value & 0b0000_0001) != 0 ps2000.ps2000_stop(device.handle) channel_a_mv = adc2mV(buffer_a, ps2000.PS2000_VOLTAGE_RANGE['PS2000_500MV'], c_int16(32767)) channel_b_mv = adc2mV(buffer_b, ps2000.PS2000_VOLTAGE_RANGE['PS2000_50MV'], c_int16(32767)) fig, ax = plt.subplots() ax.set_xlabel('time/ms') ax.set_ylabel('voltage/mV') ax.plot(list(map(lambda x: x * 1e-6, times[:])), channel_a_mv[:]) ax.plot(list(map(lambda x: x * 1e-6, times[:])), channel_b_mv[:]) if channel_a_overflow: ax.text(0.01, 0.01, 'Overflow present', color='red', transform=ax.transAxes) plt.show() ================================================ FILE: ps2000Examples/device_info.py ================================================ from picosdk.ps2000 import ps2000 with ps2000.open_unit() as device: print('Device info: {}'.format(device.info)) ================================================ FILE: ps2000Examples/gen_sq_wave.py ================================================ import ctypes import numpy as np def gen_square(t, duty, low_thres): t, w = np.asarray(t), np.asarray(duty) w = np.asarray(w + (t - t)) t = np.asarray(t + (w - w)) if t.dtype.char in ['fFdD']: ytype = t.dtype.char else: ytype = 'd' y = np.zeros(t.shape, ytype) # width must be between 0 and 1 inclusive mask1 = (w > 1) | (w < 0) np.place(y, mask1, np.nan) # on the interval 0 to duty*2*pi the function is 1 tmod = np.mod(t, 2 * np.pi) mask2 = (32767-mask1)&(tmod 5_000: interval_ns /= 1000 unit += 1 return interval_ns, units[unit] class StreamingDevice: def __init__(self, gather_values, potential_range=PotentialRange.PS2000_50MV): self.device = ps2000.open_unit() self.potential_range = potential_range self.gather_values = gather_values res = ps2000.ps2000_set_channel(self.device.handle, Channel.PS2000_CHANNEL_A, True, True, potential_range) assert_pico2000_ok(res) # start 'fast-streaming' mode res = ps2000.ps2000_run_streaming_ns( self.device.handle, 500, TimeUnit.NANOSECOND, 100_000, False, 1, 50_000 ) assert_pico2000_ok(res) self.start_time = time_ns() self.end_time = time_ns() def close(self): ps2000.ps2000_stop(self.device.handle) self.device.close() def gather(self): adc_values = [] def get_overview_buffers(buffers, _overflow, _triggered_at, _triggered, _auto_stop, n_values): adc_values.extend(buffers[0][0:n_values]) callback = CALLBACK(get_overview_buffers) while len(adc_values) < self.gather_values: ps2000.ps2000_get_streaming_last_values( self.device.handle, callback ) self.end_time = time_ns() return adc_to_mv(adc_values, self.potential_range) stream = StreamingDevice(6_000_000) values = stream.gather() stream.close() print('Values gathered: {}'.format(len(values))) fig, ax = plt.subplots() interval, units = determine_time_unit(stream.end_time - stream.start_time) ax.set_xlabel('time/{}'.format(units)) ax.set_ylabel('voltage/mV') ax.plot(np.linspace(0, interval, len(values)), values) plt.show() ================================================ FILE: ps2000Examples/streaming_mode/streaming_mode_polling.py ================================================ import asyncio import concurrent.futures import functools from ctypes import POINTER, c_int16, c_uint32 from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from enum import IntEnum class Channel(IntEnum): PS2000_CHANNEL_A = 0 PS2000_CHANNEL_B = 1 class PotentialRange(IntEnum): PS2000_20MV = 1 PS2000_50MV = 2 PS2000_100MV = 3 PS2000_200MV = 4 PS2000_500MV = 5 PS2000_1V = 6 PS2000_2V = 7 PS2000_5V = 8 PS2000_10V = 9 PS2000_20V = 10 CALLBACK = C_CALLBACK_FUNCTION_FACTORY(None, POINTER(POINTER(c_int16)), c_int16, c_uint32, c_int16, c_int16, c_uint32) # reimplement this because the other one only takes ctypes def adc_to_mv(values, range_, bitness=16): v_ranges = [10, 20, 50, 100, 200, 500, 1_000, 2_000, 5_000, 10_000, 20_000] return [(x * v_ranges[range_]) / (2**(bitness - 1) - 1) for x in values] class StreamingDevice: def __init__(self, potential_range=PotentialRange.PS2000_50MV): self.device = ps2000.open_unit() self.potential_range = potential_range # create an event loop self.loop = asyncio.new_event_loop() # create a thread-pool executor self.executor = concurrent.futures.ThreadPoolExecutor() self.waiting_blocks = {} res = ps2000.ps2000_set_channel(self.device.handle, Channel.PS2000_CHANNEL_A, True, True, potential_range) assert_pico2000_ok(res) # start 'fast-streaming' mode res = ps2000.ps2000_run_streaming_ns( self.device.handle, 100, 3, 30_000, False, 1, 15_000 ) assert_pico2000_ok(res) async def process_value(self, mv_value): # overload pass def get_streamed_values(self, block_id): def get_overview_buffers(buffers, _overflow, _triggered_at, _triggered, _auto_stop, n_values): adc_values = buffers[0][0:n_values] mv_values = adc_to_mv(adc_values, self.potential_range) self.waiting_blocks[block_id] = mv_values callback = CALLBACK(get_overview_buffers) res = ps2000.ps2000_get_streaming_last_values( self.device.handle, callback ) assert_pico2000_ok(res) def start(self): async def gather_values(): block_id = 0 while True: await asyncio.sleep(0.5) await self.loop.run_in_executor(self.executor, functools.partial(self.get_streamed_values, block_id)) block_id += 1 async def poll_waiting(): next_block = 0 while True: if block := self.waiting_blocks.get(next_block): next_block += 1 for n in block: await self.process_value(n) await asyncio.sleep(0.25) try: self.loop.create_task(gather_values()) self.loop.run_until_complete(poll_waiting()) finally: self.loop.close() ps2000.ps2000_stop(self.device.handle) ps2000.ps2000_close(self.device.handle) stream = StreamingDevice() stream.start() ================================================ FILE: ps2000Examples/streaming_mode/streaming_mode_threaded.py ================================================ from ctypes import POINTER, c_int16, c_uint32 from picosdk.ps2000 import ps2000 from picosdk.functions import assert_pico2000_ok from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY from enum import IntEnum from concurrent.futures import ThreadPoolExecutor import functools import time import os CALLBACK = C_CALLBACK_FUNCTION_FACTORY(None, POINTER(POINTER(c_int16)), c_int16, c_uint32, c_int16, c_int16, c_uint32) THREADPOOL = ThreadPoolExecutor() past_mv_values = [] term_width = os.get_terminal_size() def process_values(adc_values): mv_values = adc_to_mv(adc_values, PotentialRange.PS2000_50MV) for value in mv_values: pre = (value + 500) / 500 * term_width print('{}|'.format(' ' * pre)) past_mv_values.extend(mv_values) def get_overview_buffers(buffers, _overflow, _triggered_at, _triggered, _auto_stop, n_values): adc_values = buffers[0][0:n_values] THREADPOOL.submit(functools.partial(process_values, adc_values)) callback = CALLBACK(get_overview_buffers) def adc_to_mv(values, range_, bitness=16): v_ranges = [10, 20, 50, 100, 200, 500, 1_000, 2_000, 5_000, 10_000, 20_000] return [(x * v_ranges[range_]) / (2**(bitness - 1) - 1) for x in values] class Channel(IntEnum): PS2000_CHANNEL_A = 0 PS2000_CHANNEL_B = 1 class PotentialRange(IntEnum): PS2000_20MV = 1 PS2000_50MV = 2 PS2000_100MV = 3 PS2000_200MV = 4 PS2000_500MV = 5 PS2000_1V = 6 PS2000_2V = 7 PS2000_5V = 8 PS2000_10V = 9 PS2000_20V = 10 with ps2000.open_unit() as device: res = ps2000.ps2000_set_channel(device.handle, Channel.PS2000_CHANNEL_A, True, True, PotentialRange.PS2000_50MV) assert_pico2000_ok(res) res = ps2000.ps2000_run_streaming_ns( device.handle, 500, 2, 100_000, False, 1, 50_000 ) assert_pico2000_ok(res) target_samples = 1_000_000 while True: ps2000.ps2000_get_streaming_last_values( device.handle, callback ) time.sleep(0.01) ================================================ FILE: ps2000aExamples/ps2000aBlockAdvancedEdgeExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS2000A BLOCK MODE EXAMPLE # This example opens a 2000a 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.ps2000a import ps2000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 2000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = PS2000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V chARange = 7 status["setChA"] = ps.ps2000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS2000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V chBRange = 7 status["setChB"] = ps.ps2000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up advanced edge trigger adcTriggerLevel = mV2adc(500, chARange, maxADC) hysteresisPercentage = 0.05 conditions = ps.PS2000A_TRIGGER_CONDITION(ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_TRUE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"], ps.PS2000A_TRIGGER_STATE["PS2000A_CONDITION_DONT_CARE"]) status["setConditions"] = ps.ps2000aSetTriggerChannelConditions(chandle, ctypes.byref(conditions), 1) assert_pico_ok(status["setConditions"]) properties = ps.PS2000A_TRIGGER_CHANNEL_PROPERTIES(adcTriggerLevel, (adcTriggerLevel * hysteresisPercentage), (adcTriggerLevel * -1), (adcTriggerLevel * hysteresisPercentage), ps.PS2000A_CHANNEL["PS2000A_CHANNEL_A"], ps.PS2000A_THRESHOLD_MODE["PS2000A_LEVEL"]) status["setProperties"] = ps.ps2000aSetTriggerChannelProperties(chandle, ctypes.byref(properties),1,0,1000) assert_pico_ok(status["setProperties"]) status["setDirections"] = ps.ps2000aSetTriggerChannelDirections(chandle, ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_RISING"], ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_NONE"], ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_NONE"], ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_NONE"], ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_NONE"], ps.PS2000A_THRESHOLD_DIRECTION["PS2000A_NONE"]) assert_pico_ok(status["setDirections"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = totalSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # pointer to totalSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(0) status["getTimebase2"] = ps.ps2000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # oversample = 0 = oversample # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps2000aIsReady rather than ps2000aBlockReady) # pParameter = None status["runBlock"] = ps.ps2000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps2000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps2000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * totalSamples)() bufferAMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * totalSamples)() bufferBMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS2000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferDPort0Max) # pointer to buffer min = ctypes.byref(bufferDPort0Min) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), totalSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS2000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps2000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), totalSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # Create overflow location overflow = ctypes.c_int16() # create converted type totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cTotalSamples) # downsample ratio = 0 # downsample ratio mode = PS2000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps2000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, ((cTotalSamples.value)-1) * timeIntervalns.value, cTotalSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps2000aExamples/ps2000aBlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS2000A BLOCK MODE EXAMPLE # This example opens a 2000a 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.ps2000a import ps2000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 2000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = PS2000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V chARange = 7 status["setChA"] = ps.ps2000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS2000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V chBRange = 7 status["setChB"] = ps.ps2000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up single trigger # handle = chandle # enabled = 1 # source = PS2000A_CHANNEL_A = 0 # threshold = 1024 ADC counts # direction = PS2000A_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps2000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = totalSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # pointer to totalSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(0) status["getTimebase2"] = ps.ps2000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # oversample = 0 = oversample # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps2000aIsReady rather than ps2000aBlockReady) # pParameter = None status["runBlock"] = ps.ps2000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps2000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps2000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * totalSamples)() bufferAMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * totalSamples)() bufferBMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS2000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferDPort0Max) # pointer to buffer min = ctypes.byref(bufferDPort0Min) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), totalSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS2000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps2000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), totalSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # Create overflow location overflow = ctypes.c_int16() # create converted type totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cTotalSamples) # downsample ratio = 0 # downsample ratio mode = PS2000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps2000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, ((cTotalSamples.value)-1) * timeIntervalns.value, cTotalSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps2000aExamples/ps2000aBlockExampleCallbackMethod.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS2000A BLOCK MODE EXAMPLE # This example opens a 2000a 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.ps2000a import ps2000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 2000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = PS2000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V chARange = 7 status["setChA"] = ps.ps2000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS2000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V chBRange = 7 status["setChB"] = ps.ps2000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up single trigger # handle = chandle # enabled = 1 # source = PS2000A_CHANNEL_A = 0 # threshold = 1024 ADC counts # direction = PS2000A_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps2000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = totalSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # pointer to totalSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(0) status["getTimebase2"] = ps.ps2000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) wasCalledBack = False def blockready_callback(handle, statusCode, param): global wasCalledBack wasCalledBack = True cFuncPtr = ps.BlockReadyType(blockready_callback) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # oversample = 0 = oversample # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps2000aIsReady rather than ps2000aBlockReady) # pParameter = None status["runBlock"] = ps.ps2000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, cFuncPtr, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish and callback while wasCalledBack == False: time.sleep(0.01) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * totalSamples)() bufferAMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * totalSamples)() bufferBMin = (ctypes.c_int16 * totalSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS2000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferDPort0Max) # pointer to buffer min = ctypes.byref(bufferDPort0Min) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), totalSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS2000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps2000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), totalSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # Create overflow location overflow = ctypes.c_int16() # create converted type totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cTotalSamples) # downsample ratio = 0 # downsample ratio mode = PS2000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps2000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, ((cTotalSamples.value)-1) * timeIntervalns.value, cTotalSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps2000aExamples/ps2000aMSOBlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 2000 Series (A API) MSO Block Mode Example # This example demonstrates how to use the PicoScope 2000 Series (ps2000a) driver API functions in order to do the # following: # # Open a connection to a PicoScope 2000 Series MSO device # Setup input analog channels and a digital port # Setup a trigger on a digital channel # Collect a block of data # Plot data import ctypes import numpy as np from picosdk.ps2000a import ps2000a as ps, PS2000A_TRIGGER_CONDITIONS, PS2000A_DIGITAL_CHANNEL_DIRECTIONS import matplotlib.pyplot as plt from picosdk.functions import adc2mV, splitMSODataFast, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open a connection to a PicoScope 2000 Series device # Returns handle to chandle for use in future API functions status["openUnit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openUnit"]) # Set up channel A # handle = chandle # channel = PS2000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V channelA = ps.PS2000A_CHANNEL['PS2000A_CHANNEL_A'] chAEnabled = 1 chACoupling = ps.PS2000A_COUPLING['PS2000A_DC'] chARange = ps.PS2000A_RANGE['PS2000A_2V'] chAAnalogOffset = 0 status["setChA"] = ps.ps2000aSetChannel(chandle, channelA, chAEnabled, chACoupling, chARange, chAAnalogOffset) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS2000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V channelB = ps.PS2000A_CHANNEL['PS2000A_CHANNEL_B'] chBEnabled = 1 chBCoupling = ps.PS2000A_COUPLING['PS2000A_DC'] chBRange = ps.PS2000A_RANGE['PS2000A_2V'] chBAnalogOffset = 0 status["setChB"] = ps.ps2000aSetChannel(chandle, channelB, chBEnabled, chBCoupling, chBRange, chBAnalogOffset) assert_pico_ok(status["setChB"]) # Set Digital Port 0 # handle = chandle # port = PS2000A_DIGITAL_PORT0 = 0x80 # enabled = 1 # logicLevel = 9754 (1.5 V) dPort0 = ps.PS2000A_DIGITAL_PORT.get("PS2000A_DIGITAL_PORT0") status["setDigitalPort0"] = ps.ps2000aSetDigitalPort(chandle, dPort0, 1, 9754) assert_pico_ok(status["setDigitalPort0"]) # Set up trigger on digital channel # Device will trigger when there is a transition from low to high on digital channel 0 # Set trigger conditions # handle = chandle # Trigger conditions: # channelA = PS2000A_CONDITION_DONT_CARE = 0 # channelB = PS2000A_CONDITION_DONT_CARE = 0 # channelC = PS2000A_CONDITION_DONT_CARE = 0 # channelD = PS2000A_CONDITION_DONT_CARE = 0 # external = PS2000A_CONDITION_DONT_CARE = 0 # aux = PS2000A_CONDITION_DONT_CARE = 0 # pulseWidthQualifier = PS2000A_CONDITION_DONT_CARE = 0 # digital = PS2000A_CONDITION_TRUE = 1 # nConditions = 1 dont_care = ps.PS2000A_TRIGGER_STATE['PS2000A_CONDITION_DONT_CARE'] trigger_true = ps.PS2000A_TRIGGER_STATE['PS2000A_CONDITION_TRUE'] nConditions = 1 triggerConditions = PS2000A_TRIGGER_CONDITIONS(dont_care, dont_care, dont_care, dont_care, dont_care, dont_care, dont_care, trigger_true) status["setTriggerChannelConditions"] = ps.ps2000aSetTriggerChannelConditions(chandle, ctypes.byref(triggerConditions), nConditions) assert_pico_ok(status["setTriggerChannelConditions"]) # Set digital trigger directions # handle = chandle # Digital directions # channel = PS2000A_DIGITAL_CHANNEL_0 = 0 # direction = PS2000A_DIGITAL_DIRECTION_RISING = 3 # nDirections = 1 digitalChannel = ps.PS2000A_DIGITAL_CHANNEL['PS2000A_DIGITAL_CHANNEL_0'] digiTriggerDirection = ps.PS2000A_DIGITAL_DIRECTION['PS2000A_DIGITAL_DIRECTION_RISING'] digitalDirections = PS2000A_DIGITAL_CHANNEL_DIRECTIONS(digitalChannel, digiTriggerDirection) nDigitalDirections = 1 status["setTriggerDigitalPortProperties"] = ps.ps2000aSetTriggerDigitalPortProperties(chandle, ctypes.byref(digitalDirections), nDigitalDirections) assert_pico_ok(status["setTriggerDigitalPortProperties"]) # Set number of pre- and post-trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 1252 = 10000 ns = timebase (see Programmer's guide for more information on timebases) # noSamples = totalSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # pointer to totalSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 1252 timeIntervalNs = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(0) # Query this function in a loop in case the timebase index selected is invalid. status["getTimebase2"] = ps.PICO_STATUS['PICO_INVALID_TIMEBASE'] while status["getTimebase2"] == ps.PICO_STATUS['PICO_INVALID_TIMEBASE']: status["getTimebase2"] = ps.ps2000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalNs), oversample, ctypes.byref(returnedMaxSamples), 0) if status["getTimebase2"] == ps.PICO_STATUS['PICO_OK']: break else: timebase = timebase + 1 assert_pico_ok(status["getTimebase2"]) print "Starting data collection - waiting for trigger on channel D0..." # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 1252 = 10000 ns = timebase (see Programmer's guide for mre information on timebases) # oversample = 0 # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps2000aIsReady() rather than ps2000aBlockReady()) # pParameter = None status["runBlock"] = ps.ps2000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps2000aIsReady() ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps2000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferA = (ctypes.c_int16 * totalSamples)() bufferB = (ctypes.c_int16 * totalSamples)() bufferDPort0 = (ctypes.c_int16 * totalSamples)() ratio_mode_none = ps.PS2000A_RATIO_MODE['PS2000A_RATIO_MODE_NONE'] # Set data buffer location for data collection from channel A # handle = chandle # source = PS2000A_CHANNEL_A = 0 # pointer to buffer = ctypes.byref(bufferA) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBufferA"] = ps.ps2000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA), totalSamples, 0, ratio_mode_none) assert_pico_ok(status["setDataBufferA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS2000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferB) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBufferB"] = ps.ps2000aSetDataBuffer(chandle, channelB, ctypes.byref(bufferB), totalSamples, 0, ratio_mode_none) assert_pico_ok(status["setDataBufferB"]) # Set data buffer location for data collection from digital port 0 # handle = chandle # source = PS2000A_DIGITAL_PORT0 = 0x80 # pointer to buffer max = ctypes.byref(bufferB) # buffer length = totalSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBufferDPort0"] = ps.ps2000aSetDataBuffer(chandle, dPort0, ctypes.byref(bufferDPort0), totalSamples, 0, ratio_mode_none) assert_pico_ok(status["setDataBufferDPort0"]) # create overflow location overflow = ctypes.c_int16() # create converted type totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cTotalSamples) # downsample ratio = 1 # downsample ratio mode = PS2000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps2000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 0, 1, ratio_mode_none, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) print "Data collection complete." # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Convert ADC counts data to millivolts adc2mVChA = adc2mV(bufferA, chARange, maxADC) adc2mVChB = adc2mV(bufferB, chBRange, maxADC) # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). dPort0BinaryData = splitMSODataFast(cTotalSamples, bufferDPort0) # Create time data time = np.linspace(0, (cTotalSamples.value - 1) * timeIntervalNs.value, cTotalSamples.value) # Plot data from channels A, B and D0 print "Plotting data..." fig, axs = plt.subplots(2, 1, constrained_layout=True) axs[0].plot(time, adc2mVChA[:], time, adc2mVChB[:]) axs[0].set_title('Analog data acquisition') axs[0].set_xlabel('Time (ns)') axs[0].set_ylabel('Voltage (mV)') axs[0].legend(('Ch. A', 'Ch. B'), loc="upper right") axs[1].plot(time, dPort0BinaryData[7], label='D0') # D0 is the last array in the tuple. axs[1].set_title('Digital data acquisition') axs[1].set_xlabel('Time (ns)') axs[1].set_ylabel('Logic Level') axs[1].legend(loc="upper right") fig.canvas.set_window_title('PicoScope 2000 Series (A API) MSO Block Capture Example') plt.show() print "Close figure to stop the device and close the connection." # Stop the scope # handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Close the connection to the device # handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps2000aExamples/ps2000aRapidBlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # ps2000a RAPID BLOCK MODE EXAMPLE # This example opens a 3000a driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps2000a import ps2000a as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = ps2000a_CHANNEL_A = 0 # enabled = 1 # coupling type = ps2000a_DC = 1 # range = ps2000a_10V = 9 # analogue offset = 0 V chARange = 9 status["setChA"] = ps.ps2000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Sets up single trigger # andle = chandle # Enable = 1 # Source = ps2000a_channel_A = 0 # Threshold = 1024 ADC counts # Direction = ps2000a_Falling = 3 # Delay = 0 # autoTrigger_ms = 1000 status["trigger"] = ps.ps2000aSetSimpleTrigger(chandle, 1, 0, 1024, 3, 0, 1000) assert_pico_ok(status["trigger"]) # Setting the number of sample to be collected preTriggerSamples = 400 postTriggerSamples = 400 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # Timebase = 2 = timebase # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 2 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps2000aGetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Handle = Chandle # nSegments = 10 # nMaxSamples = ctypes.byref(cmaxSamples) status["MemorySegments"] = ps.ps2000aMemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) assert_pico_ok(status["MemorySegments"]) # sets number of captures status["SetNoOfCaptures"] = ps.ps2000aSetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # Starts the block capture # handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps2000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax1 = (ctypes.c_int16 * maxsamples)() bufferAMin1 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 1 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax2 = (ctypes.c_int16 * maxsamples)() bufferAMin2 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 2 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax3 = (ctypes.c_int16 * maxsamples)() bufferAMin3 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 3 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax4 = (ctypes.c_int16 * maxsamples)() bufferAMin4 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 4 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax5 = (ctypes.c_int16 * maxsamples)() bufferAMin5 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 5 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax6 = (ctypes.c_int16 * maxsamples)() bufferAMin6 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 6 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax7 = (ctypes.c_int16 * maxsamples)() bufferAMin7 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 7 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax8 = (ctypes.c_int16 * maxsamples)() bufferAMin8 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 8 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax9 = (ctypes.c_int16 * maxsamples)() bufferAMin9 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # handle = chandle # source = ps2000a_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 9 # Ratio mode = ps2000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps2000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9, 0) assert_pico_ok(status["SetDataBuffers"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps2000aIsReady(chandle, ctypes.byref(ready)) # handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps2000aGetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int16*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps2000aGetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Finds the max ADC count # handle = chandle # Value = ctype.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status) ================================================ FILE: ps2000aExamples/ps2000aSigGen.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 2000 (A API) Series Signal Generator Example # This example demonstrates how to use the PicoScope 2000 Series (ps2000a) 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.ps2000a import ps2000a as ps import time from picosdk.functions import assert_pico_ok import numpy as np import math # Gives the device a handle status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) 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.ps2000aChangePowerSource(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.ps2000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Output a sine wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(0) = PS2000A_SINE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS2000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS2000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS2000A_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(0) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps2000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS2000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS2000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS2000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS2000A_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps2000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # pauses the script to show signal time.sleep(10) # Output square wave with an up-down sweep, ranging from 10-100 kHz in 5 kHz increments every 1 second. # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS2000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 100 kHz # increment = 5 kHz # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS2000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS2000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS2000A_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(2) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps2000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 100000, 5000, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(36) #max and min values and lengths minValue = ctypes.c_int16(0) maxValue = ctypes.c_int16(0) minSize = ctypes.c_int16(0) maxSize = ctypes.c_int16(0) status["sigGenArbMinMaxValues"] = ps.ps2000aSigGenArbitraryMinMaxValues(chandle, ctypes.byref(minValue), ctypes.byref(maxValue), ctypes.byref(minSize),ctypes.byref(maxSize)) assert_pico_ok(status["sigGenArbMinMaxValues"]) a=maxValue # create a custom waveform awgBuffer = np.sin(np.linspace(0,2*math.pi,1024)) awgbufferPointer = awgBuffer.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)) phase = ctypes.c_uint32(0) status["freq2phase"] = ps.ps2000aSigGenFrequencyToPhase(chandle, 100, 0, 1024, ctypes.byref(phase)) assert_pico_ok(status["freq2phase"]) # output custom waveform with peak-to-peak of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # startDeltaPhase = phase # stopDeltaPhase = phase # deltaPhaseIncrement = 0 # dwellCount = 0 # *arbitaryWaveform = awgbufferPointer # arbitaryWaveformSize = 1024 # sweepType = ctypes.c_int32(1) = PS5000A_UP # operation = 0 # indexMode = 0 = PS2000A_SINGLE # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS5000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS5000A_SIGGEN_NONE # extInThreshold = 0 status["setSigGenArbitrary"] = ps.ps2000aSetSigGenArbitrary(chandle, 0, 2000000, phase, phase, 0, 0, awgbufferPointer, 1024, 0, 0, 0, 0, 0, 0, 0, 0) assert_pico_ok(status["setSigGenArbitrary"]) # Pauses the script to show signal time.sleep(36) # output a custom binary sequence from the AWG # create a binary buffer for AWG # this buffer can be replaced with whatever binary sequence is wanted to be outputted # any 1s should use the a variable which is equal to the maximum value for the awg buffer binaryBuffer = [0,a,a,a,0,0,a,a,0,0,0,0,a,a,a,a,a,a,a,a,0,0,a,a,0] cBinaryBuffer = (ctypes.c_int16*len(binaryBuffer))(*binaryBuffer) binarybufferPointer = ctypes.byref(cBinaryBuffer) phase2 = ctypes.c_uint32(0) # get the phase for 100 kHz status["freq2phase"] = ps.ps2000aSigGenFrequencyToPhase(chandle, 100, 0, len(cBinaryBuffer), ctypes.byref(phase2)) assert_pico_ok(status["freq2phase"]) # output custom waveform with peak-to-peak of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # startDeltaPhase = phase2 # stopDeltaPhase = phase2 # deltaPhaseIncrement = 0 # dwellCount = 0 # *arbitaryWaveform = binarybufferPointer # arbitaryWaveformSize = len(binarybufferPointer) # sweepType = ctypes.c_int32(1) = PS5000A_UP # operation = 0 # indexMode = 0 = PS2000A_SINGLE # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS5000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS5000A_SIGGEN_NONE # extInThreshold = 0 status["setSigGenArbitrary"] = ps.ps2000aSetSigGenArbitrary(chandle, 0, 2000000, phase2, phase2, 0, 0, binarybufferPointer, len(cBinaryBuffer), 0, 0, 0, 0, 0, 0, 0, 0) assert_pico_ok(status["setSigGenArbitrary"]) # Pauses the script to show signal time.sleep(36) # Closes the unit # Handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the status returns print(status) ================================================ FILE: ps2000aExamples/ps2000aStreamingExample.py ================================================ # # Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms. # # PS2000 Series (A API) STREAMING MODE EXAMPLE # This example demonstrates how to call the ps2000a driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps2000a import ps2000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 2000 Series device # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) enabled = 1 disabled = 0 analogue_offset = 0.0 # Set up channel A # handle = chandle # channel = PS2000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V channel_range = ps.PS2000A_RANGE['PS2000A_2V'] status["setChA"] = ps.ps2000aSetChannel(chandle, ps.PS2000A_CHANNEL['PS2000A_CHANNEL_A'], enabled, ps.PS2000A_COUPLING['PS2000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS2000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS2000A_DC = 1 # range = PS2000A_2V = 7 # analogue offset = 0 V status["setChB"] = ps.ps2000aSetChannel(chandle, ps.PS2000A_CHANNEL['PS2000A_CHANNEL_B'], enabled, ps.PS2000A_COUPLING['PS2000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 500 numBuffersToCapture = 10 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) memory_segment = 0 # Set data buffer location for data collection from channel A # handle = chandle # source = PS2000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps2000aSetDataBuffers(chandle, ps.PS2000A_CHANNEL['PS2000A_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS2000A_RATIO_MODE['PS2000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS2000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS2000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps2000aSetDataBuffers(chandle, ps.PS2000A_CHANNEL['PS2000A_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS2000A_RATIO_MODE['PS2000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(250) sampleUnits = ps.PS2000A_TIME_UNITS['PS2000A_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps2000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, ps.PS2000A_RATIO_MODE['PS2000A_RATIO_MODE_NONE'], sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps2000aGetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps2000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples-1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps3000EExamples/ps3000EBlockExample.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # # PSOSPA BLOCK MODE EXAMPLE # This example opens a psospa 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.psospa import psospa as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as structs # from picosdk.PicoConnectProbes import picoConnectProbes as probes import matplotlib.pyplot as plt from picosdk.functions import adc2mVV2, mV2adcV2, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open a psospa driver device # returns handle for future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openUnit"] = ps.psospaOpenUnit(ctypes.byref(chandle), None, resolution, None) assert_pico_ok(status["openUnit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC"] rangeMax = 2000000000 #nV rangeMin = -rangeMax #nV rangeType = 0 #probes.PICO_PROBE_RANGE_INFO["PICO_PROBE_NONE_NV"] analogueOffset = 0 bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.psospaSetChannelOn(chandle, channelA, coupling, rangeMin, rangeMax, rangeType, analogueOffset, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 3, 1): channel = x status["setChannel",x] = ps.psospaSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.psospaGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.psospaSetSimpleTrigger(chandle, 1, source, mV2adcV2(100,rangeMax,maxADC), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.psospaGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.psospaRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using psospaIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.psospaIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.psospaGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # # convert ADC counts data to mV adc2mVChAMax = adc2mVV2(bufferAMax, rangeMax, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, bufferAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the psospa driver device status["closeUnit"] = ps.psospaCloseUnit(chandle) assert_pico_ok(status["closeUnit"]) print(status) ================================================ FILE: ps3000EExamples/ps3000ERapidBlockExample.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # # PSOSPA RAPID BLOCK MODE EXAMPLE # This example opens a psospa driver device, sets up two channels and a trigger then collects 10 blocks of data in rapid block mode. # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.psospa import psospa as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as structs # from picosdk.PicoConnectProbes import picoConnectProbes as probes import matplotlib.pyplot as plt from picosdk.functions import adc2mVV2, assert_pico_ok, mV2adcV2 # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open a psospa driver device # returns handle for future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openUnit"] = ps.psospaOpenUnit(ctypes.byref(chandle), None, resolution, None) assert_pico_ok(status["openUnit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC"] rangeMax = 2000000000 #nV rangeMin = -rangeMax #nV rangeType = 0 #probes.PICO_PROBE_RANGE_INFO["PICO_PROBE_NONE_NV"] analogueOffset = 0 bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.psospaSetChannelOn(chandle, channelA, coupling, rangeMin, rangeMax, rangeType, analogueOffset, bandwidth) assert_pico_ok(status["setChannelA"]) for x in range (1, 3, 1): channel = x status["setChannel",x] = ps.psospaSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.psospaGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.psospaSetSimpleTrigger(chandle, 1, source, mV2adcV2(100,rangeMax,maxADC), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.psospaGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = (noOfPostTriggerSamples + noOfPreTriggerSamples) # Set number of memory segments noOfCaptures = 20 maxSegments = ctypes.c_uint64(10) status["memorySegments"] = ps.psospaMemorySegments(chandle, noOfCaptures, ctypes.byref(maxSegments)) assert_pico_ok(status["memorySegments"]) # Set number of captures status["setNoOfCaptures"] = ps.psospaSetNoOfCaptures(chandle, noOfCaptures) assert_pico_ok(status["setNoOfCaptures"]) # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax1 = (ctypes.c_int16 * nSamples)() bufferAMin1 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax2 = (ctypes.c_int16 * nSamples)() bufferAMin2 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax3 = (ctypes.c_int16 * nSamples)() bufferAMin3 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax4 = (ctypes.c_int16 * nSamples)() bufferAMin4 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax5 = (ctypes.c_int16 * nSamples)() bufferAMin5 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax6 = (ctypes.c_int16 * nSamples)() bufferAMin6 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax7 = (ctypes.c_int16 * nSamples)() bufferAMin7 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax8 = (ctypes.c_int16 * nSamples)() bufferAMin8 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax9 = (ctypes.c_int16 * nSamples)() bufferAMin9 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) waveform1 = 1 status["setDataBuffers1"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), nSamples, dataType, waveform1, downSampleMode, add) assert_pico_ok(status["setDataBuffers1"]) waveform2 = 2 status["setDataBuffers2"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), nSamples, dataType, waveform2, downSampleMode, add) assert_pico_ok(status["setDataBuffers2"]) waveform3 = 3 status["setDataBuffers3"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), nSamples, dataType, waveform3, downSampleMode, add) assert_pico_ok(status["setDataBuffers3"]) waveform4 = 4 status["setDataBuffers4"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), nSamples, dataType, waveform4, downSampleMode, add) assert_pico_ok(status["setDataBuffers4"]) waveform5 = 5 status["setDataBuffers5"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), nSamples, dataType, waveform5, downSampleMode, add) assert_pico_ok(status["setDataBuffers5"]) waveform6 = 6 status["setDataBuffers6"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), nSamples, dataType, waveform6, downSampleMode, add) assert_pico_ok(status["setDataBuffers6"]) waveform7 = 7 status["setDataBuffers7"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), nSamples, dataType, waveform7, downSampleMode, add) assert_pico_ok(status["setDataBuffers7"]) waveform8 = 8 status["setDataBuffers8"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), nSamples, dataType, waveform8, downSampleMode, add) assert_pico_ok(status["setDataBuffers8"]) waveform9 = 9 status["setDataBuffers9"] = ps.psospaSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), nSamples, dataType, waveform9, downSampleMode, add) assert_pico_ok(status["setDataBuffers9"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.psospaRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using psospaIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.psospaIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 # Creates a overflow location for each segment overflow = (ctypes.c_int16 * 10)() status["getValues"] = ps.psospaGetValuesBulk(chandle, 0, ctypes.byref(noOfSamples),0, 9, 1, downSampleMode, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mVV2(bufferAMax, rangeMax, maxADC) adc2mVChAMax1 = adc2mVV2(bufferAMax1, rangeMax, maxADC) adc2mVChAMax2 = adc2mVV2(bufferAMax2, rangeMax, maxADC) adc2mVChAMax3 = adc2mVV2(bufferAMax3, rangeMax, maxADC) adc2mVChAMax4 = adc2mVV2(bufferAMax4, rangeMax, maxADC) adc2mVChAMax5 = adc2mVV2(bufferAMax5, rangeMax, maxADC) adc2mVChAMax6 = adc2mVV2(bufferAMax6, rangeMax, maxADC) adc2mVChAMax7 = adc2mVV2(bufferAMax7, rangeMax, maxADC) adc2mVChAMax8 = adc2mVV2(bufferAMax8, rangeMax, maxADC) adc2mVChAMax9 = adc2mVV2(bufferAMax9, rangeMax, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.psospaCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps3000EExamples/ps3000EStreamingModeExample.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # # PSOSPA STREAMING MODE EXAMPLE # This example opens a psospa driver device, sets up two channels then collects a streamed set of data. # The data from channel A is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.psospa import psospa as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as structs import matplotlib.pyplot as plt from picosdk.functions import adc2mVV2, assert_pico_ok, mV2adcV2 from picosdk.constants import PICO_STATUS import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open a psospa driver device # returns handle for future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openUnit"] = ps.psospaOpenUnit(ctypes.byref(chandle), None, resolution, None) assert_pico_ok(status["openUnit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC"] rangeMax = 2000000000 #nV rangeMin = -rangeMax #nV rangeType = 0 #probes.PICO_PROBE_RANGE_INFO["PICO_PROBE_NONE_NV"] analogueOffset = 0 bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.psospaSetChannelOn(chandle, channelA, coupling, rangeMin, rangeMax, rangeType, analogueOffset, bandwidth) assert_pico_ok(status["setChannelA"]) channelB = enums.PICO_CHANNEL["PICO_CHANNEL_B"] status["setChannelB"] = ps.psospaSetChannelOn(chandle, channelB, coupling, rangeMin, rangeMax, rangeType, analogueOffset, bandwidth) assert_pico_ok(status["setChannelB"]) # set channel C-D off for x in range(2, 3, 1): channel = x status["setChannel", x] = ps.psospaSetChannelOff(chandle, channel) assert_pico_ok(status["setChannel", x]) # Set number of samples to be collected noOfPreTriggerSamples = 100000 noOfPostTriggerSamples = 900000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.psospaGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.psospaSetSimpleTrigger(chandle, 1, source, (mV2adcV2(100,rangeMax,maxADC)), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # create buffers maxBuffers = 10 bufferA = ((ctypes.c_int16 * nSamples) * 10)() bufferB = ((ctypes.c_int16 * nSamples) * 10)() # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear | add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] actionAdd = add status["setDataBuffersA"] = ps.psospaSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[0]), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffersA"]) status["setDataBuffersB"] = ps.psospaSetDataBuffer(chandle, channelB, ctypes.byref(bufferB[0]), nSamples, dataType, waveform, downSampleMode, actionAdd) assert_pico_ok(status["setDataBuffersB"]) # Run streaming sampleInterval = ctypes.c_double(1) sampleIntervalTimeUnits = enums.PICO_TIME_UNITS["PICO_US"] autoStop = 0 downSampleRatio = 1 status["runStreaming"] = ps.psospaRunStreaming(chandle, ctypes.byref(sampleInterval), sampleIntervalTimeUnits, noOfPreTriggerSamples, noOfPostTriggerSamples, autoStop, downSampleRatio, downSampleMode) assert_pico_ok(status["runStreaming"]) streamData = (structs.PICO_STREAMING_DATA_INFO * 2)() streamData[0] = structs.PICO_STREAMING_DATA_INFO(channelA, downSampleMode, dataType, 0, 0, 0, 0) streamData[1] = structs.PICO_STREAMING_DATA_INFO(channelB, downSampleMode, dataType, 0, 0, 0, 0) streamTrigger = structs.PICO_STREAMING_DATA_TRIGGER_INFO(0, 0, 0) count = 0 picoOk = PICO_STATUS["PICO_OK"] collectedSamples = 0 while collectedSamples < (maxBuffers*nSamples): status["getStreamingLatestValues"] = ps.psospaGetStreamingLatestValues(chandle, ctypes.byref(streamData), 1, ctypes.byref(streamTrigger)) if status["getStreamingLatestValues"] == picoOk: # do nothing time.sleep(0.01) else: count = count + 1 if count < maxBuffers: status["setDataBufferA"] = ps.psospaSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[count]), nSamples, dataType, waveform, downSampleMode, actionAdd) assert_pico_ok(status["setDataBufferA"]) status["setDataBufferB"] = ps.psospaSetDataBuffer(chandle, channelB, ctypes.byref(bufferB[count]), nSamples, dataType, waveform, downSampleMode, actionAdd) assert_pico_ok(status["setDataBufferB"]) print(count) collectedSamples = collectedSamples + streamData[0].noOfSamples # stop scope streaming status["stop"] = ps.psospaStop(chandle) assert_pico_ok(status["stop"]) # get total number of streamed data points noOfStreamedSamples=ctypes.c_uint64() status["noOfStreamedSamples"] = ps.psospaNoOfStreamingValues(chandle, ctypes.byref(noOfStreamedSamples)) assert_pico_ok(status["noOfStreamedSamples"]) print("streaming finished") print("Number of samples collected during streaming") print(noOfStreamedSamples.value) # convert ADC counts data to mV bufferAmV = [] for k in range (0, maxBuffers, 1): mvValues = adc2mVV2(bufferA[k], rangeMax, maxADC) bufferAmV.append(mvValues) time = np.linspace(0, ((nSamples -1)*maxBuffers) * sampleInterval.value * 1000000, (nSamples*maxBuffers)) startTime = 0 endTime = nSamples # plot data for h in range (0, maxBuffers, 1): plt.plot(time[startTime:endTime],bufferAmV[h]) startTime += nSamples endTime += nSamples plt.xlabel('Time (us)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.psospaCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps3000aExamples/ps3000aBlockAdvancedTriggerExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS3000A BLOCK MODE EXAMPLE # This example opens a 3000a driver device, sets up one channels and a trigger then collects a block of data. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps3000a import ps3000a as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, mV2adc, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps3000aOpenUnit(ctypes.byref(chandle), None) 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.ps3000aChangePowerSource(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.ps3000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Set up channel A # handle = chandle # channel = PS3000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS3000A_DC = 1 # range = PS3000A_5V = 8 # analogue offset = 0 V chARange = 8 status["setChA"] = ps.ps3000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Finds the max ADC count # Handle = chandle # Value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps3000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Set an advanced trigger adcTriggerLevel = mV2adc(500, chARange, maxADC) # set trigger channel properties # handle = chandle channelProperties = ps.PS3000A_TRIGGER_CHANNEL_PROPERTIES(adcTriggerLevel, 10, adcTriggerLevel, 10, ps.PS3000A_CHANNEL["PS3000A_CHANNEL_A"], ps.PS3000A_THRESHOLD_MODE["PS3000A_LEVEL"]) nChannelProperties = 1 # auxOutputEnabled = 0 autoTriggerMilliseconds = 10000 status["setTrigProp"] = ps.ps3000aSetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, 0, autoTriggerMilliseconds) assert_pico_ok(status["setTrigProp"]) # set trigger conditions V2 # chandle = handle conditions = ps.PS3000A_TRIGGER_CONDITIONS_V2(ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_TRUE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"], ps.PS3000A_TRIGGER_STATE["PS3000A_CONDITION_DONT_CARE"]) nConditions = 1 status["setTrigCond"] = ps.ps3000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(conditions), nConditions) assert_pico_ok(status["setTrigCond"]) # set trigger directions # handle = chandle channelADirection = ps.PS3000A_THRESHOLD_DIRECTION["PS3000A_RISING"] channelBDirection = ps.PS3000A_THRESHOLD_DIRECTION["PS3000A_NONE"] channelCDirection = ps.PS3000A_THRESHOLD_DIRECTION["PS3000A_NONE"] channelDDirection = ps.PS3000A_THRESHOLD_DIRECTION["PS3000A_NONE"] extDirection = ps.PS3000A_THRESHOLD_DIRECTION["PS3000A_RISING"] auxDirection = ps.PS3000A_THRESHOLD_DIRECTION["PS3000A_NONE"] status["setTrigDir"] = ps.ps3000aSetTriggerChannelDirections(chandle, channelADirection, channelBDirection, channelCDirection, channelDDirection, extDirection, auxDirection) assert_pico_ok(status["setTrigDir"]) # Setting the number of sample to be collected preTriggerSamples = 00000 postTriggerSamples = 50000 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle # Timebase = 2 = timebase # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 2 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps3000aGetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps3000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps3000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # start index = 0 # noOfSamples = ctypes.byref(cmaxSamples) # DownSampleRatio = 0 # DownSampleRatioMode = 0 # SegmentIndex = 0 # Overflow = ctypes.byref(overflow) status["GetValues"] = ps.ps3000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValues"]) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps3000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps3000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status) ================================================ FILE: ps3000aExamples/ps3000aBlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS3000A BLOCK MODE EXAMPLE # This example opens a 3000a driver device, sets up one channels and a trigger then collects a block of data. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps3000a import ps3000a as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps3000aOpenUnit(ctypes.byref(chandle), None) 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.ps3000aChangePowerSource(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.ps3000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Set up channel A # handle = chandle # channel = PS3000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS3000A_DC = 1 # range = PS3000A_10V = 8 # analogue offset = 0 V chARange = 8 status["setChA"] = ps.ps3000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Sets up single trigger # Handle = Chandle # Source = ps3000A_channel_B = 0 # Enable = 0 # Threshold = 1024 ADC counts # Direction = ps3000A_Falling = 3 # Delay = 0 # autoTrigger_ms = 1000 status["trigger"] = ps.ps3000aSetSimpleTrigger(chandle, 1, 0, 1024, 3, 0, 1000) assert_pico_ok(status["trigger"]) # Setting the number of sample to be collected preTriggerSamples = 40000 postTriggerSamples = 40000 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle # Timebase = 2 = timebase # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 2 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps3000aGetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps3000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps3000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # start index = 0 # noOfSamples = ctypes.byref(cmaxSamples) # DownSampleRatio = 0 # DownSampleRatioMode = 0 # SegmentIndex = 0 # Overflow = ctypes.byref(overflow) status["GetValues"] = ps.ps3000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValues"]) # Finds the max ADC count # Handle = chandle # Value = ctype.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps3000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps3000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps3000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status) ================================================ FILE: ps3000aExamples/ps3000aBlockMSOExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 3000 Series (A API) MSO Block Mode Example # This example demonstrates how to use the PicoScope 3000 Series (ps3000a) driver API functions in order to do the # following: # # Open a connection to a PicoScope 3000 Series MSO device # Setup a digital port # Collect a block of data # Plot data import ctypes from picosdk.ps3000a import ps3000a 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.ps3000aOpenUnit(ctypes.byref(chandle), None) digital_port0 = ps.PS3000A_DIGITAL_PORT["PS3000A_DIGITAL_PORT0"] 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.ps3000aChangePowerSource(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.ps3000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Set up digital port # handle = chandle # channel = PS3000A_DIGITAL_PORT0 = 0x80 # enabled = 1 # logicLevel = 10000 status["SetDigitalPort"] = ps.ps3000aSetDigitalPort( chandle, digital_port0, 1, 10000) assert_pico_ok(status["SetDigitalPort"]) # Set the number of sample to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Gets timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 1252 # Nosample = totalSamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 1252 timeIntervalNs = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps3000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalNs), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Create buffers ready for assigning pointers for data collection bufferDPort0Max = (ctypes.c_int16 * totalSamples)() bufferDPort0Min = (ctypes.c_int16 * totalSamples)() # Set the data buffer location for data collection from PS3000A_DIGITAL_PORT0 # handle = chandle # source = PS3000A_DIGITAL_PORT0 = 0x80 # Buffer max = ctypes.byref(bufferDPort0Max) # Buffer min = ctypes.byref(bufferDPort0Min) # Buffer length = totalSamples # Segment index = 0 # Ratio mode = PS3000A_RATIO_MODE_NONE = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, digital_port0, ctypes.byref(bufferDPort0Max), ctypes.byref(bufferDPort0Min), totalSamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) print ("Starting data collection...") # Starts the block capture # handle = chandle # Number of preTriggerSamples # Number of postTriggerSamples # Timebase = 1252 = 10000 ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps3000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Creates a overflow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps3000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # start index = 0 # noOfSamples = ctypes.byref(cTotalSamples) # DownSampleRatio = 1 # DownSampleRatioMode = 0 # SegmentIndex = 0 # Overflow = ctypes.byref(overflow) status["GetValues"] = ps.ps3000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 1, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValues"]) print ("Data collection complete.") # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). bufferDPort0 = splitMSODataFast(cTotalSamples, bufferDPort0Max) # Creates the time data time = np.linspace(0, (cTotalSamples.value - 1) * timeIntervalNs.value, cTotalSamples.value) # Plot the data from digital channels onto a graph print ("Plotting data...") plt.figure(num='PicoScope 3000 Series (A API) MSO Block Capture Example') plt.title('Plot of Digital Port 0 digital channels vs. time') plt.plot(time, bufferDPort0[0], label='D7') # D7 is the last array in the tuple. plt.plot(time, bufferDPort0[1], label='D6') plt.plot(time, bufferDPort0[2], label='D5') plt.plot(time, bufferDPort0[3], label='D4') plt.plot(time, bufferDPort0[4], label='D3') plt.plot(time, bufferDPort0[5], label='D2') plt.plot(time, bufferDPort0[6], label='D1') plt.plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. plt.xlabel('Time (ns)') plt.ylabel('Logic Level') plt.legend(loc="upper right") plt.show() print ("Close figure to stop the device and close the connection.") # Stops the scope # handle = chandle status["stop"] = ps.ps3000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # handle = chandle status["closeUnit"] = ps.ps3000aCloseUnit(chandle) assert_pico_ok(status["closeUnit"]) # Displays the status returns print(status) ================================================ FILE: ps3000aExamples/ps3000aRapidBlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS3000A RAPID BLOCK MODE EXAMPLE # This example opens a 3000a driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps3000a import ps3000a as ps import numpy as np import matplotlib import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps3000aOpenUnit(ctypes.byref(chandle), None) 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.ps3000aChangePowerSource(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.ps3000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Set up channel A # handle = chandle # channel = PS3000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS3000A_DC = 1 # range = PS3000A_10V = 8 # analogue offset = 0 V chARange = 8 status["setChA"] = ps.ps3000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Sets up single trigger # Handle = Chandle # Enable = 1 # Source = ps3000A_channel_A = 0 # Threshold = 1024 ADC counts # Direction = ps3000A_Falling = 3 # Delay = 0 # autoTrigger_ms = 1000 status["trigger"] = ps.ps3000aSetSimpleTrigger(chandle, 1, 0, 1024, 3, 0, 1000) assert_pico_ok(status["trigger"]) # Setting the number of sample to be collected preTriggerSamples = 40000 postTriggerSamples = 40000 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle # Timebase = 2 = timebase # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 2 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps3000aGetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Handle = Chandle # nSegments = 10 # nMaxSamples = ctypes.byref(cmaxSamples) status["MemorySegments"] = ps.ps3000aMemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) assert_pico_ok(status["MemorySegments"]) # sets number of captures status["SetNoOfCaptures"] = ps.ps3000aSetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps3000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection #bufferAMax = (ctypes.c_int16 * maxsamples)() #bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example bufferAMax = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax.ctypes.data, bufferAMin.ctypes.data, maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax1 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin1 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax1) # Buffer min = ctypes.byref(bufferAMin1) # Buffer length = maxsamples # Segment index = 1 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax1.ctypes.data, bufferAMin1.ctypes.data, maxsamples, 1, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax2 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin2 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 2 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax2.ctypes.data, bufferAMin2.ctypes.data, maxsamples, 2, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax3 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin3 =np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 3 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax3.ctypes.data, bufferAMin3.ctypes.data, maxsamples, 3, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax4 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin4 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 4 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax4.ctypes.data, bufferAMin4.ctypes.data, maxsamples, 4, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax5 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin5 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 5 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax5.ctypes.data, bufferAMin5.ctypes.data, maxsamples, 5, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax6 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin6 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 6 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax6.ctypes.data, bufferAMin6.ctypes.data, maxsamples, 6, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax7 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin7 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 7 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax7.ctypes.data, bufferAMin7.ctypes.data, maxsamples, 7, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax8 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin8 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 8 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax8.ctypes.data, bufferAMin8.ctypes.data, maxsamples, 8, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax9 = np.empty(maxsamples, dtype=np.dtype('int16')) bufferAMin9 = np.empty(maxsamples, dtype=np.dtype('int16')) # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps3000A_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 9 # Ratio mode = ps3000A_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps3000aSetDataBuffers(chandle, 0, bufferAMax9.ctypes.data, bufferAMin9.ctypes.data, maxsamples, 9, 0) assert_pico_ok(status["SetDataBuffers"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps3000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps3000aGetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 1, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # Handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int16*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps3000aGetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) print(Times[0:9]) print(TimeUnits) # Finds the max ADC count # Handle = chandle # Value = ctype.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps3000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Creates the time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax) print('test') plt.plot(time, adc2mVChAMax1) plt.plot(time, adc2mVChAMax2) plt.plot(time, adc2mVChAMax3) plt.plot(time, adc2mVChAMax4) plt.plot(time, adc2mVChAMax5) plt.plot(time, adc2mVChAMax6) plt.plot(time, adc2mVChAMax7) plt.plot(time, adc2mVChAMax8) plt.plot(time, adc2mVChAMax9) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps3000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps3000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status) ================================================ FILE: ps3000aExamples/ps3000aSigGen.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 3000 (A API) Series Signal Generator Example # This example demonstrates how to use the PicoScope 3000 Series (ps3000a) 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.ps3000a import ps3000a as ps import time from picosdk.functions import assert_pico_ok # Gives the device a handle status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps3000aOpenUnit(ctypes.byref(chandle), None) 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.ps3000aChangePowerSource(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.ps3000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Output a sine wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(0) = PS3000A_SINE # startFrequency = 10000 Hz # stopFrequency = 10000 Hz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS3000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS3000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = P3000A_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(0) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps3000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS3000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS3000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS3000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = P3000A_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps3000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with an up-down sweep, 10-100 kHz in 5 kHz increments every 1 second. # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS3000A_Square # startFrequency = 100 kHz # stopFrequency = 100 kHz # increment = 5 kHz # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS3000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS3000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = P3000A_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(2) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps3000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 100000, 5000, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(36) # Closes the unit # Handle = chandle status["close"] = ps.ps3000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the status returns print(status) ================================================ FILE: ps3000aExamples/ps3000aStreamingExample.py ================================================ # # Copyright (C) 2018-2020 Pico Technology Ltd. See LICENSE file for terms. # # PS3000 Series (A API) STREAMING MODE EXAMPLE # This example demonstrates how to call the ps3000a driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps3000a import ps3000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 5000 Series device status["openunit"] = ps.ps3000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps3000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps3000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) enabled = 1 disabled = 0 analogue_offset = 0.0 # Set up channel A # handle = chandle # channel = PS3000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS3000A_DC = 1 # range = PS3000A_2V = 7 # analogue offset = 0 V channel_range = ps.PS3000A_RANGE['PS3000A_2V'] status["setChA"] = ps.ps3000aSetChannel(chandle, ps.PS3000A_CHANNEL['PS3000A_CHANNEL_A'], enabled, ps.PS3000A_COUPLING['PS3000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS3000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS3000A_DC = 1 # range = PS3000A_2V = 7 # analogue offset = 0 V status["setChB"] = ps.ps3000aSetChannel(chandle, ps.PS3000A_CHANNEL['PS3000A_CHANNEL_B'], enabled, ps.PS3000A_COUPLING['PS3000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 500 numBuffersToCapture = 10 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) memory_segment = 0 # Set data buffer location for data collection from channel A # handle = chandle # source = PS3000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS3000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps3000aSetDataBuffers(chandle, ps.PS3000A_CHANNEL['PS3000A_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS3000A_RATIO_MODE['PS3000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS3000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS3000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps3000aSetDataBuffers(chandle, ps.PS3000A_CHANNEL['PS3000A_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS3000A_RATIO_MODE['PS3000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(250) sampleUnits = ps.PS3000A_TIME_UNITS['PS3000A_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps3000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, ps.PS3000A_RATIO_MODE['PS3000A_RATIO_MODE_NONE'], sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps3000aGetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps3000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples - 1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps3000aStop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps3000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps4000Examples/ps4000BlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4000 BLOCK MODE EXAMPLE # This example opens a 4000 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.ps4000 import ps4000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 5000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000OpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = PS4000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000_DC = 1 # range = PS4000_2V = 7 chARange = 7 status["setChA"] = ps.ps4000SetChannel(chandle, 0, 1, 1, chARange) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000_DC = 1 # range = PS4000_2V = 7 chBRange = 7 status["setChB"] = ps.ps4000SetChannel(chandle, 1, 1, 1, chBRange) assert_pico_ok(status["setChB"]) # setbandwidth filter A status["setBW"] = ps.ps4000SetBwFilter(chandle, 0, 1) # Set up single trigger # handle = chandle # enabled = 1 # source = PS4000_CHANNEL_A = 0 # threshold = 1024 ADC counts # direction = PS4000_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps4000SetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000IsReady rather than ps4000BlockReady) # pParameter = None status["runBlock"] = ps.ps4000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000IsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000IsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples status["setDataBuffersA"] = ps.ps4000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples status["setDataBuffersB"] = ps.ps4000SetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000Stop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"] = ps.ps4000CloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000Examples/ps4000StreamingExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS4000 Series (A API) STREAMING MODE EXAMPLE # This example demonstrates how to call the ps4000 driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps4000 import ps4000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 4000 Series device # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000OpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openunit"]) enabled = 1 disabled = 0 analogue_offset = 0.0 # Set up channel A # handle = chandle # channel = PS4000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000_DC = 1 # range = PS4000_2V = 7 channel_range = ps.PS4000_RANGE['PS4000_2V'] status["setChA"] = ps.ps4000SetChannel(chandle, ps.PS4000_CHANNEL['PS4000_CHANNEL_A'], enabled, 1, channel_range) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000_DC = 1 # range = PS4000_2V = 7 status["setChB"] = ps.ps4000SetChannel(chandle, ps.PS4000_CHANNEL['PS4000_CHANNEL_B'], enabled, 1, channel_range) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 500 numBuffersToCapture = 10 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) memory_segment = 0 # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS4000_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000SetDataBuffers(chandle, ps.PS4000_CHANNEL['PS4000_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS4000_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps4000SetDataBuffers(chandle, ps.PS4000_CHANNEL['PS4000_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(250) sampleUnits = ps.PS4000_TIME_UNITS['PS4000_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps4000RunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps4000GetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples - 1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000Stop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps4000CloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000 Ch4 AND logic triggering.py ================================================ import ctypes from ctypes import byref, c_int16, c_int32, sizeof, Structure, c_uint16 import numpy as np from picosdk.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV,mV2adc ,assert_pico_ok from picosdk.errors import PicoSDKCtypesError import time nChannels = 4 # Level triggers are limited to any 4 channels by the driver/device! ie (Above/Below "THRESHOLD_DIRECTION") # Use edge trigger for 5 Channels or more (Rising/falling "THRESHOLD_DIRECTION") # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) maxADC = ctypes.c_int16(0) # (32767) status["MaximumValue"] = ps.ps4000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["MaximumValue"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V ##################chARange = 7 #channel = ctypes.c_int32() chRange = ctypes.c_int32() #chARange = 7 #ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"] chRange = ps.PICO_CONNECT_PROBE_RANGE["PICO_X1_PROBE_2V"] # pico_x1_probe_2v (see ps4000a.py) for channel in range(nChannels): status["setCh"] = ps.ps4000aSetChannel(chandle, ctypes.c_int32(channel), ctypes.c_int16(1), ps.PS4000A_COUPLING["PS4000A_DC"], chRange, ctypes.c_float(0)) assert_pico_ok(status["setCh"]) # Trigger CONDITIONS #################################### clear = ps.PS4000A_CONDITIONS_INFO["PS4000A_CLEAR"] add = ps.PS4000A_CONDITIONS_INFO["PS4000A_ADD"] action = clear|add conditions = (ps.PS4000A_CONDITION * nChannels)() # Array for each channel condition nConditions = nChannels ######## LOOP # for channel in range(nChannels): conditions[channel].source = ctypes.c_int32(channel) conditions[channel].condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"] status["setTriggerChannelConditions"] = ps.ps4000aSetTriggerChannelConditions( chandle, ctypes.byref(conditions), # Pass the array by reference ctypes.c_int16(nConditions), # Pass the length of the array action # Pass the conditions info ##### USE (CLEAR | ADD) on frist call ) #print("Channel is ", channel) assert_pico_ok(status["setTriggerChannelConditions"]) ############### # Trigger DIRECTIONS #################################### directions = (ps.PS4000A_DIRECTION * nChannels)() # Array for directions (ALL CHANNELS) nDirections = len(directions) ######## LOOP # for channel in range(nChannels): directions[channel].channel = ctypes.c_int32(channel) directions[channel].direction = ps.PS4000A_THRESHOLD_DIRECTION["PS4000A_BELOW"] ############### status["setTriggerChannelDirections"] = ps.ps4000aSetTriggerChannelDirections( chandle, ctypes.byref(directions), # Pass the array by reference ctypes.c_int16(nDirections), # Pass the length of the array (1 in this case) ) assert_pico_ok(status["setTriggerChannelDirections"]) # Trigger PROPERTIES #################################### channelProperties = (ps.PS4000A_TRIGGER_CHANNEL_PROPERTIES * nChannels)() # Array for Properties (ALL CHANNELS) nChannelProperties = len(channelProperties) # set trigger properties for channels # thresholdUpper = mV2adc(300, chRange, maxADC) # Use to set Voltage value thresholdUpper = int(maxADC.value * 0.5) # (+50% of ADC range) Adjust threshold as needed thresholdLower = 0 # Adjust threshold as needed ######## LOOP # for channel in range(nChannels): channelProperties[channel].thresholdUpper = ctypes.c_int16(thresholdUpper) channelProperties[channel].thresholdUpperHysteresis = ctypes.c_uint16(16) # Adjust hysteresis as needed channelProperties[channel].thresholdLower = ctypes.c_int16(thresholdLower) channelProperties[channel].thresholdLowerHysteresis = ctypes.c_uint16(16) # Adjust hysteresis as needed channelProperties[channel].channel = ctypes.c_int32(channel) channelProperties[channel].thresholdMode = ps.PS4000A_THRESHOLD_MODE["PS4000A_LEVEL"] ############### autoTriggerMilliseconds = 0 # Set to 0 to wait indefinitely for a trigger status["setTriggerChannelProperties"] = ps.ps4000aSetTriggerChannelProperties( chandle, ctypes.byref(channelProperties), # Pass the array by reference ctypes.c_int16(nChannelProperties), # Pass the length of the array ctypes.c_int16(0), # auxOutputEnable (not used) ctypes.c_int32(autoTriggerMilliseconds), # autoTriggerMilliseconds ############## PASS as int32 was not working! ) assert_pico_ok(status["setTriggerChannelProperties"]) ######################################################################### preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples timebase = 32 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) print(status) ################################## triggerEnabled = ctypes.c_int16(0) pulseWidthQualifierEnabled = ctypes.c_int16(0) status["isTriggerOrPulseWidthQualifierEnabled"] = ps.ps4000aIsTriggerOrPulseWidthQualifierEnabled( chandle, ctypes.byref(triggerEnabled), ctypes.byref(pulseWidthQualifierEnabled) ) if status["isTriggerOrPulseWidthQualifierEnabled"] == 0: if triggerEnabled.value != 0: print("Trigger is enabled.") else: print("Trigger is disabled.") if pulseWidthQualifierEnabled.value != 0: print("Pulse width qualifier is enabled.") else: print("Pulse width qualifier is disabled.") else: print("Error checking trigger/pulse width qualifier status.") #------------------------------------------------------------------------------------------- # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) #assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady '''ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready))''' ready = ctypes.c_int16(0) check = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) while ready.value == 0: #time.sleep(0.01) # Short delay to allow data capture status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) #assert_pico_ok(status["isReady"]) ###########print(ready.value) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferCMax = (ctypes.c_int16 * maxSamples)() bufferCMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferDMax = (ctypes.c_int16 * maxSamples)() bufferDMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) status["setDataBuffersC"] = ps.ps4000aSetDataBuffers(chandle, 2, ctypes.byref(bufferCMax), ctypes.byref(bufferCMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersC"]) status["setDataBuffersD"] = ps.ps4000aSetDataBuffers(chandle, 3, ctypes.byref(bufferDMax), ctypes.byref(bufferDMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersD"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chRange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chRange, maxADC) adc2mVChCMax = adc2mV(bufferCMax, chRange, maxADC) adc2mVChDMax = adc2mV(bufferDMax, chRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) time = time/1000000 #fig, (ax1, ax2) = plt.subplots(2, 1) #2 rows 1 column fig, (ax1) = plt.subplots(1, 1) #1 rows 1 column # plot data ax1.plot(time, adc2mVChAMax[:]) ax1.plot(time, adc2mVChBMax[:]) ax1.plot(time, adc2mVChCMax[:]) ax1.plot(time, adc2mVChDMax[:]) ax1.set_xlabel('Time (ms)') ax1.set_ylabel('Voltage (mV)') ax1.set_title('Channels') plt.tight_layout() plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000aBlockAdvancedEdgeTriggerExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4824 BLOCK MODE EXAMPLE # This example opens a 4000a 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.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc from math import * # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chARange = 6 status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000a_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chBRange = 6 status["setChB"] = ps.ps4000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up dropout trigger # set trigger condtions for channel A channelAConditions = ps.PS4000A_CONDITION(ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"],ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]) #conditions.channelA.condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"] nConditions = 1 clear = ps.PS4000A_CONDITIONS_INFO["PS4000A_CLEAR"] add = ps.PS4000A_CONDITIONS_INFO["PS4000A_ADD"] info = clear|add status["setTriggerChannelConditions"] = ps.ps4000aSetTriggerChannelConditions(chandle, ctypes.byref(channelAConditions), nConditions, info) assert_pico_ok(status["setTriggerChannelConditions"]) #set trigger directions for channel A directions = ps.PS4000A_DIRECTION(ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_DIRECTION["PS4000A_RISING"]) nDirections = 1 status["setTriggerChannelDirections"] = ps.ps4000aSetTriggerChannelDirections(chandle, ctypes.byref(directions), nDirections) assert_pico_ok(status["setTriggerChannelDirections"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # set trigger properties for channel ADC thresholdUpper = mV2adc(300, chARange, maxADC) thresholdLower = mV2adc(200, chARange, maxADC) channelProperties = ps.PS4000A_TRIGGER_CHANNEL_PROPERTIES(thresholdUpper, floor(thresholdUpper * 0.01), thresholdLower, floor(thresholdLower * 0.01), ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_MODE["PS4000A_WINDOW"]) nChannelProperties = 1 autoTriggerms = 10000 status["setTriggerChannelProperties"] = ps.ps4000aSetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, 0, autoTriggerms) assert_pico_ok(status["setTriggerChannelProperties"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) triggerEnabled = ctypes.c_int16(0) pulseWidthQualifierEnabled = ctypes.c_int16(0) status["isTriggerOrPulseWidthQualifierEnabled"] = ps.ps4000aIsTriggerOrPulseWidthQualifierEnabled( chandle, ctypes.byref(triggerEnabled), ctypes.byref(pulseWidthQualifierEnabled) ) if status["isTriggerOrPulseWidthQualifierEnabled"] == 0: if triggerEnabled.value != 0: print("Trigger is enabled.") else: print("Trigger is disabled.") if pulseWidthQualifierEnabled.value != 0: print("Pulse width qualifier is enabled.") else: print("Pulse width qualifier is disabled.") else: print("Error checking trigger/pulse width qualifier status.") # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000a_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000aBlockDropoutTriggerExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4824 BLOCK MODE EXAMPLE # This example opens a 4000a 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.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc from math import * # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chARange = 7 status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000a_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chBRange = 7 status["setChB"] = ps.ps4000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up dropout trigger # set trigger condtions for channel A and pulse width qualifier class RECT(ctypes.Structure): _fields_ = [("channelA",ps.PS4000A_CONDITION), ("pwq",ps.PS4000A_CONDITION)] #conditions =[ps.PS4000A_CONDITION() for i in range (2)] channelAConditions = ps.PS4000A_CONDITION(ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"],ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]) #conditions.channelA.condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"] pulseWidthConditions = ps.PS4000A_CONDITION(ps.PS4000A_CHANNEL["PS4000A_PULSE_WIDTH_SOURCE"],ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]) #conditions.pwq.condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"] conditions = RECT(channelAConditions,pulseWidthConditions) nConditions = 2 info = ps.PS4000A_CONDITIONS_INFO["PS4000A_ADD"] status["setTriggerChannelConditions"] = ps.ps4000aSetTriggerChannelConditions(chandle, ctypes.byref(conditions), nConditions, info) assert_pico_ok(status["setTriggerChannelConditions"]) #set trigger directions for channel A directions = ps.PS4000A_DIRECTION(ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_DIRECTION["PS4000A_ENTER"]) nDirections = 1 status["setTriggerChannelDirections"] = ps.ps4000aSetTriggerChannelDirections(chandle, ctypes.byref(directions), nDirections) assert_pico_ok(status["setTriggerChannelDirections"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # set trigger properties for channel ADC thresholdUpper = mV2adc(500, 7, maxADC) channelProperties = ps.PS4000A_TRIGGER_CHANNEL_PROPERTIES(thresholdUpper, floor(thresholdUpper * 0.05), (thresholdUpper * -1), floor(thresholdUpper * 0.05), ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_MODE["PS4000A_WINDOW"]) nChannelProperties = 1 autoTriggerms = 10000 status["setTriggerChannelProperties"] = ps.ps4000aSetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, 0, autoTriggerms) assert_pico_ok(status["setTriggerChannelProperties"]) # set pulse width qualifier conditions pwqNConditions = 1 status["setPulseWidthQualifierConditions"] = ps.ps4000aSetPulseWidthQualifierConditions(chandle, ctypes.byref(pulseWidthConditions), pwqNConditions, info) assert_pico_ok(status["setPulseWidthQualifierConditions"]) # set pulse width qualifier properties direction = ps.PS4000A_THRESHOLD_DIRECTION["PS4000A_ENTER"] lower = 15 upper = 100 type = ps.PS4000A_PULSE_WIDTH_TYPE["PW_TYPE_IN_RANGE"] status["setPulseWidthQualifierProperties"] = ps.ps4000aSetPulseWidthQualifierProperties(chandle, direction, lower, upper, type) assert_pico_ok(status["setPulseWidthQualifierProperties"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000a_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000aBlockFrequencyCounterExample.py ================================================ # # Copyright (C) 2025 Pico Technology Ltd. See LICENSE file for terms. # # PS4000 BLOCK MODE FREQUENCY COUNTER EXAMPLE # This example opens a 4000a driver device, sets up two channels and a trigger then collects a block of data. # This data is then plotted as Hz against time in ns. # # This example will only work with an automotive version of a 4000 series scope # such as 4225A and 4425A import ctypes import numpy as np from picosdk.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc from math import * # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_5V = 8 # analogOffset = 0 V chARange = 8 status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_5V = 8 # analogOffset = 0 V chARange = 8 status["setChB"] = ps.ps4000aSetChannel(chandle, 1, 1, 1, chARange, 0) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # set trigger properties for channel ADC thresholdMajor = mV2adc(300, chARange, maxADC) thresholdMinor = mV2adc(0, chARange, maxADC) # set up frequency counting # handle = chandle # channel - PS4000a_CHANNEL_A = 0 # enabled = 1 # frequency range = PS4000A_FC_200 = 0 - 200 Hz status["setFrequencyCounter"] = ps.ps4000aSetFrequencyCounter(chandle, 0, 1, ps.PS4000A_FREQUENCY_COUNTER_RANGE["PS4000A_FC_200"],thresholdMajor,thresholdMinor) # Set number of pre and post trigger samples to be collected preTriggerSamples = 500000 postTriggerSamples = 500000 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 52 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # # convert ADC counts data to mV adc2mVChBMax = adc2mV(bufferBMax, chARange, maxADC) # convert ADC counts to Hz for channel A chAHzMax = [((x + 32767) * 200) / (2 * maxADC.value) for x in bufferAMax] # # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A plt.plot(time, chAHzMax) # plt.plot(time, chAHzMin) plt.xlabel('Time (ns)') plt.ylabel('Frequency (Hz)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000aRapidBlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4000A RAPID BLOCK MODE EXAMPLE # This example opens a 4000a driver device, sets up two channels and a trigger then collects 10 blocks of data with additional driver calls. # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chARange = 7 status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000a_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chBRange = 7 status["setChB"] = ps.ps4000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up single trigger # handle = chandle # enabled = 1 # source = PS4000a_CHANNEL_A = 0 # threshold = 1024 ADC counts # direction = PS4000a_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps4000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Set memory segments # handle = chandle # nSegments = 10 nMaxSamples = ctypes.c_int32(0) status["setMemorySegments"] = ps.ps4000aMemorySegments(chandle, 10, ctypes.byref(nMaxSamples)) assert_pico_ok(status["setMemorySegments"]) # Set number of captures # handle = chandle # nCaptures = 10 status["SetNoOfCaptures"] = ps.ps4000aSetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # set up buffers bufferA0 = (ctypes.c_int16 * maxSamples)() bufferA1 = (ctypes.c_int16 * maxSamples)() bufferA2 = (ctypes.c_int16 * maxSamples)() bufferA3 = (ctypes.c_int16 * maxSamples)() bufferA4 = (ctypes.c_int16 * maxSamples)() bufferA5 = (ctypes.c_int16 * maxSamples)() bufferA6 = (ctypes.c_int16 * maxSamples)() bufferA7 = (ctypes.c_int16 * maxSamples)() bufferA8 = (ctypes.c_int16 * maxSamples)() bufferA9 = (ctypes.c_int16 * maxSamples)() bufferB0 = (ctypes.c_int16 * maxSamples)() bufferB1 = (ctypes.c_int16 * maxSamples)() bufferB2 = (ctypes.c_int16 * maxSamples)() bufferB3 = (ctypes.c_int16 * maxSamples)() bufferB4 = (ctypes.c_int16 * maxSamples)() bufferB5 = (ctypes.c_int16 * maxSamples)() bufferB6 = (ctypes.c_int16 * maxSamples)() bufferB7 = (ctypes.c_int16 * maxSamples)() bufferB8 = (ctypes.c_int16 * maxSamples)() bufferB9 = (ctypes.c_int16 * maxSamples)() # set data buffers # handle = chandle # channel = PS4000A_CHANNEL_A = 0 # buffer = bufferAX (where X = segmentIndex) # bufferLength = maxSamples # segmentIndex = X # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBufferA0"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA0), maxSamples, 0, 0) status["setDataBufferA1"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA1), maxSamples, 1, 0) status["setDataBufferA2"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA2), maxSamples, 2, 0) status["setDataBufferA3"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA3), maxSamples, 3, 0) status["setDataBufferA4"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA4), maxSamples, 4, 0) status["setDataBufferA5"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA5), maxSamples, 5, 0) status["setDataBufferA6"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA6), maxSamples, 6, 0) status["setDataBufferA7"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA7), maxSamples, 7, 0) status["setDataBufferA8"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA8), maxSamples, 8, 0) status["setDataBufferA9"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferA9), maxSamples, 9, 0) status["setDataBufferB0"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB0), maxSamples, 0, 0) status["setDataBufferB1"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB1), maxSamples, 1, 0) status["setDataBufferB2"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB2), maxSamples, 2, 0) status["setDataBufferB3"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB3), maxSamples, 3, 0) status["setDataBufferB4"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB4), maxSamples, 4, 0) status["setDataBufferB5"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB5), maxSamples, 5, 0) status["setDataBufferB6"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB6), maxSamples, 6, 0) status["setDataBufferB7"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB7), maxSamples, 7, 0) status["setDataBufferB8"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB8), maxSamples, 8, 0) status["setDataBufferB9"] = ps.ps4000aSetDataBuffer(chandle, 0, ctypes.byref(bufferB9), maxSamples, 9, 0) # run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # check for end of capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxSamples) # collect data # handle = chandle # noOfSamples = cmaxSamples # fromSegmentIndex = 0 # toSegmentIndex = 9 # downSampleRatio = 1 # downSampleRatioMode = PS4000A_RATIO_MODE_NONE status["getValuesBulk"] = ps.ps4000aGetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 1, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValuesBulk"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # convert from adc to mV adc2mVChA0 = adc2mV(bufferA0, chARange, maxADC) adc2mVChA1 = adc2mV(bufferA1, chARange, maxADC) adc2mVChA2 = adc2mV(bufferA2, chARange, maxADC) adc2mVChA3 = adc2mV(bufferA3, chARange, maxADC) adc2mVChA4 = adc2mV(bufferA4, chARange, maxADC) adc2mVChA5 = adc2mV(bufferA5, chARange, maxADC) adc2mVChA6 = adc2mV(bufferA6, chARange, maxADC) adc2mVChA7 = adc2mV(bufferA7, chARange, maxADC) adc2mVChA8 = adc2mV(bufferA8, chARange, maxADC) adc2mVChA9 = adc2mV(bufferA9, chARange, maxADC) adc2mVChB0 = adc2mV(bufferB0, chARange, maxADC) adc2mVChB1 = adc2mV(bufferB1, chARange, maxADC) adc2mVChB2 = adc2mV(bufferB2, chARange, maxADC) adc2mVChB3 = adc2mV(bufferB3, chARange, maxADC) adc2mVChB4 = adc2mV(bufferB4, chARange, maxADC) adc2mVChB5 = adc2mV(bufferB5, chARange, maxADC) adc2mVChB6 = adc2mV(bufferB6, chARange, maxADC) adc2mVChB7 = adc2mV(bufferB7, chARange, maxADC) adc2mVChB8 = adc2mV(bufferB8, chARange, maxADC) adc2mVChB9 = adc2mV(bufferB9, chARange, maxADC) # Create time data time = np.linspace(0, ((cmaxSamples.value)-1) * timeIntervalns.value, cmaxSamples.value) # plot data plt.plot(time, adc2mVChA0) plt.plot(time, adc2mVChA1) plt.plot(time, adc2mVChA2) plt.plot(time, adc2mVChA3) plt.plot(time, adc2mVChA4) plt.plot(time, adc2mVChA5) plt.plot(time, adc2mVChA6) plt.plot(time, adc2mVChA7) plt.plot(time, adc2mVChA8) plt.plot(time, adc2mVChA9) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000aRapidBlockWaveformAveragingExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS4000 A BLOCK MODE WAVEFORM AVERAGING EXAMPLE # This example opens a 4000a driver device, sets up two channels and a trigger then collects blocks of data. # The blocks are then avraged together for each channel. # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps4000a import ps4000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc from picosdk.functionsExhibitions import * from math import ceil # Scope settings noOfChannels = 1 samplingRate = 1 #Mhz sampleLength = 10000 #Samples numberOfSegments = 10 timebase = ps4000aTimebase(samplingRate) # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set channels on # handle = chandle coupling = enums.PICO_COUPLING["PICO_DC"] channelRange = 7 # +-2 V range # analogueOffset = 0 V for x in range(0, noOfChannels, 1): channel = x status["setChannel",x] = ps.ps4000aSetChannel(chandle, channel, 1, coupling, channelRange, 0) assert_pico_ok(status["setChannel",x]) # set channels off for x in range (noOfChannels, 4, 1): channel = x status["setChannel",x] = ps.ps4000aSetChannel(chandle,channel, 0, coupling, channelRange, 0) try: assert_pico_ok(status["setChannel",x]) except: break # get max ADC value # handle = chandle maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps4000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = 0 # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps4000aSetSimpleTrigger(chandle, 1, source, (mV2adc(500,channelRange,maxADC)), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Set number of samples to be collected noOfPreTriggerSamples = int(sampleLength/2) noOfPostTriggerSamples = int(sampleLength/2) nSamples = int(noOfPostTriggerSamples + noOfPreTriggerSamples) # Get fastest available timebase # handle = chandle # enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] # timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_float(0) # # resolution = resolution # status["getMinimumTimebaseStateless"] = ps.ps4000aGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) # print("timebase = ", timebase.value) # print("sample interval =", timeInterval.value, "s") maxSamples = ctypes.c_uint32(0) status["getTimebase"] = ps.ps4000aGetTimebase2(chandle, timebase, nSamples, ctypes.byref(timeInterval), ctypes.byref(maxSamples), 0) assert_pico_ok(status["getTimebase"]) # Set number of memory segments maxSegments = ctypes.c_uint64(10) status["memorySegments"] = ps.ps4000aMemorySegments(chandle, numberOfSegments, ctypes.byref(maxSegments)) assert_pico_ok(status["memorySegments"]) # Set number of captures status["setNoOfCaptures"] = ps.ps4000aSetNoOfCaptures(chandle, numberOfSegments) assert_pico_ok(status["setNoOfCaptures"]) oneDBuffer = (ctypes.c_int16 * nSamples) twoDbuffer = (oneDBuffer * numberOfSegments) threeDBuffer = (twoDbuffer * noOfChannels) buffer = (threeDBuffer)() # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples downSampleMode = ps.PS4000A_RATIO_MODE["PS4000A_RATIO_MODE_NONE"] for x in range(0, numberOfSegments, 1): for y in range(0, noOfChannels, 1): channel = y status["setDataBuffers",x,y] = ps.ps4000aSetDataBuffer(chandle, channel, ctypes.byref(buffer[y][x]), nSamples, x, downSampleMode) assert_pico_ok(status["setDataBuffers",x,y]) # sign gen output # Set signal generator waveform # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 wavetype = ctypes.c_int32(0) #PS4000a_SINE frequencyHz = 1000 # increment = 0 # dwellTime = 1 sweepType = ctypes.c_int32(0) #PS4000a_UP # operation = 0 # shots = 0 # sweeps = 0 triggertype = ctypes.c_int32(0) #PS4000a_SIGGEN_RISING triggerSource = ctypes.c_int32(0) #P4000a_SIGGEN_NONE # extInThreshold = 1 status["setSigGenBuiltInV2"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, frequencyHz, frequencyHz, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 0) assert_pico_ok(status["setSigGenBuiltInV2"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 # Creates a overflow location for each segment overflow = (ctypes.c_int16 * numberOfSegments)() status["getValues"] = ps.ps4000aGetValuesBulk(chandle, ctypes.byref(noOfSamples), 0, numberOfSegments-1, 1, downSampleMode, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) oneDBuffer = (ctypes.c_float * nSamples) twoDbuffer = (oneDBuffer * numberOfSegments) threeDBuffer = (twoDbuffer * noOfChannels) rapidBlockBuffers = (threeDBuffer)() # convert ADC counts data to mV # convert all active channels for x in range (0, numberOfSegments,1): for y in range (0, noOfChannels, 1): A = adc2mV(buffer[y][x], channelRange, maxADC) for z in range(0, nSamples, 1): rapidBlockBuffers[y][x][z] = ctypes.c_float(A[z]) # Average waveforms averageWaveform=np.zeros((noOfChannels,nSamples)) # loop through each channel, each memory segment and each sample to sum together, then divides by the number of memory segment to get the mean waveform for each channel for y in range (0, noOfChannels, 1): for x in range (0, numberOfSegments,1): for z in range (0, nSamples,1): averageWaveform[y][z] = averageWaveform[y][z] + rapidBlockBuffers[y][x][z] averageWaveform[y] = [x/numberOfSegments for x in averageWaveform[y]] # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot channel A from all blocks # for y in range (0, numberOfSegments, 1): # segment = y # plt.plot(time, rapidBlockBuffers[0][y]) # plot averaged waveform from channel A plt.plot(time, averageWaveform[0]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps4000aExamples/ps4000aSigGen.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 4000 (A API) Series Signal Generator Example # This example demonstrates how to use the PicoScope 4000 Series (ps4000a) 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.ps4000a import ps4000a as ps import time from picosdk.functions import assert_pico_ok # Gives the device a handle status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) 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.ps4000aChangePowerSource(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.ps4000aChangePowerSource(chandle, 286) else: raise assert_pico_ok(status["ChangePowerSource"]) # Output a sine wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(0) = PS4000A_SINE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int32(0) = PS4000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS4000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS4000A_SIGGEN_NONE # extInThreshold = 0 wavetype = ps.PS4000A_WAVE_TYPE['PS4000A_SINE'] sweepType = ps.PS4000A_SWEEP_TYPE['PS4000A_UP'] triggertype = ps.PS4000A_SIGGEN_TRIG_TYPE['PS4000A_SIGGEN_RISING'] triggerSource = ps.PS4000A_SIGGEN_TRIG_SOURCE['PS4000A_SIGGEN_NONE'] extInThreshold = ctypes.c_int16(0) #extInThreshold - Not used status["SetSigGenBuiltIn"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, extInThreshold) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(1) = PS4000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int32(0) = PS4000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS4000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS4000A_SIGGEN_NONE # extInThreshold = 0 wavetype = ps.PS4000A_WAVE_TYPE['PS4000A_SQUARE'] sweepType = ps.PS4000A_SWEEP_TYPE['PS4000A_UP'] triggertype = ps.PS4000A_SIGGEN_TRIG_TYPE['PS4000A_SIGGEN_RISING'] triggerSource = ps.PS4000A_SIGGEN_TRIG_SOURCE['PS4000A_SIGGEN_NONE'] extInThreshold = ctypes.c_int16(0) #extInThreshold - Not used status["SetSigGenBuiltIn"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, extInThreshold) assert_pico_ok(status["SetSigGenBuiltIn"]) # pauses the script to show signal time.sleep(10) # Output square wave with an up-down sweep, ranging from 10-100 kHz in 5 kHz increments every 1 second. # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(1) = PS4000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 100 kHz # increment = 5 kHz # dwellTime = 1 # sweepType = ctypes.c_int32(2) = PS4000A_UPDOWN # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS4000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS4000A_SIGGEN_NONE # extInThreshold = 0 wavetype = ps.PS4000A_WAVE_TYPE['PS4000A_SQUARE'] sweepType = ps.PS4000A_SWEEP_TYPE['PS4000A_UPDOWN'] triggertype = ps.PS4000A_SIGGEN_TRIG_TYPE['PS4000A_SIGGEN_RISING'] triggerSource = ps.PS4000A_SIGGEN_TRIG_SOURCE['PS4000A_SIGGEN_NONE'] extInThreshold = ctypes.c_int16(0) #extInThreshold - Not used status["SetSigGenBuiltIn"] = ps.ps4000aSetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 100000, 5000, 1, sweepType, 0, 0, 0, triggertype, triggerSource, extInThreshold) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(36) # Closes the unit # Handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the status returns print(status) ================================================ FILE: ps4000aExamples/ps4000aStreamingExample.py ================================================ # # Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms. # # PS2000 Series (A API) STREAMING MODE EXAMPLE # This example demonstrates how to call the ps4000A driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 2000 Series device # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) enabled = 1 disabled = 0 analogue_offset = 0.0 # Set up channel A # handle = chandle # channel = PS4000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000A_DC = 1 # range = PS4000A_2V = 7 # analogue offset = 0 V channel_range = 7 status["setChA"] = ps.ps4000aSetChannel(chandle, ps.PS4000A_CHANNEL['PS4000A_CHANNEL_A'], enabled, ps.PS4000A_COUPLING['PS4000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000A_DC = 1 # range = PS4000A_2V = 7 # analogue offset = 0 V status["setChB"] = ps.ps4000aSetChannel(chandle, ps.PS4000A_CHANNEL['PS4000A_CHANNEL_B'], enabled, ps.PS4000A_COUPLING['PS4000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 500 numBuffersToCapture = 100 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) memory_segment = 0 # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, ps.PS4000A_CHANNEL['PS4000A_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS4000A_RATIO_MODE['PS4000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, ps.PS4000A_CHANNEL['PS4000A_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS4000A_RATIO_MODE['PS4000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(250) sampleUnits = ps.PS4000A_TIME_UNITS['PS4000A_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps4000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, ps.PS4000A_RATIO_MODE['PS4000A_RATIO_MODE_NONE'], sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps4000aGetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps4000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples - 1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, bufferCompleteA[:]) plt.plot(time, bufferCompleteB[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps4000aExamples/ps4000a_Runt_trigger.py ================================================ import ctypes from picosdk.ps4000a import ps4000a as ps from picosdk.functions import assert_pico_ok import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV,mV2adc def setup_runt_trigger(chandle, trigger_ch, channel_range_mv): # Sets up a positive "Runt" trigger between levels 0v and 1.8V, autotrigger disabled. # Assume chandle is already open and channels are set up print("Configuring Runt trigger...") status = {} # 1. Define Trigger Channel Conditions # This specifies the Channelto be the source for the trigger logic. # PS4000A_CONDITION(source, condition) # condition: 0 = Ignore, 1 = True, 2 = False cond_list = [ ps.PS4000A_CONDITION( trigger_ch, # ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"] ) ] # Convert list to ctypes array n_cond = len(cond_list) conditions = (ps.PS4000A_CONDITION * n_cond)(*cond_list) status["setTriggerChannelConditions"] = ps.ps4000aSetTriggerChannelConditions( chandle, ctypes.byref(conditions), ctypes.c_int16(n_cond), ps.PS4000A_CONDITIONS_INFO["PS4000A_CLEAR"] | ps.PS4000A_CONDITIONS_INFO["PS4000A_ADD"] ) assert_pico_ok(status["setTriggerChannelConditions"]) # 2. Define Trigger Directions # For a Runt trigger, we use "POSITIVE_RUNT" or "NEGATIVE_RUNT". # PS4000A_DIRECTION(channel, direction) dir_list = [ ps.PS4000A_DIRECTION( trigger_ch, # ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_DIRECTION["PS4000A_POSITIVE_RUNT"] ) ] n_dirs = len(dir_list) directions = (ps.PS4000A_DIRECTION * n_dirs)(*dir_list) status["setTriggerChannelDirections"] = ps.ps4000aSetTriggerChannelDirections( chandle, ctypes.byref(directions), ctypes.c_int16(n_dirs) ) assert_pico_ok(status["setTriggerChannelDirections"]) # 3. Define Trigger Channel Properties (Thresholds) # A runt trigger requires two thresholds (Upper and Lower). # Convert mV to ADC counts (helper function assumed or manual calc) # For example, if max ADC is 32767: lower_threshold_adc = mV2adc(0, channel_range_mv, maxADC) print("Lower Threshold: ",lower_threshold_adc) upper_threshold_adc = mV2adc(1800, channel_range_mv, maxADC) print("Upper Threshold: ",upper_threshold_adc) prop_list = [ ps.PS4000A_TRIGGER_CHANNEL_PROPERTIES( ctypes.c_int16(upper_threshold_adc), # thresholdUpper ctypes.c_uint16(256), # thresholdUpperHysteresis ctypes.c_int16(lower_threshold_adc), # thresholdLower ctypes.c_uint16(256), # thresholdLowerHysteresis trigger_ch, # ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_MODE["PS4000A_WINDOW"] # Window type needed for Runt trigger ) ] n_props = len(prop_list) properties = (ps.PS4000A_TRIGGER_CHANNEL_PROPERTIES * n_props)(*prop_list) status["setTriggerChannelProperties"] = ps.ps4000aSetTriggerChannelProperties( chandle, ctypes.byref(properties), ctypes.c_int16(n_props), ctypes.c_int16(0), # auxOutputEnable 0: Off ctypes.c_int32(0) # autoTriggerMilliseconds (0 to wait forever) ) assert_pico_ok(status["setTriggerChannelProperties"]) # Check with API if trigger is set... triggerEnabled = ctypes.c_int16(0) pulseWidthQualifierEnabled = ctypes.c_int16(0) status["isTriggerOrPulseWidthQualifierEnabled"] = ps.ps4000aIsTriggerOrPulseWidthQualifierEnabled( chandle, ctypes.byref(triggerEnabled), ctypes.byref(pulseWidthQualifierEnabled) ) if status["isTriggerOrPulseWidthQualifierEnabled"] == 0: if triggerEnabled.value != 0: print("Trigger is enabled.") else: print("Trigger is disabled.") if pulseWidthQualifierEnabled.value != 0: print("Pulse width qualifier is enabled.") else: print("Pulse width qualifier is disabled.") else: print("Error checking trigger/pulse width qualifier status.") return status #------------------------------------------------------------------------------------------- ############################################################ # START MAIN CODE # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) maxADC = ctypes.c_int16(0) # (32767) status["MaximumValue"] = ps.ps4000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["MaximumValue"]) channel = ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"] chRange = ps.PICO_CONNECT_PROBE_RANGE["PICO_X1_PROBE_5V"] # (see ps4000a.py) status["setChA"] = ps.ps4000aSetChannel(chandle, ctypes.c_int32(channel), ctypes.c_int16(1), ps.PS4000A_COUPLING["PS4000A_DC"], chRange, ctypes.c_float(0)) assert_pico_ok(status["setChA"]) ######################################################################### setup_runt_trigger(chandle, channel, chRange) # Setup a "Runt "Trigger ######################################################################### # Setup number samples and trigger point, and sample interval preTriggerSamples = 50_000 postTriggerSamples = 50_000 maxSamples = preTriggerSamples + postTriggerSamples timebase = 400 # ~200kS/s # (see Programmer's guide for mre information on timebases) timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) print(status) #------------------------------------------------------------------------------------------- # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady '''ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready))''' ready = ctypes.c_int16(0) check = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) while ready.value == 0: #time.sleep(0.01) # Short delay to allow data capture status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) #assert_pico_ok(status["isReady"]) ###########print(ready.value) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chRange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) time = time/1000000 #fig, (ax1, ax2) = plt.subplots(2, 1) #2 rows 1 column fig, (ax1) = plt.subplots(1, 1) #1 rows 1 column # plot data ax1.plot(time, adc2mVChAMax[:]) ax1.plot(time, adc2mVChBMax[:]) ax1.set_xlabel('Time (ms)') ax1.set_ylabel('Voltage (mV)') ax1.set_title('Channels') plt.tight_layout() plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4444BlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4824 BLOCK MODE EXAMPLE # This example opens a 4000a 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.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chARange = 7 status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000a_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chBRange = 7 status["setChB"] = ps.ps4000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up channel C # handle = chandle # channel = PS4000a_CHANNEL_C = 2 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chCRange = 7 status["setChC"] = ps.ps4000aSetChannel(chandle, 2, 0, 1, chCRange, 0) assert_pico_ok(status["setChC"]) # Set up channel D # handle = chandle # channel = PS4000a_CHANNEL_D = 3 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chDRange = 7 status["setChD"] = ps.ps4000aSetChannel(chandle, 3, 0, 1, chDRange, 0) assert_pico_ok(status["setChD"]) # Set up single trigger # handle = chandle # enabled = 1 # source = PS4000a_CHANNEL_A = 0 # threshold = 1024 ADC counts # direction = PS4000a_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps4000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 100) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000a_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4444BlockPicoConnectProbesExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4444 PICOCONNECT PROBE, BLOCK MODE EXAMPLE # This example opens a 4444 device, and demos PicoConnectProbes events. import ctypes from array import array import time import numpy as np from picosdk.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, adc2mVpl1000, mV2adcpl1000 from pynput import keyboard # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} probes = (ps.PS4000A_USER_PROBE_INTERACTIONS * 4)() # # Calback for PicoConnectProbes events def PicoConnectProbe_callback(handle, pico_status, probes_ptr, nProbes): global PicoConnectProbewasCalledBack PicoConnectProbewasCalledBack = True print("PicoConnectProbes pico_status ", pico_status) print("Number of PicoConnectProbes events is ", nProbes) #print(probes_ptr) # If probes_ptr is an integer (raw address), cast it to a pointer if isinstance(probes_ptr, int): probes_ptr = ctypes.cast(probes_ptr, ctypes.POINTER( (ps.PS4000A_USER_PROBE_INTERACTIONS) )) n_probes = nProbes if n_probes > 0 and probes_ptr: # Iterate over the pointer using the count provided by n_probes for i in range(n_probes): # Access the struct at index i probes[(probes_ptr[i].channel)] = probes_ptr[i] else: print("No probe interactions recorded.") ########################################################### # Convert the python function into a C function pointer. cFuncPtr2 = ps.ps4000aProbeInteractions(PicoConnectProbe_callback) # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) status["SetProbeInteractionCallback"] = ps.ps4000aSetProbeInteractionCallback(chandle, cFuncPtr2) assert_pico_ok(status["SetProbeInteractionCallback"]) time.sleep(1.0) # Delay for first Probe callback events to trigger status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, ps.PS4000A_COUPLING["PS4000A_DC"], ps.PICO_CONNECT_PROBE_RANGE["PICO_X1_PROBE_1V"], 0) status["setChA"] = ps.ps4000aSetChannel(chandle, 1, 1, ps.PS4000A_COUPLING["PS4000A_DC"], ps.PICO_CONNECT_PROBE_RANGE["PICO_X1_PROBE_1V"], 0) status["setChA"] = ps.ps4000aSetChannel(chandle, 2, 1, ps.PS4000A_COUPLING["PS4000A_DC"], ps.PICO_CONNECT_PROBE_RANGE["PICO_X1_PROBE_1V"], 0) status["setChA"] = ps.ps4000aSetChannel(chandle, 3, 1, ps.PS4000A_COUPLING["PS4000A_DC"], ps.PICO_CONNECT_PROBE_RANGE["PICO_X1_PROBE_1V"], 0) ################################################## # Look in \picosdk\ps4000a.py for all "PICO_CONNECT_PROBE_RANGE" defines for your Probe. # The 4444 PicoConnect current clamps don't have auto zero offset. # You need to manually set an analog offset in both PicoScope 7 and when using the API. # If you measuring AC current you can just AC couple the channel to remove any offset. # You can find out the max. and min. analogoffset values that can be set for any probe range by calling- # ps4000aGetAnalogueOffset(). ################################################## print("Press 'Enter' to exit the Probe update loop!") keep_going=keyboard.Listener(lambda key: False if key==keyboard.Key.enter else True) keep_going.start() while keep_going.is_alive(): if (PicoConnectProbewasCalledBack == True): PicoConnectProbewasCalledBack = False print("DEBUG all probe status:") for i in range(4): #probe = probes_ptr[i] # index into the array if (probes[i].connected): status["setChannel"] = ps.ps4000aSetChannel(chandle, i, # channel 1, # enabled ps.PS4000A_COUPLING["PS4000A_DC"], # coupling (probes[i].rangeLast_), # probes[i].rangeFirst_, # ps.PICO_CONNECT_PROBE_RANGE[probes[i].rangeFirst_], 0) # offset else: status["setChannel"] = ps.ps4000aSetChannel(chandle, i, 0, ps.PS4000A_COUPLING["PS4000A_DC"], ps.PICO_CONNECT_PROBE_RANGE["PICO_CONNECT_PROBE_OFF"], 0) assert_pico_ok(status["setChannel"]) #for i in range(4): print(f"Channel {i}:") print(f" Connected: {probes[i].connected}") print(f" probeName: {probes[i].probeName}") #print(f" Status: {probes[i].status}") print(f" Coupling: {probes[i].couplingCurrent_}") # Add more fields as needed time.sleep(0.1) #status["trigger"] = ps.ps4000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 100) #assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 25000 postTriggerSamples = 25000 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 400 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferCMax = (ctypes.c_int16 * maxSamples)() bufferCMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferDMax = (ctypes.c_int16 * maxSamples)() bufferDMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) status["setDataBuffersC"] = ps.ps4000aSetDataBuffers(chandle, 2, ctypes.byref(bufferCMax), ctypes.byref(bufferCMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersC"]) status["setDataBuffersD"] = ps.ps4000aSetDataBuffers(chandle, 3, ctypes.byref(bufferDMax), ctypes.byref(bufferDMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersD"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # Scale for ps.PICO_CONNECT_PROBE_RANGE["PICO_CURRENT_CLAMP_40A_5A"] range -> scale to +/-5A # adc2ProbeRangeChAMax = [(float(x) * 5 ) / float(maxADC.value) for x in float(bufferAMax)] # Just use adc2mVpl1000() to do this, and pass the range value scale to. # Just scale to 100 for percentage, for this demo adc2ProbeRangeChAMax = adc2mVpl1000(bufferAMax, 100 , maxADC) adc2ProbeRangeChBMax = adc2mVpl1000(bufferBMax, 100 , maxADC) adc2ProbeRangeChCMax = adc2mVpl1000(bufferCMax, 100 , maxADC) adc2ProbeRangeChDMax = adc2mVpl1000(bufferDMax, 100 , maxADC) # NICE TO HAVE A FUNCTION AND LOOK TABLE/ARRAY TO TRANSLATE PROBE ENUMS TO SCALING VALUES, rather than passing in constant above. # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data plt.plot(time, adc2ProbeRangeChAMax[:]) plt.plot(time, adc2ProbeRangeChBMax[:]) plt.plot(time, adc2ProbeRangeChCMax[:]) plt.plot(time, adc2ProbeRangeChDMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Channel range (+/-100%)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps4000aExamples/ps4824BlockExample.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PS4824 BLOCK MODE EXAMPLE # This example opens a 4000a 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.ps4000a import ps4000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 4000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps4000aOpenUnit(ctypes.byref(chandle), None) try: assert_pico_ok(status["openunit"]) except: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps4000aChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle # channel = PS4000a_CHANNEL_A = 0 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chARange = 7 status["setChA"] = ps.ps4000aSetChannel(chandle, 0, 1, 1, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS4000a_CHANNEL_B = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chBRange = 7 status["setChB"] = ps.ps4000aSetChannel(chandle, 1, 1, 1, chBRange, 0) assert_pico_ok(status["setChB"]) # Set up channel C # handle = chandle # channel = PS4000a_CHANNEL_C = 2 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chCRange = 7 status["setChC"] = ps.ps4000aSetChannel(chandle, 2, 0, 1, chCRange, 0) assert_pico_ok(status["setChC"]) # Set up channel D # handle = chandle # channel = PS4000a_CHANNEL_D = 3 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chDRange = 7 status["setChD"] = ps.ps4000aSetChannel(chandle, 3, 0, 1, chDRange, 0) assert_pico_ok(status["setChD"]) # Set up channel E # handle = chandle # channel = PS4000a_CHANNEL_E = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chERange = 7 status["setChE"] = ps.ps4000aSetChannel(chandle, 4, 0, 1, chERange, 0) assert_pico_ok(status["setChE"]) # Set up channel F # handle = chandle # channel = PS4000a_CHANNEL_F = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chFRange = 7 status["setChF"] = ps.ps4000aSetChannel(chandle, 5, 0, 1, chFRange, 0) assert_pico_ok(status["setChF"]) # Set up channel G # handle = chandle # channel = PS4000a_CHANNEL_G = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chGRange = 7 status["setChG"] = ps.ps4000aSetChannel(chandle, 6, 0, 1, chGRange, 0) assert_pico_ok(status["setChG"]) # Set up channel H # handle = chandle # channel = PS4000a_CHANNEL_H = 1 # enabled = 1 # coupling type = PS4000a_DC = 1 # range = PS4000a_2V = 7 # analogOffset = 0 V chHRange = 7 status["setChH"] = ps.ps4000aSetChannel(chandle, 7, 0, 1, chHRange, 0) assert_pico_ok(status["setChH"]) # Set up single trigger # handle = chandle # enabled = 1 # source = PS4000a_CHANNEL_A = 0 # threshold = 1024 ADC counts # direction = PS4000a_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps4000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 100) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # WARNING: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() oversample = ctypes.c_int16(1) status["getTimebase2"] = ps.ps4000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 3 = 80 ns = timebase (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps4000aIsReady rather than ps4000aBlockReady) # pParameter = None status["runBlock"] = ps.ps4000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps4000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps4000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS4000a_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps4000aSetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS4000a_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segementIndex = 0 # mode = PS4000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps4000aSetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0 , 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS4000a_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps4000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps4000aStop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle status["close"] = ps.ps4000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000Examples/ps5000BlockExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS5000 BLOCK MODE EXAMPLE # This example opens a 5000a 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.ps5000 import ps5000 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 # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps5000OpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle channel = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"] # enabled = 1 coupling_type = 1 # DC chARange = ps.PS5000_RANGE["PS5000_20V"] # analogue offset = 0 V status["setChA"] = ps.ps5000SetChannel(chandle, channel, 1, coupling_type, chARange) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle channel = ps.PS5000_CHANNEL["PS5000_CHANNEL_B"] # enabled = 1 # coupling_type = ps.PS5000_COUPLING["PS5000_DC"] chBRange = ps.PS5000_RANGE["PS5000_2V"] # analogue offset = 0 V status["setChB"] = ps.ps5000SetChannel(chandle, channel, 1, coupling_type, chBRange) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32512) # Set up single trigger # handle = chandle # enabled = 1 source = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"] threshold = int(mV2adc(500,chARange, maxADC)) # direction = PS5000_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps5000SetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle timebase = 8 # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) oversample = 1 # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timeIntervalns = ctypes.c_long() returnedMaxSamples = ctypes.c_int32() status["getTimebase"] = ps.ps5000GetTimebase(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # oversample = 1 # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps5000IsReady rather than ps5000BlockReady) # pParameter = None status["runBlock"] = ps.ps5000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000IsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000IsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle source = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"] # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples status["setDataBuffersA"] = ps.ps5000SetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle source = ps.PS5000_CHANNEL["PS5000_CHANNEL_B"] # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000SetDataBuffers(chandle, source, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps5000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000Stop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"]=ps.ps5000CloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000Examples/ps5000RapidBlockExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # ps5000 RAPID BLOCK MODE EXAMPLE # This example opens a 5000 driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps5000 import ps5000 as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps5000OpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openunit"]) # Displays the serial number and handle print(chandle.value) # Set up channel A # handle = chandle channel = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"] # enabled = 1 coupling_type = 1 # DC chARange = ps.PS5000_RANGE["PS5000_5V"] status["setChA"] = ps.ps5000SetChannel(chandle, channel, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Finds the max ADC count # Handle = chandle # Value = ctype.byref(maxADC) maxADC = ctypes.c_int16(32512) # Set up single trigger # handle = chandle # enabled = 1 source = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"] threshold = int(mV2adc(500,chARange, maxADC)) # direction = PS5000_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps5000SetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Setting the number of sample to be collected preTriggerSamples = 400 postTriggerSamples = 400 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle timebase = 2 # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timeIntervalns = ctypes.c_float() oversample = 1 returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps5000GetTimebase(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Handle = Chandle # nSegments = 10 # nMaxSamples = ctypes.byref(cmaxSamples) status["MemorySegments"] = ps.ps5000MemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) assert_pico_ok(status["MemorySegments"]) # sets number of captures status["SetNoOfCaptures"] = ps.ps5000SetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps5000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle source = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 0 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax1 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 1 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax2 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 2 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax3 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 3 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax4 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 4 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax5 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 5 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax6 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 6 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax7 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 7 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax8 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 8 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax9 = (ctypes.c_int16 * maxsamples)() # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000_CHANNEL["ps5000_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer length = maxsamples # Segment index = 9 status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9) assert_pico_ok(status["SetDataBuffers"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000IsReady(chandle, ctypes.byref(ready)) # Handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps5000GetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # Handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int16*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps5000GetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps5000Stop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps5000CloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns #print(status) ================================================ FILE: ps5000Examples/ps5000StreamingExample.py ================================================ # # Copyright (C) 2018-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS5000 Series STREAMING MODE EXAMPLE # This example demonstrates how to call the ps5000 driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps5000 import ps5000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 5000 Series device status["openunit"] = ps.ps5000OpenUnit(ctypes.byref(chandle)) try: assert_pico_ok(status["openunit"]) except: # PicoNotOkError: powerStatus = status["openunit"] if powerStatus == 286: status["changePowerSource"] = ps.ps5000ChangePowerSource(chandle, powerStatus) elif powerStatus == 282: status["changePowerSource"] = ps.ps5000ChangePowerSource(chandle, powerStatus) else: raise assert_pico_ok(status["changePowerSource"]) enabled = 1 disabled = 0 coupling_type = 1 # Set up channel A # handle = chandle # channel = PS5000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS5000A_DC = 1 # range = PS5000A_2V = 7 channel_range = ps.PS5000_RANGE["PS5000_2V"] status["setChA"] = ps.ps5000SetChannel(chandle, ps.PS5000_CHANNEL['PS5000_CHANNEL_A'], enabled, coupling_type, channel_range) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS5000_CHANNEL_B = 1 # enabled = 1 # coupling type = PS5000A_DC = 1 # range = PS5000A_2V = 7 status["setChB"] = ps.ps5000SetChannel(chandle, ps.PS5000_CHANNEL['PS5000_CHANNEL_B'], enabled, coupling_type, channel_range) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 10000 numBuffersToCapture = 10 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) memory_segment = 0 # Set data buffer location for data collection from channel A # handle = chandle # source = PS5000_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # buffer length = maxSamples status["setDataBuffersA"] = ps.ps5000SetDataBuffers(chandle, ps.PS5000_CHANNEL['PS5000_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer ) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS5000_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # buffer length = maxSamples status["setDataBuffersB"] = ps.ps5000SetDataBuffers(chandle, ps.PS5000_CHANNEL['PS5000_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(200) sampleUnits = ps.PS5000_TIME_UNITS['PS5000_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps5000RunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps5000GetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32767) #status["maximumValue"] = ps.ps5000MaximumValue(chandle, ctypes.byref(maxADC)) #assert_pico_ok(status["maximumValue"]) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples - 1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000Stop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps5000CloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockAdvancedTriggerExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS5000A BLOCK MODE EXAMPLE # This example opens a 5000a 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.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 assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # enabled = 1 coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chARange = ps.PS5000A_RANGE["PS5000A_20V"] # analogue offset = 0 V status["setChA"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # enabled = 1 # coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chBRange = ps.PS5000A_RANGE["PS5000A_2V"] # analogue offset = 0 V status["setChB"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chBRange, 0) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Set up an advanced trigger adcTriggerLevelA = mV2adc(500, chARange, maxADC) adcTriggerLevelB = mV2adc(500, chARange, maxADC) adcTriggerLevelC = mV2adc(500, chARange, maxADC) adcTriggerLevelD = mV2adc(500, chARange, maxADC) triggerProperties = (ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2 * 4)() triggerProperties[0] = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(adcTriggerLevelA, 10, 0, 10, ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]) triggerProperties[1] = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(adcTriggerLevelB, 10, 0, 10, ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"]) triggerProperties[2] = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(adcTriggerLevelC, 10, 0, 10, ps.PS5000A_CHANNEL["PS5000A_CHANNEL_C"]) triggerProperties[3] = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(adcTriggerLevelD, 10, 0, 10, ps.PS5000A_CHANNEL["PS5000A_CHANNEL_D"]) status["setTriggerChannelPropertiesV2"] = ps.ps5000aSetTriggerChannelPropertiesV2(chandle, ctypes.byref(triggerProperties), 4, 0) assert_pico_ok(status["setTriggerChannelPropertiesV2"]) triggerConditionsA = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) triggerConditionsB = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) triggerConditionsC = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_C"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) triggerConditionsD = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_D"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) clear = 1 add = 2 status["setTriggerChannelConditionsV2_A"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(triggerConditionsA), 1, (clear + add)) assert_pico_ok(status["setTriggerChannelConditionsV2_A"]) status["setTriggerChannelConditionsV2_B"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(triggerConditionsB), 1, (add)) assert_pico_ok(status["setTriggerChannelConditionsV2_B"]) status["setTriggerChannelConditionsV2_C"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(triggerConditionsC), 1, (add)) assert_pico_ok(status["setTriggerChannelConditionsV2_C"]) status["setTriggerChannelConditionsV2_D"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(triggerConditionsD), 1, (add)) assert_pico_ok(status["setTriggerChannelConditionsV2_D"]) triggerDirections = (ps.PS5000A_DIRECTION * 4)() triggerDirections[0] = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]) triggerDirections[1] = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]) triggerDirections[2] = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_C"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]) triggerDirections[3] = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_D"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]) status["setTriggerChannelDirections"] = ps.ps5000aSetTriggerChannelDirectionsV2(chandle, ctypes.byref(triggerDirections), 4) assert_pico_ok(status["setTriggerChannelDirections"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle timebase = 8 # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps5000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps5000aIsReady rather than ps5000aBlockReady) # pParameter = None status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"]=ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockCallbackExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS5000A BLOCK MODE EXAMPLE # This example opens a 5000a 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.ps5000a import ps5000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc from picosdk.constants import PICO_STATUS import time # 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 assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # enabled = 1 coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chARange = ps.PS5000A_RANGE["PS5000A_20V"] # analogue offset = 0 V status["setChA"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # enabled = 1 # coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chBRange = ps.PS5000A_RANGE["PS5000A_2V"] # analogue offset = 0 V status["setChB"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chBRange, 0) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Set up single trigger # handle = chandle # enabled = 1 source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] threshold = int(mV2adc(500,chARange, maxADC)) # direction = PS5000A_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps5000aSetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle timebase = 8 # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps5000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # setup callback function ready = False def block_callback(handle, statusCallback, param): global wasCalledBack, ready wasCalledBack = True if statusCallback != PICO_STATUS['PICO_CANCELLED']: ready = True # Convert the python function into a C function pointer. cFuncPtr = ps.BlockReadyType(block_callback) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = cFuncPtr # pParameter = None status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, cFuncPtr, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady check = ctypes.c_int16(0) while ready == False: time.sleep(0.01) print("Capture finished") # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"]=ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS5000A BLOCK MODE EXAMPLE # This example opens a 5000a 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.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 assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle channelA = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # enabled = 1 coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chARange = ps.PS5000A_RANGE["PS5000A_2V"] # analogue offset = 0 V status["setChA"] = ps.ps5000aSetChannel(chandle, channelA, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle channelB = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # enabled = 1 # coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chBRange = ps.PS5000A_RANGE["PS5000A_2V"] # analogue offset = 0 V status["setChB"] = ps.ps5000aSetChannel(chandle, channelB, 1, coupling_type, chBRange, 0) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Set up simple trigger # handle = chandle # enabled = 1 source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] threshold = int(mV2adc(500,chARange, maxADC)) # direction = PS5000A_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps5000aSetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle timebase = 8 # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps5000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps5000aIsReady rather than ps5000aBlockReady) # pParameter = None status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"]=ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockLevelPulseWidthAdvancedTriggerExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS5000A BLOCK MODE EXAMPLE # This example opens a 5000a 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.ps5000a import ps5000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc import math # 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 assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # enabled = 1 coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chARange = ps.PS5000A_RANGE["PS5000A_20V"] # analogue offset = 0 V status["setChA"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # enabled = 1 # coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chBRange = ps.PS5000A_RANGE["PS5000A_2V"] # analogue offset = 0 V status["setChB"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chBRange, 0) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle timebase = 8 # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps5000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Set up an advanced trigger adcTriggerLevel = mV2adc(500, chARange, maxADC) triggerProperties = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(adcTriggerLevel, 10, 0, 10, ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]) status["setTriggerChannelPropertiesV2"] = ps.ps5000aSetTriggerChannelPropertiesV2(chandle, ctypes.byref(triggerProperties), 1, 0) assert_pico_ok(status["setTriggerChannelPropertiesV2"]) triggerConditions = (ps.PS5000A_CONDITION * 2)() # triggerConditions[0] = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], # ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) triggerConditions = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_PULSE_WIDTH_SOURCE"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) clear = 1 add = 2 status["setTriggerChannelConditionsV2"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(triggerConditions), 1, (clear|add)) assert_pico_ok(status["setTriggerChannelConditionsV2"]) triggerDirections = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]) status["setTriggerChannelDirections"] = ps.ps5000aSetTriggerChannelDirectionsV2(chandle, ctypes.byref(triggerDirections), 1) assert_pico_ok(status["setTriggerChannelDirections"]) # pulse width setup # pulse width conditions PWQConditions = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) status["setPWQualifierConditions"] = ps.ps5000aSetPulseWidthQualifierConditions(chandle, ctypes.byref(PWQConditions), 1, add) assert_pico_ok(status["setPWQualifierConditions"]) #set pulse width counter timeWidthNs = 3000 counterSamples = math.ceil(timeWidthNs / timeIntervalns.value) # pulse width properties PWtype = 2 #ps.PS5000A_PULSE_WIDTH_TYPE["PS5000A_PW_TYPE_GREATER_THAN"] status["setPWQualifierProperties"] = ps.ps5000aSetPulseWidthQualifierProperties(chandle, counterSamples, counterSamples, PWtype) assert_pico_ok(status["setPWQualifierProperties"]) #pulse width directions PWQDirections = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_FALLING"], ps.PS5000A_THRESHOLD_MODE["PS5000A_LEVEL"]) status["setPWQualifierDirections"] = ps.ps5000aSetPulseWidthQualifierDirections(chandle, ctypes.byref(PWQDirections), 1) assert_pico_ok(status["setPWQualifierDirections"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps5000aIsReady rather than ps5000aBlockReady) # pParameter = None status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"]=ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockMSOExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 5000 Series (A API) MSO Block Mode Example # This example demonstrates how to use the PicoScope 5000 Series (ps5000a) driver API functions in order to do the # following: # # Open a connection to a PicoScope 5000 Series MSO device # 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) else: raise assert_pico_ok(status["ChangePowerSource"]) digital_port0 = ps.PS5000A_CHANNEL["PS5000A_DIGITAL_PORT0"] # Set up digital port # handle = chandle # channel = ps5000a_DIGITAL_PORT0 = 0x80 # enabled = 1 # logicLevel = 10000 status["SetDigitalPort"] = ps.ps5000aSetDigitalPort( chandle, digital_port0, 1, 10000) assert_pico_ok(status["SetDigitalPort"]) #Set a trigger on digital channel # Set the number of sample to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Gets timebase information # handle = chandle # timebase = 1252 # Nosample = totalSamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 1252 timeIntervalNs = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps5000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalNs), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Create buffers ready for assigning pointers for data collection bufferDPort0Max = (ctypes.c_int16 * totalSamples)() bufferDPort0Min = (ctypes.c_int16 * totalSamples)() # Set the data buffer location for data collection from ps5000a_DIGITAL_PORT0 # handle = chandle # source = ps5000a_DIGITAL_PORT0 = 0x80 # Buffer max = ctypes.byref(bufferDPort0Max) # Buffer min = ctypes.byref(bufferDPort0Min) # Buffer length = totalSamples # Segment index = 0 # Ratio mode = ps5000a_RATIO_MODE_NONE = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, 0x80, ctypes.byref(bufferDPort0Max), ctypes.byref(bufferDPort0Min), totalSamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) print ("Starting data collection...") # Starts the block capture # handle = chandle # Number of preTriggerSamples # Number of postTriggerSamples # Timebase = 1252 = 10000 ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runblock"]) # Creates a overflow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # start index = 0 # noOfSamples = ctypes.byref(cTotalSamples) # DownSampleRatio = 1 # DownSampleRatioMode = 0 # SegmentIndex = 0 # Overflow = ctypes.byref(overflow) status["GetValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 1, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValues"]) print ("Data collection complete.") # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). bufferDPort0 = splitMSODataFast(cTotalSamples, bufferDPort0Max) # Creates the time data time = np.linspace(0, (cTotalSamples.value - 1) * timeIntervalNs.value, cTotalSamples.value) print ("Plotting data...") # Plot the data from digital channels onto a graph plt.figure(num='PicoScope 3000 Series (A API) MSO Block Capture Example') plt.title('Plot of Digital Port 0 digital channels vs. time') plt.plot(time, bufferDPort0[0], label='D7') # D7 is the first array in the tuple. plt.plot(time, bufferDPort0[1], label='D6') plt.plot(time, bufferDPort0[2], label='D5') plt.plot(time, bufferDPort0[3], label='D4') plt.plot(time, bufferDPort0[4], label='D3') plt.plot(time, bufferDPort0[5], label='D2') plt.plot(time, bufferDPort0[6], label='D1') plt.plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. plt.xlabel('Time (ns)') plt.ylabel('Logic Level') plt.legend(loc="upper right") plt.show() print ("Close figure to stop the device and close the connection.") # Stops the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # handle = chandle status["closeUnit"] = ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["closeUnit"]) # Displays the status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockMSOTriggerExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 5000 Series (A API) MSO Block Mode Triggered Example # This example demonstrates how to use the PicoScope 5000 Series (ps5000a) driver API functions in order to do the # following: # # Open a connection to a PicoScope 5000 Series MSO device # Setup a digital port # Set up a digital trigger # 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) else: raise assert_pico_ok(status["ChangePowerSource"]) digital_port0 = ps.PS5000A_CHANNEL["PS5000A_DIGITAL_PORT0"] # Set up digital port # handle = chandle # channel = ps5000a_DIGITAL_PORT0 = 0x80 # enabled = 1 # logicLevel = 10000 status["SetDigitalPort"] = ps.ps5000aSetDigitalPort( chandle, digital_port0, 1, 10000) assert_pico_ok(status["SetDigitalPort"]) #Set a trigger on digital channel # Set the number of sample to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 totalSamples = preTriggerSamples + postTriggerSamples # Gets timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 1252 # Nosample = totalSamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalNs) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 1252 timeIntervalNs = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps5000aGetTimebase2(chandle, timebase, totalSamples, ctypes.byref(timeIntervalNs), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Create buffers ready for assigning pointers for data collection bufferDPort0Max = (ctypes.c_int16 * totalSamples)() bufferDPort0Min = (ctypes.c_int16 * totalSamples)() # Set the data buffer location for data collection from ps5000a_DIGITAL_PORT0 # handle = chandle # source = ps5000a_DIGITAL_PORT0 = 0x80 # Buffer max = ctypes.byref(bufferDPort0Max) # Buffer min = ctypes.byref(bufferDPort0Min) # Buffer length = totalSamples # Segment index = 0 # Ratio mode = ps5000a_RATIO_MODE_NONE = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, 0x80, ctypes.byref(bufferDPort0Max), ctypes.byref(bufferDPort0Min), totalSamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) # set the digital trigger for a high bit on digital channel 0 conditions = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_DIGITAL_PORT0"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) nConditions = 1 clear = 1 add = 2 info = clear + add status["setTriggerChannelConditionsV2"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(conditions), nConditions, info) assert_pico_ok(status["setTriggerChannelConditionsV2"]) directions = ps.PS5000A_DIGITAL_CHANNEL_DIRECTIONS(ps.PS5000A_DIGITAL_CHANNEL["PS5000A_DIGITAL_CHANNEL_0"], ps.PS5000A_DIGITAL_DIRECTION["PS5000A_DIGITAL_DIRECTION_HIGH"]) nDirections = 1 status["setTriggerDigitalPortProperties"] = ps.ps5000aSetTriggerDigitalPortProperties(chandle, ctypes.byref(directions), nDirections) assert_pico_ok(status["setTriggerDigitalPortProperties"]) # set autotrigger timeout value status["autoTriggerus"] = ps.ps5000aSetAutoTriggerMicroSeconds(chandle, 10000) assert_pico_ok(status["autoTriggerus"]) print ("Starting data collection...") # Starts the block capture # handle = chandle # Number of preTriggerSamples # Number of postTriggerSamples # Timebase = 1252 = 10000 ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runblock"]) # Creates a overflow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types totalSamples cTotalSamples = ctypes.c_int32(totalSamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # start index = 0 # noOfSamples = ctypes.byref(cTotalSamples) # DownSampleRatio = 1 # DownSampleRatioMode = 0 # SegmentIndex = 0 # Overflow = ctypes.byref(overflow) status["GetValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cTotalSamples), 1, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValues"]) print ("Data collection complete.") # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). bufferDPort0 = splitMSODataFast(cTotalSamples, bufferDPort0Max) # Creates the time data time = np.linspace(0, (cTotalSamples.value - 1) * timeIntervalNs.value, cTotalSamples.value) print ("Plotting data...") # Plot the data from digital channels onto a graph plt.figure(num='PicoScope 3000 Series (A API) MSO Block Capture Example') plt.title('Plot of Digital Port 0 digital channels vs. time') plt.plot(time, bufferDPort0[0], label='D7') # D7 is the first array in the tuple. plt.plot(time, bufferDPort0[1], label='D6') plt.plot(time, bufferDPort0[2], label='D5') plt.plot(time, bufferDPort0[3], label='D4') plt.plot(time, bufferDPort0[4], label='D3') plt.plot(time, bufferDPort0[5], label='D2') plt.plot(time, bufferDPort0[6], label='D1') plt.plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. plt.xlabel('Time (ns)') plt.ylabel('Logic Level') plt.legend(loc="upper right") plt.show() print ("Close figure to stop the device and close the connection.") # Stops the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # handle = chandle status["closeUnit"] = ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["closeUnit"]) # Displays the status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aBlockWindowPulseWidthAdvancedTriggerExample.py ================================================ # # Copyright (C) 2018-2023 Pico Technology Ltd. See LICENSE file for terms. # # PS5000A BLOCK MODE WINDOW PULSE WIDTH ADVANCED TRIGGER EXAMPLE # This example opens a 5000a 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.ps5000a import ps5000a as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc import math # 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 assert_pico_ok(status["changePowerSource"]) # Set up channel A # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # enabled = 1 coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chARange = ps.PS5000A_RANGE["PS5000A_20V"] # analogue offset = 0 V status["setChA"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # enabled = 1 # coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chBRange = ps.PS5000A_RANGE["PS5000A_2V"] # analogue offset = 0 V status["setChB"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chBRange, 0) assert_pico_ok(status["setChB"]) # find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle timebase = 8 # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps5000aGetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Set up an advanced trigger adcTriggerLevel = mV2adc(500, chARange, maxADC) triggerProperties = ps.PS5000A_TRIGGER_CHANNEL_PROPERTIES_V2(adcTriggerLevel, 10, 0, 10, ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]) status["setTriggerChannelPropertiesV2"] = ps.ps5000aSetTriggerChannelPropertiesV2(chandle, ctypes.byref(triggerProperties), 1, 0) assert_pico_ok(status["setTriggerChannelPropertiesV2"]) triggerConditions = (ps.PS5000A_CONDITION * 2)() # triggerConditions[0] = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], # ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) triggerConditions = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_PULSE_WIDTH_SOURCE"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) clear = 1 add = 2 status["setTriggerChannelConditionsV2"] = ps.ps5000aSetTriggerChannelConditionsV2(chandle, ctypes.byref(triggerConditions), 1, (clear|add)) assert_pico_ok(status["setTriggerChannelConditionsV2"]) triggerDirections = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_OUTSIDE"], ps.PS5000A_THRESHOLD_MODE["PS5000A_WINDOW"]) status["setTriggerChannelDirections"] = ps.ps5000aSetTriggerChannelDirectionsV2(chandle, ctypes.byref(triggerDirections), 1) assert_pico_ok(status["setTriggerChannelDirections"]) # pulse width setup # pulse width conditions PWQConditions = ps.PS5000A_CONDITION(ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], ps.PS5000A_TRIGGER_STATE["PS5000A_CONDITION_TRUE"]) status["setPWQualifierConditions"] = ps.ps5000aSetPulseWidthQualifierConditions(chandle, ctypes.byref(PWQConditions), 1, add) assert_pico_ok(status["setPWQualifierConditions"]) #set pulse width counter timeWidthNs = 3000 counterSamples = math.ceil(timeWidthNs / timeIntervalns.value) # pulse width properties PWtype = 2 #ps.PS5000A_PULSE_WIDTH_TYPE["PS5000A_PW_TYPE_GREATER_THAN"] status["setPWQualifierProperties"] = ps.ps5000aSetPulseWidthQualifierProperties(chandle, counterSamples, counterSamples, PWtype) assert_pico_ok(status["setPWQualifierProperties"]) #pulse width directions PWQDirections = ps.PS5000A_DIRECTION(ps.PS5000A_CHANNEL["PS5000A_PULSE_WIDTH_SOURCE"], ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_ENTER"], ps.PS5000A_THRESHOLD_MODE["PS5000A_WINDOW"]) status["setPWQualifierDirections"] = ps.ps5000aSetPulseWidthQualifierDirections(chandle, ctypes.byref(PWQDirections), 1) assert_pico_ok(status["setPWQualifierDirections"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps5000aIsReady rather than ps5000aBlockReady) # pParameter = None status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"] # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0, 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps5000aGetValues(chandle, 0, ctypes.byref(cmaxSamples), 0, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Close unit Disconnect the scope # handle = chandle status["close"]=ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # display status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aRapidBlockExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # ps5000a RAPID BLOCK MODE EXAMPLE # This example opens a 5000a driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps5000a import ps5000a as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s 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 assert_pico_ok(status["changePowerSource"]) # Displays the serial number and handle print(chandle.value) # Set up channel A # handle = chandle channel = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # enabled = 1 coupling_type = ps.PS5000A_COUPLING["PS5000A_DC"] chARange = ps.PS5000A_RANGE["PS5000A_20V"] # analogue offset = 0 V status["setChA"] = ps.ps5000aSetChannel(chandle, channel, 1, coupling_type, chARange, 0) assert_pico_ok(status["setChA"]) # Finds the max ADC count # Handle = chandle # Value = ctype.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) # Set up single trigger # handle = chandle # enabled = 1 source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] threshold = int(mV2adc(500,chARange, maxADC)) # direction = PS5000A_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps5000aSetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Setting the number of sample to be collected preTriggerSamples = 400 postTriggerSamples = 400 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle timebase = 2 # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["GetTimebase"] = ps.ps5000aGetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Handle = Chandle # nSegments = 10 # nMaxSamples = ctypes.byref(cmaxSamples) status["MemorySegments"] = ps.ps5000aMemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) assert_pico_ok(status["MemorySegments"]) # sets number of captures status["SetNoOfCaptures"] = ps.ps5000aSetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax1 = (ctypes.c_int16 * maxsamples)() bufferAMin1 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 1 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax2 = (ctypes.c_int16 * maxsamples)() bufferAMin2 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 2 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax3 = (ctypes.c_int16 * maxsamples)() bufferAMin3 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 3 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax4 = (ctypes.c_int16 * maxsamples)() bufferAMin4 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 4 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax5 = (ctypes.c_int16 * maxsamples)() bufferAMin5 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 5 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax6 = (ctypes.c_int16 * maxsamples)() bufferAMin6 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 6 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax7 = (ctypes.c_int16 * maxsamples)() bufferAMin7 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 7 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax8 = (ctypes.c_int16 * maxsamples)() bufferAMin8 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 8 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8, 0) assert_pico_ok(status["SetDataBuffers"]) # Create buffers ready for assigning pointers for data collection bufferAMax9 = (ctypes.c_int16 * maxsamples)() bufferAMin9 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps.PS5000A_CHANNEL["ps5000a_channel_A"] # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 9 # Ratio mode = ps5000a_Ratio_Mode_None = 0 status["SetDataBuffers"] = ps.ps5000aSetDataBuffers(chandle, source, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9, 0) assert_pico_ok(status["SetDataBuffers"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps5000aGetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # Handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int64*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps5000aGetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Get and print TriggerInfo for memory segments # Create array of ps.PS5000A_TRIGGER_INFO for each memory segment Ten_TriggerInfo = (ps.PS5000A_TRIGGER_INFO*10) () status["GetTriggerInfoBulk"] = ps.ps5000aGetTriggerInfoBulk(chandle, ctypes.byref(Ten_TriggerInfo), 0, 9) assert_pico_ok(status["GetTriggerInfoBulk"]) print("Printing triggerInfo blocks") for i in Ten_TriggerInfo: print("PICO_STATUS is ", i.status) print("segmentIndex is ", i.segmentIndex) print("triggerTime is ", i.triggerTime) print("timeUnits is ", i.timeUnits) print("timeStampCounter is ", i.timeStampCounter) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns #print(status) ================================================ FILE: ps5000aExamples/ps5000aSigGen.py ================================================ # # Copyright (C) 2018-2024 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 5000 (A API) Signal Generator Example # 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 import numpy as np import math import matplotlib.pyplot as plt 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 assert_pico_ok(status["changePowerSource"]) # Output a sine wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(0) = PS5000A_SINE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS5000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS5000a_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = P5000a_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int32(0) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["setSigGenBuiltInV2"] = ps.ps5000aSetSigGenBuiltInV2(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 0) assert_pico_ok(status["setSigGenBuiltInV2"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS5000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS5000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS5000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS5000A_SIGGEN_NONE # extInThreshold = 0 wavetype = ctypes.c_int32(1) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["setSigGenBuiltInV2"] = ps.ps5000aSetSigGenBuiltInV2(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 0) assert_pico_ok(status["setSigGenBuiltInV2"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with an up-down sweep, 10-100 kHz in 5 kHz increments every 1 second. # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS5000A_SQUARE # startFrequency = 10 kHz # stopFrequency = 100 kHz # increment = 5 kHz # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS5000A_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS5000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS5000A_SIGGEN_NONE # extInThreshold = 0 wavetype = ctypes.c_int32(1) sweepType = ctypes.c_int32(2) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["setSigGenBuiltInV2"] = ps.ps5000aSetSigGenBuiltInV2(chandle, 0, 2000000, wavetype, 10000, 100000, 5000, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 0) assert_pico_ok(status["setSigGenBuiltInV2"]) # Pauses the script to show signal time.sleep(6) # create a custom waveform minValue = ctypes.c_int16(0) maxValue = ctypes.c_int16(0) minSize = ctypes.c_int16(0) maxSize = ctypes.c_int16(0) status["sigGenArbMinMax"] = ps.ps5000aSigGenArbitraryMinMaxValues(chandle, ctypes.byref(minValue), ctypes.byref(maxValue),ctypes.byref(minSize),ctypes.byref(maxSize)) assert_pico_ok(status["sigGenArbMinMax"]) awgBuffer = (np.sin(np.linspace(0,2*math.pi,10000)))*maxValue.value awgBuffer = awgBuffer.astype(ctypes.c_int16) awgbufferPointer = awgBuffer.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)) # convert 10 KHZ frequency to phase freq = 10000 indexMode = 0 bufferLength = len(awgBuffer) phase = ctypes.c_int16(0) status["freqToPhase"] = ps.ps5000aSigGenFrequencyToPhase(chandle, freq, indexMode, bufferLength, ctypes.byref(phase)) assert_pico_ok(status["freqToPhase"]) # output custom waveform with peak-to-peak of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # startDeltaPhase = phase # stopDeltaPhase = phase # deltaPhaseIncrement = 0 # dwellCount = 0 # *arbitaryWaveform = awgbufferPointer # arbitaryWaveformSize = 1024 # sweepType = ctypes.c_int32(0) # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS5000A_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS5000A_SIGGEN_NONE # extInThreshold = 0 status["setSigGenArbitrary"] = ps.ps5000aSetSigGenArbitrary(chandle, 0, 3600000, phase.value, phase.value, 0, 0, awgbufferPointer, bufferLength, 0, 0, 0, 0, 0, 0, 0, 0) assert_pico_ok(status["setSigGenArbitrary"]) # Pauses the script to show signal time.sleep(10) # Closes the unit # Handle = chandle status["close"] = ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the status returns print(status) ================================================ FILE: ps5000aExamples/ps5000aStreamingExample.py ================================================ # # Copyright (C) 2018-2019 Pico Technology Ltd. See LICENSE file for terms. # # PS5000 Series (A API) STREAMING MODE EXAMPLE # This example demonstrates how to call the ps5000a driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. 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 import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 5000 Series device # 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 assert_pico_ok(status["changePowerSource"]) enabled = 1 disabled = 0 analogue_offset = 0.0 # Set up channel A # handle = chandle # channel = PS5000A_CHANNEL_A = 0 # enabled = 1 # coupling type = PS5000A_DC = 1 # range = PS5000A_2V = 7 # analogue offset = 0 V channel_range = ps.PS5000A_RANGE['PS5000A_2V'] status["setChA"] = ps.ps5000aSetChannel(chandle, ps.PS5000A_CHANNEL['PS5000A_CHANNEL_A'], enabled, ps.PS5000A_COUPLING['PS5000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS5000A_CHANNEL_B = 1 # enabled = 1 # coupling type = PS5000A_DC = 1 # range = PS5000A_2V = 7 # analogue offset = 0 V status["setChB"] = ps.ps5000aSetChannel(chandle, ps.PS5000A_CHANNEL['PS5000A_CHANNEL_B'], enabled, ps.PS5000A_COUPLING['PS5000A_DC'], channel_range, analogue_offset) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 500 numBuffersToCapture = 10 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) memory_segment = 0 # Set data buffer location for data collection from channel A # handle = chandle # source = PS5000A_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(chandle, ps.PS5000A_CHANNEL['PS5000A_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS5000A_RATIO_MODE['PS5000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS5000A_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS5000A_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(chandle, ps.PS5000A_CHANNEL['PS5000A_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, memory_segment, ps.PS5000A_RATIO_MODE['PS5000A_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(250) sampleUnits = ps.PS5000A_TIME_UNITS['PS5000A_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps5000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, ps.PS5000A_RATIO_MODE['PS5000A_RATIO_MODE_NONE'], sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps5000aGetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16() status["maximumValue"] = ps.ps5000aMaximumValue(chandle, ctypes.byref(maxADC)) assert_pico_ok(status["maximumValue"]) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples - 1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps5000aStop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps5000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps6000Examples/ps6000BlockAdvancedTriggerExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 BLOCK MODE ADVANCED TRIGGER EXAMPLE # This example opens a 6000 driver device, sets up one channel and a window pulse width advanced 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.ps6000 import ps6000 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 6000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = PS6000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS6000_DC = 1 # range = PS6000_2V = 7 # analogue offset = 0 V # bandwidth limiter = PS6000_BW_FULL = 0 chARange = 7 status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0) assert_pico_ok(status["setChA"]) # Set up window pulse width trigger on A triggerConditions = ps.PS6000_TRIGGER_CONDITIONS(ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"]) nTriggerConditions = 1 status["setTriggerChannelConditions"] = ps.ps6000SetTriggerChannelConditions(chandle, ctypes.byref(triggerConditions), nTriggerConditions) assert_pico_ok(status["setTriggerChannelConditions"]) status["setTriggerChannelDirections"] = ps.ps6000SetTriggerChannelDirections(chandle, ps.PS6000_THRESHOLD_DIRECTION["PS6000_INSIDE"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"], ps.PS6000_THRESHOLD_DIRECTION["PS6000_NONE"]) assert_pico_ok(status["setTriggerChannelDirections"]) maxADC = ctypes.c_int16(32512) threshold = mV2adc(109.2, chARange, maxADC) hysteresis = mV2adc((109.2 * 0.015), chARange, maxADC) channelProperties = ps.PS6000_TRIGGER_CHANNEL_PROPERTIES(threshold, hysteresis, (threshold * -1), hysteresis, ps.PS6000_CHANNEL["PS6000_CHANNEL_A"], ps.PS6000_THRESHOLD_MODE["PS6000_WINDOW"]) nChannelProperties = 1 auxOutputEnable = 0 autoTriggerMilliseconds = 10000 status["setTriggerChannelProperties"] = ps.ps6000SetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, auxOutputEnable, autoTriggerMilliseconds) assert_pico_ok(status["setTriggerChannelProperties"]) pwqConditions = ps.PS6000_PWQ_CONDITIONS(ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_TRUE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"], ps.PS6000_TRIGGER_STATE["PS6000_CONDITION_DONT_CARE"]) nPwqConditions = 1 direction = ps.PS6000_THRESHOLD_DIRECTION["PS6000_RISING_OR_FALLING"] upper = 390625 #samples at timebase 8 is 10 ms lower = upper type = ps.PS6000_PULSE_WIDTH_TYPE["PS6000_PW_TYPE_GREATER_THAN"] status["setPulseWidthQualifier"] = ps.ps6000SetPulseWidthQualifier(chandle, ctypes.byref(pwqConditions), nPwqConditions, direction, lower, upper, type) assert_pico_ok(status["setPulseWidthQualifier"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 390625*2 postTriggerSamples = 390625 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # oversample = 1 # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps6000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # oversample = 0 # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps6000IsReady rather than ps6000BlockReady) # pParameter = None status["runBlock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 0, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000IsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS6000_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # ratio mode = PS6000_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0) assert_pico_ok(status["setDataBuffersA"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 1 # downsample ratio mode = PS6000_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps6000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 1, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value maxADC = ctypes.c_int16(32512) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value -1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() status["stop"] = ps.ps6000Stop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle ps.ps6000CloseUnit(chandle) # display status returns print(status) ================================================ FILE: ps6000Examples/ps6000BlockExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 BLOCK MODE EXAMPLE # This example opens a 6000 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.ps6000 import ps6000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Set up channel A # handle = chandle # channel = PS6000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS6000_DC = 1 # range = PS6000_2V = 7 # analogue offset = 0 V # bandwidth limiter = PS6000_BW_FULL = 0 chARange = 7 status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS6000_CHANNEL_B = 1 # enabled = 1 # coupling type = PS6000_DC = 1 # range = PS6000_2V = 7 # analogue offset = 0 V # bandwidth limiter = PS6000_BW_FULL = 0 chBRange = 7 status["setChB"] = ps.ps6000SetChannel(chandle, 1, 1, 1, chBRange, 0, 0) assert_pico_ok(status["setChB"]) # Set up single trigger # handle = chandle # enabled = 1 # source = PS6000_CHANNEL_A = 0 # threshold = 64 ADC counts # direction = PS6000_RISING = 2 # delay = 0 s # auto Trigger = 1000 ms status["trigger"] = ps.ps6000SetSimpleTrigger(chandle, 1, 0, 64, 2, 0, 1000) assert_pico_ok(status["trigger"]) # Set number of pre and post trigger samples to be collected preTriggerSamples = 2500 postTriggerSamples = 2500 maxSamples = preTriggerSamples + postTriggerSamples # Get timebase information # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # handle = chandle # timebase = 8 = timebase # noSamples = maxSamples # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns) # oversample = 1 # pointer to maxSamples = ctypes.byref(returnedMaxSamples) # segment index = 0 timebase = 8 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int32() status["getTimebase2"] = ps.ps6000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase2"]) # Run block capture # handle = chandle # number of pre-trigger samples = preTriggerSamples # number of post-trigger samples = PostTriggerSamples # timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases) # oversample = 0 # time indisposed ms = None (not needed in the example) # segment index = 0 # lpReady = None (using ps6000IsReady rather than ps6000BlockReady) # pParameter = None status["runBlock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 0, None, 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000IsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready)) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxSamples)() bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * maxSamples)() bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example # Set data buffer location for data collection from channel A # handle = chandle # source = PS6000_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # ratio mode = PS6000_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS6000_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # ratio mode = PS6000_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps6000SetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0) assert_pico_ok(status["setDataBuffersB"]) # create overflow loaction overflow = ctypes.c_int16() # create converted type maxSamples cmaxSamples = ctypes.c_int32(maxSamples) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 1 # downsample ratio mode = PS6000_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) status["getValues"] = ps.ps6000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 1, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # find maximum ADC count value maxADC = ctypes.c_int16(32512) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC) # Create time data time = np.linspace(0, (cmaxSamples.value -1) * timeIntervalns.value, cmaxSamples.value) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() status["stop"] = ps.ps6000Stop(chandle) assert_pico_ok(status["stop"]) # Close unitDisconnect the scope # handle = chandle ps.ps6000CloseUnit(chandle) # display status returns print(status) ================================================ FILE: ps6000Examples/ps6000GetInfoExample.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 GET INFO EXAMPLE # This example opens a 6000 driver device, gets the variant info and closes the scope. import ctypes import numpy as np from picosdk.ps6000 import ps6000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 series PicoScope # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Get Info from scope string = (ctypes.c_char * 40)() stringLength = ctypes.c_int16(40) requiredSize = ctypes.c_int16(40) info = ps.PICO_INFO["PICO_VARIANT_INFO"] status["getInfo"] = ps.ps6000GetUnitInfo(chandle, ctypes.byref(string),stringLength, ctypes.byref(requiredSize), info) assert_pico_ok(status["getInfo"]) print(string.value) # Close unitDisconnect the scope # handle = chandle ps.ps6000CloseUnit(chandle) # display status returns print(status) ================================================ FILE: ps6000Examples/ps6000RapidBlockExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # ps6000 RAPID BLOCK MODE EXAMPLE # This example opens a 6000 driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps6000 import ps6000 as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Displays the serial number and handle print(chandle.value) # Set up channel A # handle = chandle # channel = ps6000_CHANNEL_A = 0 # enabled = 1 # coupling type = ps6000_DC = 1 # range = ps6000_10V = 8 # analogue offset = 0 V chARange = 8 status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0) assert_pico_ok(status["setChA"]) # Sets up single trigger # Handle = Chandle # Enable = 1 # Source = ps6000_channel_A = 0 # Threshold = 1024 ADC counts # Direction = ps6000_Falling = 3 # Delay = 0 # autoTrigger_ms = 1000 status["trigger"] = ps.ps6000SetSimpleTrigger(chandle, 1, 0, 1024, 3, 0, 1000) assert_pico_ok(status["setChA"]) # Setting the number of sample to be collected preTriggerSamples = 400 postTriggerSamples = 400 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle # Timebase = 2 = timebase # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 2 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps6000GetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Handle = Chandle # nSegments = 10 # nMaxSamples = ctypes.byref(cmaxSamples) status["MemorySegments"] = ps.ps6000MemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) assert_pico_ok(status["MemorySegments"]) # sets number of captures status["SetNoOfCaptures"] = ps.ps6000SetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax1 = (ctypes.c_int16 * maxsamples)() bufferAMin1 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 1 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax2 = (ctypes.c_int16 * maxsamples)() bufferAMin2 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 2 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax3 = (ctypes.c_int16 * maxsamples)() bufferAMin3 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 3 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax4 = (ctypes.c_int16 * maxsamples)() bufferAMin4 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 4 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax5 = (ctypes.c_int16 * maxsamples)() bufferAMin5 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 5 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax6 = (ctypes.c_int16 * maxsamples)() bufferAMin6 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 6 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax7 = (ctypes.c_int16 * maxsamples)() bufferAMin7 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 7 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax8 = (ctypes.c_int16 * maxsamples)() bufferAMin8 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 8 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax9 = (ctypes.c_int16 * maxsamples)() bufferAMin9 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 9 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready)) # Handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps6000GetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # Handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int16*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps6000GetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Finds the max ADC count maxADC = ctypes.c_int16(32512) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value -1) * timeIntervalns.value, cmaxSamples.value) # Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stops the scope # Handle = chandle status["stop"] = ps.ps6000Stop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps6000CloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status) ================================================ FILE: ps6000Examples/ps6000RapidBlockTriggerTimestampExample.py ================================================ # # Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms. # # ps6000 RAPID BLOCK MODE EXAMPLE # This example opens a 6000 driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. # This data is then plotted as mV against time in ns. import ctypes from picosdk.ps6000 import ps6000 as ps import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Displays the serial number and handle print(chandle.value) # Set up channel A # handle = chandle # channel = ps6000_CHANNEL_A = 0 # enabled = 1 # coupling type = ps6000_DC = 1 # range = ps6000_10V = 8 # analogue offset = 0 V chARange = 8 status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0) assert_pico_ok(status["setChA"]) # Sets up single trigger # Handle = Chandle # Enable = 1 # Source = ps6000_channel_A = 0 # Threshold = 1024 ADC counts # Direction = ps6000_Falling = 3 # Delay = 0 # autoTrigger_ms = 1000 status["trigger"] = ps.ps6000SetSimpleTrigger(chandle, 1, 0, 1024, 3, 0, 1000) assert_pico_ok(status["setChA"]) # Setting the number of sample to be collected preTriggerSamples = 400 postTriggerSamples = 400 maxsamples = preTriggerSamples + postTriggerSamples # Gets timebase innfomation # Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope. # To access these Timebases, set any unused analogue channels to off. # Handle = chandle # Timebase = 2 = timebase # Nosample = maxsamples # TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) # MaxSamples = ctypes.byref(returnedMaxSamples) # Segement index = 0 timebase = 2 timeIntervalns = ctypes.c_float() returnedMaxSamples = ctypes.c_int16() status["GetTimebase"] = ps.ps6000GetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["GetTimebase"]) # Creates a overlow location for data overflow = ctypes.c_int16() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Handle = Chandle # nSegments = 10 # nMaxSamples = ctypes.byref(cmaxSamples) status["MemorySegments"] = ps.ps6000MemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) assert_pico_ok(status["MemorySegments"]) # sets number of captures status["SetNoOfCaptures"] = ps.ps6000SetNoOfCaptures(chandle, 10) assert_pico_ok(status["SetNoOfCaptures"]) # Starts the block capture # Handle = chandle # Number of prTriggerSamples # Number of postTriggerSamples # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) # time indisposed ms = None (This is not needed within the example) # Segment index = 0 # LpRead = None # pParameter = None status["runblock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) assert_pico_ok(status["runblock"]) # Create buffers ready for assigning pointers for data collection bufferAMax = (ctypes.c_int16 * maxsamples)() bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 0 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax1 = (ctypes.c_int16 * maxsamples)() bufferAMin1 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 1 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax2 = (ctypes.c_int16 * maxsamples)() bufferAMin2 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 2 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax3 = (ctypes.c_int16 * maxsamples)() bufferAMin3 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 3 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax4 = (ctypes.c_int16 * maxsamples)() bufferAMin4 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 4 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax5 = (ctypes.c_int16 * maxsamples)() bufferAMin5 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 5 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax6 = (ctypes.c_int16 * maxsamples)() bufferAMin6 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 6 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax7 = (ctypes.c_int16 * maxsamples)() bufferAMin7 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 7 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax8 = (ctypes.c_int16 * maxsamples)() bufferAMin8 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 8 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Create buffers ready for assigning pointers for data collection bufferAMax9 = (ctypes.c_int16 * maxsamples)() bufferAMin9 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example # Setting the data buffer location for data collection from channel A # Handle = Chandle # source = ps6000_channel_A = 0 # Buffer max = ctypes.byref(bufferAMax) # Buffer min = ctypes.byref(bufferAMin) # Buffer length = maxsamples # Segment index = 9 # Ratio mode = ps6000_Ratio_Mode_None = 0 status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9, 0) assert_pico_ok(status["SetDataBuffersBulk"]) # Creates a overlow location for data overflow = (ctypes.c_int16 * 10)() # Creates converted types maxsamples cmaxSamples = ctypes.c_int32(maxsamples) # Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready)) # Handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps6000GetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # Handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int16*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps6000GetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Finds the max ADC count maxADC = ctypes.c_int16(32512) # Converts ADC from channel A to mV adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) # Creates the time data time = np.linspace(0, (cmaxSamples.value -1) * timeIntervalns.value, cmaxSamples.value) """# Plots the data from channel A onto a graph plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show()""" # Create the trigger timestamping structure triggerInfo = (ps.PS6000_TRIGGER_INFO * 10)() # Collect time stamp information status["triggerTimes"] = ps.ps6000GetTriggerInfoBulk(chandle, ctypes.byref(triggerInfo), 0, 9) assert_pico_ok(status["triggerTimes"]) # retrieve information from the structure print("segmentIndex") for i in range(0,9): print(triggerInfo[i].segmentIndex) print("status") for i in range(0,9): print(triggerInfo[i].status) print("timeStampCounter") for i in range(0,9): print(triggerInfo[i].timeStampCounter) # Stops the scope # Handle = chandle status["stop"] = ps.ps6000Stop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps6000CloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status) ================================================ FILE: ps6000Examples/ps6000SigGen.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # # PicoScope 6000 Series Signal Generator Example # This example demonstrates how to use the PicoScope 6000 Series (ps6000) driver API functions to 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.ps6000 import ps6000 as ps import time from picosdk.functions import assert_pico_ok # Gives the device a handle status = {} chandle = ctypes.c_int16() # Opens the device/s status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) # Output a sine wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = 0 # pkToPk = 2000000 # waveType = ctypes.c_int16(0) = PS6000_SINE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS6000_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS6000_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS6000_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(0) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps6000SetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with peak-to-peak voltage of 2 V and frequency of 10 kHz # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS6000_SQUARE # startFrequency = 10 kHz # stopFrequency = 10 kHz # increment = 0 # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS6000_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS6000_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS6000_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(0) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps6000SetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 10000, 0, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(10) # Output a square wave with an up-down sweep, 10-100 kHz in 5 kHz increments every 1 second. # handle = chandle # offsetVoltage = -1000000 # pkToPk = 1500000 # waveType = ctypes.c_int16(1) = PS6000_SQUARE # startFrequency = 10 kHz # stopFrequency = 100 kHz # increment = 5 kHz # dwellTime = 1 # sweepType = ctypes.c_int16(1) = PS6000_UP # operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(0) = PS6000_SIGGEN_RISING # triggerSource = ctypes.c_int16(0) = PS6000_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(2) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps6000SetSigGenBuiltIn(chandle, 0, 2000000, wavetype, 10000, 100000, 5000, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # Pauses the script to show signal time.sleep(36) # Closes the unit # Handle = chandle status["close"] = ps.ps6000CloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the status returns print(status) ================================================ FILE: ps6000Examples/ps6000StreamingExample.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 Series STREAMING MODE EXAMPLE # This example demonstrates how to call the ps6000 driver API functions in order to open a device, setup 2 channels and collects streamed data (1 buffer). # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps6000 import ps6000 as ps import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open PicoScope 6000 Series device # Returns handle to chandle for use in future API functions status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) assert_pico_ok(status["openunit"]) enabled = 1 disabled = 0 analogue_offset = 0.0 # Set up channel A # handle = chandle # channel = PS6000_CHANNEL_A = 0 # enabled = 1 # coupling type = PS6000_DC = 1 # range = PS6000_2V = 7 # analogue offset = 0 V channel_range = ps.PS6000_RANGE['PS6000_2V'] status["setChA"] = ps.ps6000SetChannel(chandle, ps.PS6000_CHANNEL['PS6000_CHANNEL_A'], enabled, ps.PS6000_COUPLING['PS6000_DC_1M'], channel_range, analogue_offset, ps.PS6000_BANDWIDTH_LIMITER['PS6000_BW_FULL']) assert_pico_ok(status["setChA"]) # Set up channel B # handle = chandle # channel = PS6000_CHANNEL_B = 1 # enabled = 1 # coupling type = PS6000_DC = 1 # range = PS6000_2V = 7 # analogue offset = 0 V status["setChB"] = ps.ps6000SetChannel(chandle, ps.PS6000_CHANNEL['PS6000_CHANNEL_B'], enabled, ps.PS6000_COUPLING['PS6000_DC_1M'], channel_range, analogue_offset, ps.PS6000_BANDWIDTH_LIMITER['PS6000_BW_FULL']) assert_pico_ok(status["setChB"]) # Size of capture sizeOfOneBuffer = 500 numBuffersToCapture = 10 totalSamples = sizeOfOneBuffer * numBuffersToCapture # Create buffers ready for assigning pointers for data collection bufferAMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) bufferBMax = np.zeros(shape=sizeOfOneBuffer, dtype=np.int16) # Set data buffer location for data collection from channel A # handle = chandle # source = PS6000_CHANNEL_A = 0 # pointer to buffer max = ctypes.byref(bufferAMax) # pointer to buffer min = ctypes.byref(bufferAMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS6000_RATIO_MODE_NONE = 0 status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, ps.PS6000_CHANNEL['PS6000_CHANNEL_A'], bufferAMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, ps.PS6000_RATIO_MODE['PS6000_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersA"]) # Set data buffer location for data collection from channel B # handle = chandle # source = PS6000_CHANNEL_B = 1 # pointer to buffer max = ctypes.byref(bufferBMax) # pointer to buffer min = ctypes.byref(bufferBMin) # buffer length = maxSamples # segment index = 0 # ratio mode = PS6000_RATIO_MODE_NONE = 0 status["setDataBuffersB"] = ps.ps6000SetDataBuffers(chandle, ps.PS6000_CHANNEL['PS6000_CHANNEL_B'], bufferBMax.ctypes.data_as(ctypes.POINTER(ctypes.c_int16)), None, sizeOfOneBuffer, ps.PS6000_RATIO_MODE['PS6000_RATIO_MODE_NONE']) assert_pico_ok(status["setDataBuffersB"]) # Begin streaming mode: sampleInterval = ctypes.c_int32(250) sampleUnits = ps.PS6000_TIME_UNITS['PS6000_US'] # We are not triggering: maxPreTriggerSamples = 0 autoStopOn = 1 # No downsampling: downsampleRatio = 1 status["runStreaming"] = ps.ps6000RunStreaming(chandle, ctypes.byref(sampleInterval), sampleUnits, maxPreTriggerSamples, totalSamples, autoStopOn, downsampleRatio, ps.PS6000_RATIO_MODE['PS6000_RATIO_MODE_NONE'], sizeOfOneBuffer) assert_pico_ok(status["runStreaming"]) actualSampleInterval = sampleInterval.value actualSampleIntervalNs = actualSampleInterval * 1000 print("Capturing at sample interval %s ns" % actualSampleIntervalNs) # We need a big buffer, not registered with the driver, to keep our complete capture in. bufferCompleteA = np.zeros(shape=totalSamples, dtype=np.int16) bufferCompleteB = np.zeros(shape=totalSamples, dtype=np.int16) nextSample = 0 autoStopOuter = False wasCalledBack = False def streaming_callback(handle, noOfSamples, startIndex, overflow, triggerAt, triggered, autoStop, param): global nextSample, autoStopOuter, wasCalledBack wasCalledBack = True destEnd = nextSample + noOfSamples sourceEnd = startIndex + noOfSamples bufferCompleteA[nextSample:destEnd] = bufferAMax[startIndex:sourceEnd] bufferCompleteB[nextSample:destEnd] = bufferBMax[startIndex:sourceEnd] nextSample += noOfSamples if autoStop: autoStopOuter = True # Convert the python function into a C function pointer. cFuncPtr = ps.StreamingReadyType(streaming_callback) # Fetch data from the driver in a loop, copying it out of the registered buffers and into our complete one. while nextSample < totalSamples and not autoStopOuter: wasCalledBack = False status["getStreamingLastestValues"] = ps.ps6000GetStreamingLatestValues(chandle, cFuncPtr, None) if not wasCalledBack: # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying # again. time.sleep(0.01) print("Done grabbing values.") # Find maximum ADC count value # handle = chandle # pointer to value = ctypes.byref(maxADC) maxADC = ctypes.c_int16(32512) # Convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC) adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC) # Create time data time = np.linspace(0, (totalSamples -1) * actualSampleIntervalNs, totalSamples) # Plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Stop the scope # handle = chandle status["stop"] = ps.ps6000Stop(chandle) assert_pico_ok(status["stop"]) # Disconnect the scope # handle = chandle status["close"] = ps.ps6000CloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: ps6000aExamples/ps6000aBlockAdvancedTriggerExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A BLOCK MODE EXAMPLE # This example opens a 6000a 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.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as struct 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 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) channelB = enums.PICO_CHANNEL["PICO_CHANNEL_B"] status["setChannelB"] = ps.ps6000aSetChannelOn(chandle, channelB, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelB"]) # set channel C-H off for x in range (2, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # use the trigger functions seperately # set up a simple edge trigger on channel A OR B with a 100 mV threshold conditions = (struct.PICO_CONDITION * 2)() conditions[0] = struct.PICO_CONDITION(channelA,enums.PICO_TRIGGER_STATE["PICO_CONDITION_TRUE"]) conditions[1] = struct.PICO_CONDITION(channelB, enums.PICO_TRIGGER_STATE["PICO_CONDITION_TRUE"]) nConditions = 2 clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setTriggerChannelConditions"] = ps.ps6000aSetTriggerChannelConditions(chandle, ctypes.byref(conditions), nConditions, action) assert_pico_ok(status["setTriggerChannelConditions"]) directions = (struct.PICO_DIRECTION * 2)() directions[0]= struct.PICO_DIRECTION(channelA, enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"], enums.PICO_THRESHOLD_MODE["PICO_LEVEL"]) directions[1]= struct.PICO_DIRECTION(channelB, enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"], enums.PICO_THRESHOLD_MODE["PICO_LEVEL"]) nDirections = 2 status["setTriggerChannelDirections"] = ps.ps6000aSetTriggerChannelDirections(chandle,ctypes.byref(directions),nDirections) assert_pico_ok(status["setTriggerChannelDirections"]) channelProperties = (struct.PICO_TRIGGER_CHANNEL_PROPERTIES * 2)() channelProperties[0] = struct.PICO_TRIGGER_CHANNEL_PROPERTIES(mV2adc(100,channelRange,maxADC), 0, 0, 0, channelA) channelProperties[1] = struct.PICO_TRIGGER_CHANNEL_PROPERTIES(mV2adc(100,channelRange,maxADC), 0, 0, 0, channelB) nChannelProperties = 2 autoTriggerMicroSeconds = 1000000 status["setTriggerChannelProperties"] = ps.ps6000aSetTriggerChannelProperties(chandle, ctypes.byref(channelProperties),nChannelProperties,0,autoTriggerMicroSeconds) assert_pico_ok(status["setTriggerChannelProperties"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] + enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_B_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.ps6000aGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferBMax = (ctypes.c_int16 * nSamples)() bufferBMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) status["setDataBuffers"] = ps.ps6000aSetDataBuffers(chandle, channelB, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), nSamples, dataType, waveform, downSampleMode, add) assert_pico_ok(status["setDataBuffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) adc2mVChBMax = adc2mV(bufferBMax, channelRange, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChBMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aBlockExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A BLOCK MODE EXAMPLE # This example opens a 6000a 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.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums 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 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps6000aSetSimpleTrigger(chandle, 1, source, (mV2adc(100,channelRange,maxADC)), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.ps6000aGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aBlockExampleExtClk.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000A Demonstrates external clock callback using block mode. # This example opens a 6000a driver device, sets up the External clock callback, and reports its status during a block capture. # Data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums import matplotlib.pyplot as plt from picosdk.functions import adc2mV, mV2adc, assert_pico_ok from picosdk.constants import PICO_STATUS import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # setup External clock callback function wasCalledBack = False ExtRefClk_PicoStatus = enums.PICO_STATUS["PICO_OK"] ExtRefClkReference = enums.PICO_CLOCK_REFERENCE["PICO_INTERNAL_REF"] def ExternalReferenceInteractions_callback(handle, statusCallback, reference): global wasCalledBack, ExtRefClk_PicoStatus, ExtRefClkReference wasCalledBack = True ExtRefClkReference = reference ExtRefClk_PicoStatus = statusCallback # Convert the python function into a C function pointer. cFuncPtrExtClkCB = ps.ExternalReferenceInteractionsReadyType(ExternalReferenceInteractions_callback) # Register the External clock callback status["SetExternalReferenceInteractionCallback"] = ps.ps6000aSetExternalReferenceInteractionCallback(chandle, cFuncPtrExtClkCB) assert_pico_ok(status["SetExternalReferenceInteractionCallback"]) time.sleep(1) if wasCalledBack == True: print("ExtRefClk_PicoStatus = ", ExtRefClk_PicoStatus) print("ExtRefClk_Reference = ", ExtRefClkReference) wasCalledBack = False # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps6000aSetSimpleTrigger(chandle, 1, source, (mV2adc(100,channelRange,maxADC)), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.ps6000aGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) timebase = ctypes.c_uint32(1000) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000aIsReady # Also print any change to the samaple clock source ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) if wasCalledBack == True: print("ExtRefClk_Reference = ", ExtRefClkReference) wasCalledBack = False # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aBlockExampleTrigTimes.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A BLOCK MODE EXAMPLE WITH ALL TRIGGER TIMES # This example opens a 6000a driver device, sets up a channel A and its trigger then collects a block of data. # This data is then plotted as mV against time in ns. # Also the trigger data is plotted as mV against time in ns. (optional) # Addition function calls so all trigger time values are returned correctly. import ctypes import numpy as np from picosdk.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as struct 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 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 3, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps6000aSetSimpleTrigger(chandle, 1, channelA, mV2adc(0,channelRange,maxADC), direction, 0, 0) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.ps6000aGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) print("MinimumTimebase is-") print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 500000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example triggerSamples = 40 # This is always 40 - 20 samples around the trigger point. triggerBuffer = (ctypes.c_int16 * triggerSamples)() # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) timebase = ctypes.c_uint32(50) print("Setting Timebase of-") print("timebase = ", timebase.value) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear | add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) # Setup triggerSamples to get "trigger time offset" values when calling "GetTriggerInfo()" and "GetTriggerTimeOffset" functions. status["setDataBuffers"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(triggerBuffer), ctypes.c_int32(triggerSamples), dataType, waveform, enums.PICO_RATIO_MODE["PICO_RATIO_MODE_TRIGGER"], add) assert_pico_ok(status["setDataBuffers"]) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # Request triggerSamples to get "trigger time offset" values when calling "GetTriggerInfo()" and "GetTriggerTimeOffset" functions. status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(ctypes.c_uint64(triggerSamples)), noOfSamples, enums.PICO_RATIO_MODE["PICO_RATIO_MODE_TRIGGER"], 0, None) assert_pico_ok(status["getValues"]) triggerInfo = (struct.PICO_TRIGGER_INFO * 1)() status["GetTriggerInfo"] = ps.ps6000aGetTriggerInfo(chandle, ctypes.byref(triggerInfo), 0, 1) assert_pico_ok(status["GetTriggerInfo"]) print("TimestampCounter values in samples (only relative timestamps one segment to the next)") # print("Timestamp samples for 2nd segment (index 1, from segment 0 to 1) = ", triggerInfo(1).timeStampCounter) print("Printing triggerInfo for segments-") for i in triggerInfo: print("segmentIndex is ", i.segmentIndex) print("PICO_STATUS is ", i.status) print("triggerIndex is ", i.triggerIndex) print("triggerTime (jitter) is ", i.triggerTime) print("timeUnits is ", i.timeUnits) print("MissedTriggers is ", i.missedTriggers) print("timeStampCounter is ", i.timeStampCounter) print("-------------------------------") timeGTO = ctypes.c_int64(0) timeUnits = ctypes.c_uint32(0) segmentIndex = ctypes.c_uint64(0) status["GetTriggerTimeOffset"] = ps.ps6000aGetTriggerTimeOffset(chandle, ctypes.byref(timeGTO), ctypes.byref(timeUnits), segmentIndex) assert_pico_ok(status["GetTriggerTimeOffset"]) print("Calling GetTriggerTimeOffset() -") print("triggerTime (jitter) is ", timeGTO) print("timeUnits is ", timeUnits) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # plot trigger area data timetrigger = np.linspace(0, (triggerSamples -1) * timeInterval.value * 1000000000, triggerSamples) plt.plot(timetrigger, triggerBuffer[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aBlockMSODigitalTriggerExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A MSO BLOCK MODE DIGITAL TRIGGER EXAMPLE # This example opens a 6000a driver device, sets up one analogue channel and one digital channel and a digital 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.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as struct import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, splitMSODataFast # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # set MSO pod 1 on # handle = chandle port = enums.PICO_CHANNEL["PICO_PORT0"] # logic level needs to be set individually for all digital channels/pins in the port pins = 8 logicThresholdLevel = (ctypes.c_int16 * pins)(0) logicThresholdLevel[0] = 1000 logicThresholdLevelLength = len(logicThresholdLevel) hysteresis = enums.PICO_DIGITAL_PORT_HYSTERESIS["PICO_LOW_50MV"] status["setDigitalPortOn"] = ps.ps6000aSetDigitalPortOn(chandle, port, ctypes.byref(logicThresholdLevel), logicThresholdLevelLength, hysteresis) assert_pico_ok(status["setDigitalPortOn"]) # Set MSO pod 2 off port2 = enums.PICO_CHANNEL["PICO_PORT1"] status["setDigitalPortOff"] = ps.ps6000aSetDigitalPortOff(chandle,port2) assert_pico_ok(status["setDigitalPortOff"]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set trigger on digital channel 0 Port 1 for rising logic level transition conditions = (struct.PICO_CONDITION * 1)() conditions = struct.PICO_CONDITION(enums.PICO_CHANNEL["PICO_PORT0"] , enums.PICO_TRIGGER_STATE["PICO_CONDITION_TRUE"]) nConditions = 1 clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add status["setTriggerChannelConditions"] = ps.ps6000aSetTriggerChannelConditions(chandle, ctypes.byref(conditions),nConditions,action) assert_pico_ok(status["setTriggerChannelConditions"]) directions = (struct.DIGITAL_CHANNEL_DIRECTIONS * 1)() directions = struct.DIGITAL_CHANNEL_DIRECTIONS(enums.PICO_PORT_DIGITAL_CHANNEL["PICO_PORT_DIGITAL_CHANNEL0"],enums.PICO_DIGITAL_DIRECTION["PICO_DIGITAL_DIRECTION_RISING"]) nDirections = 1 status["setTriggerDigitalPortProperties"] = ps.ps6000aSetTriggerDigitalPortProperties(chandle,port,ctypes.byref(directions),nDirections) assert_pico_ok(status["setTriggerDigitalPortProperties"]) # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Check timebase is valid # handle = chandle timebase = ctypes.c_uint32(1) timeInterval = ctypes.c_double(0) returnedMaxSamples=ctypes.c_uint64() #segment = 0 status["getTimebase"] = ps.ps6000aGetTimebase(chandle, timebase, nSamples, ctypes.byref(timeInterval), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase"]) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "ns") # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferDPort0Max = (ctypes.c_int16 * nSamples)() bufferDPort0Min = (ctypes.c_int16 * nSamples)() # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataChABuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataChABuffers"]) status["setDataDP0Buffers"] = ps.ps6000aSetDataBuffers(chandle, port, ctypes.byref(bufferDPort0Max), ctypes.byref(bufferDPort0Min), nSamples, dataType, waveform, downSampleMode, add) assert_pico_ok(status["setDataDP0Buffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). bufferDPort0 = splitMSODataFast(noOfSamples, bufferDPort0Max) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.figure(num='Channel A Data') plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.title('Channel A data') #plt.show() # Plot the data from digital channels onto a graph plt.figure(num='Digital Port 0 Data') plt.title('Plot of Digital Port 0 digital channels vs. time') plt.plot(time, bufferDPort0[0], label='D7') # D7 is the first array in the tuple. plt.plot(time, bufferDPort0[1], label='D6') plt.plot(time, bufferDPort0[2], label='D5') plt.plot(time, bufferDPort0[3], label='D4') plt.plot(time, bufferDPort0[4], label='D3') plt.plot(time, bufferDPort0[5], label='D2') plt.plot(time, bufferDPort0[6], label='D1') plt.plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. plt.xlabel('Time (ns)') plt.ylabel('Logic Level') plt.legend(loc="upper right") plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aBlockMSOExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A BLOCK MODE EXAMPLE # This example opens a 6000a 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.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, splitMSODataFast # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # set MSO pod 1 on # handle = chandle port = enums.PICO_CHANNEL["PICO_PORT0"] # logic level needs to be set individually for all digital channels/pins in the port pins = 8 logicThresholdLevel = (ctypes.c_int16 * pins)(0) logicThresholdLevel[0] = 1000 logicThresholdLevelLength = len(logicThresholdLevel) hysteresis = enums.PICO_DIGITAL_PORT_HYSTERESIS["PICO_LOW_50MV"] status["setDigitalPortOn"] = ps.ps6000aSetDigitalPortOn(chandle, port, ctypes.byref(logicThresholdLevel), logicThresholdLevelLength, hysteresis) assert_pico_ok(status["setDigitalPortOn"]) # Set MSO pod 2 off port2 = enums.PICO_CHANNEL["PICO_PORT1"] status["setDigitalPortOff"] = ps.ps6000aSetDigitalPortOff(chandle,port2) assert_pico_ok(status["setDigitalPortOff"]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps6000aSetSimpleTrigger(chandle, 1, source, (mV2adc(100,channelRange,maxADC), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Check timebase is valid # handle = chandle timebase = ctypes.c_uint32(1) timeInterval = ctypes.c_double(0) returnedMaxSamples=ctypes.c_uint64() #segment = 0 status["getTimebase"] = ps.ps6000aGetTimebase(chandle, timebase, nSamples, ctypes.byref(timeInterval), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase"]) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "ns") # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferDPort0Max = (ctypes.c_int16 * nSamples)() bufferDPort0Min = (ctypes.c_int16 * nSamples)() # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataChABuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataChABuffers"]) status["setDataDP0Buffers"] = ps.ps6000aSetDataBuffers(chandle, port, ctypes.byref(bufferDPort0Max), ctypes.byref(bufferDPort0Min), nSamples, dataType, waveform, downSampleMode, add) assert_pico_ok(status["setDataDP0Buffers"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). bufferDPort0 = splitMSODataFast(noOfSamples, bufferDPort0Max) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.figure(num='Channel A Data') plt.plot(time, adc2mVChAMax[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.title('Channel A data') #plt.show() # Plot the data from digital channels onto a graph plt.figure(num='Digital Port 0 Data') plt.title('Plot of Digital Port 0 digital channels vs. time') plt.plot(time, bufferDPort0[0], label='D7') # D7 is the first array in the tuple. plt.plot(time, bufferDPort0[1], label='D6') plt.plot(time, bufferDPort0[2], label='D5') plt.plot(time, bufferDPort0[3], label='D4') plt.plot(time, bufferDPort0[4], label='D3') plt.plot(time, bufferDPort0[5], label='D2') plt.plot(time, bufferDPort0[6], label='D1') plt.plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. plt.xlabel('Time (ns)') plt.ylabel('Logic Level') plt.legend(loc="upper right") plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aBlock_both_MSOExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A BLOCK MODE EXAMPLE # This example opens a 6000a 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.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as struct import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, splitMSODataFast # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # set channel A-H off for x in range (0, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # set MSO pod 1 on # handle = chandle port_0 = enums.PICO_CHANNEL["PICO_PORT0"] # logic level needs to be set individually for all digital channels/pins in the port pins = 8 logicThresholdLevel = (ctypes.c_int16 * pins)(0) logicThresholdLevel[0] = 6400 # ~1.5v logicThresholdLevelLength = len(logicThresholdLevel) hysteresis = enums.PICO_DIGITAL_PORT_HYSTERESIS["PICO_LOW_50MV"] status["setDigitalPortOn"] = ps.ps6000aSetDigitalPortOn(chandle, port_0, ctypes.byref(logicThresholdLevel), logicThresholdLevelLength, hysteresis) assert_pico_ok(status["setDigitalPortOn"]) # set MSO pod 2 on # handle = chandle port_1 = enums.PICO_CHANNEL["PICO_PORT1"] # logic level needs to be set individually for all digital channels/pins in the port pins = 8 logicThresholdLevel_upper = (ctypes.c_int16 * pins)(0) logicThresholdLevel_upper[0] = 6400 #~1.5v logicThresholdLevel_upperLength = len(logicThresholdLevel) hysteresis = enums.PICO_DIGITAL_PORT_HYSTERESIS["PICO_LOW_50MV"] status["setDigitalPortOn"] = ps.ps6000aSetDigitalPortOn(chandle, port_1, ctypes.byref(logicThresholdLevel_upper), logicThresholdLevel_upperLength, hysteresis) assert_pico_ok(status["setDigitalPortOn"]) # Set trigger on digital channel 0 Port 1 for rising logic level transition conditions = (struct.PICO_CONDITION * 1)() conditions = struct.PICO_CONDITION(enums.PICO_CHANNEL["PICO_PORT0"] , enums.PICO_TRIGGER_STATE["PICO_CONDITION_TRUE"]) nConditions = 1 clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add action_post = add status["setTriggerChannelConditions"] = ps.ps6000aSetTriggerChannelConditions(chandle, ctypes.byref(conditions),nConditions,action) assert_pico_ok(status["setTriggerChannelConditions"]) directions = (struct.DIGITAL_CHANNEL_DIRECTIONS * 1)() directions = struct.DIGITAL_CHANNEL_DIRECTIONS(enums.PICO_PORT_DIGITAL_CHANNEL["PICO_PORT_DIGITAL_CHANNEL0"],enums.PICO_DIGITAL_DIRECTION["PICO_DIGITAL_DIRECTION_RISING"]) nDirections = 1 status["setTriggerDigitalPortProperties"] = ps.ps6000aSetTriggerDigitalPortProperties(chandle,port_0,ctypes.byref(directions),nDirections) assert_pico_ok(status["setTriggerDigitalPortProperties"]) # Set number of samples to be collected noOfPreTriggerSamples = 25000 noOfPostTriggerSamples = 0 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Check timebase is valid # handle = chandle timebase = ctypes.c_uint32(1) timeInterval = ctypes.c_double(0) returnedMaxSamples=ctypes.c_uint64() #segment = 0 status["getTimebase"] = ps.ps6000aGetTimebase(chandle, timebase, nSamples, ctypes.byref(timeInterval), ctypes.byref(returnedMaxSamples), 0) assert_pico_ok(status["getTimebase"]) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "ns") # Create buffers bufferDPort0 = (ctypes.c_int16 * nSamples)() bufferDPort0Max = (ctypes.c_int16 * nSamples)() bufferDPort0Min = (ctypes.c_int16 * nSamples)() bufferDPort1 = (ctypes.c_int16 * nSamples)() bufferDPort1Max = (ctypes.c_int16 * nSamples)() bufferDPort1Min = (ctypes.c_int16 * nSamples)() # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] #dataType_MSO = enums.PICO_DATA_TYPE["PICO_INT8_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] status["setDataDP0Buffer"] = ps.ps6000aSetDataBuffers(chandle, port_0, ctypes.byref(bufferDPort0Max), ctypes.byref(bufferDPort0Min), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataDP0Buffer"]) status["setDataDP1Buffer"] = ps.ps6000aSetDataBuffers( chandle, port_1, ctypes.byref(bufferDPort1Max), ctypes.byref(bufferDPort1Min), nSamples, dataType, waveform, downSampleMode, action_post) assert_pico_ok(status["setDataDP1Buffer"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock( chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps5000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 overflow = ctypes.c_int16(0) status["getValues"] = ps.ps6000aGetValues( chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # # Obtain binary for Digital Port 0 # # The tuple returned contains the channels in order (D7, D6, D5, ... D0). # bufferDPort0 = splitMSODataFast(noOfSamples, bufferDPort0) # bufferDPort1 = splitMSODataFast(noOfSamples, bufferDPort1) # Obtain binary for Digital Port 0 # The tuple returned contains the channels in order (D7, D6, D5, ... D0). bufferDPort0 = splitMSODataFast(noOfSamples, bufferDPort0Max) bufferDPort1 = splitMSODataFast(noOfSamples, bufferDPort1Max) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) #MinMax plot fig, axs = plt.subplots(2) fig.suptitle("MSO data") # Plot the data from digital channels onto a graph axs[0].plot(time, bufferDPort0[0], label='D7') # D7 is the first array in the tuple. axs[0].plot(time, bufferDPort0[1], label='D6') axs[0].plot(time, bufferDPort0[2], label='D5') axs[0].plot(time, bufferDPort0[3], label='D4') axs[0].plot(time, bufferDPort0[4], label='D3') axs[0].plot(time, bufferDPort0[5], label='D2') axs[0].plot(time, bufferDPort0[6], label='D1') axs[0].plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. axs[0].legend(loc="upper right") #plt.show() # Plot the data from digital channels onto a graph axs[1].plot(time, bufferDPort1[0], label='D15') # D7 is the first array in the tuple. axs[1].plot(time, bufferDPort1[1], label='D14') axs[1].plot(time, bufferDPort1[2], label='D13') axs[1].plot(time, bufferDPort1[3], label='D12') axs[1].plot(time, bufferDPort1[4], label='D11') axs[1].plot(time, bufferDPort1[5], label='D10') axs[1].plot(time, bufferDPort1[6], label='D9') axs[1].plot(time, bufferDPort1[7], label='D8') # D0 is the last array in the tuple. axs[1].legend(loc="upper right") plt.xlabel('Time (ns)') plt.ylabel('Logic Level') plt.show() # fig, axs = plt.subplots(2) # fig.suptitle("MSO data") # # Plot the data from digital channels onto a graph # axs[0].plot(time, bufferDPort0[0], label='D7') # D7 is the first array in the tuple. # axs[0].plot(time, bufferDPort0[1], label='D6') # axs[0].plot(time, bufferDPort0[2], label='D5') # axs[0].plot(time, bufferDPort0[3], label='D4') # axs[0].plot(time, bufferDPort0[4], label='D3') # axs[0].plot(time, bufferDPort0[5], label='D2') # axs[0].plot(time, bufferDPort0[6], label='D1') # axs[0].plot(time, bufferDPort0[7], label='D0') # D0 is the last array in the tuple. # axs[0].legend(loc="upper right") # #plt.show() # # Plot the data from digital channels onto a graph # axs[1].plot(time, bufferDPort1[0], label='D15') # D7 is the first array in the tuple. # axs[1].plot(time, bufferDPort1[1], label='D14') # axs[1].plot(time, bufferDPort1[2], label='D13') # axs[1].plot(time, bufferDPort1[3], label='D12') # axs[1].plot(time, bufferDPort1[4], label='D11') # axs[1].plot(time, bufferDPort1[5], label='D10') # axs[1].plot(time, bufferDPort1[6], label='D9') # axs[1].plot(time, bufferDPort1[7], label='D8') # D0 is the last array in the tuple. # axs[1].legend(loc="upper right") # plt.xlabel('Time (ns)') # plt.ylabel('Logic Level') # plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aGetUnitInfo.py ================================================ # # Copyright (C) 2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A GET UNIT INFO EXAMPLE # This example opens a 6000a driver device, collects the model and serial nubmber from the device and closes the device. import ctypes import numpy as np from picosdk.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.functions import assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Get unit info modelNum = ctypes.create_string_buffer(6) modelNumString = ctypes.cast(modelNum,ctypes.c_char_p) stringLength = len(modelNum) requiredSize = ctypes.c_int16(stringLength) infoModel= 0x03 status["getUnitInfo_Model"] = ps.ps6000aGetUnitInfo(chandle, modelNumString,stringLength,ctypes.byref(requiredSize),infoModel) assert_pico_ok(status["getUnitInfo_Model"]) print(modelNum.value) SN = ctypes.create_string_buffer(b"AA000/0000") SNString = ctypes.cast(SN,ctypes.c_char_p) stringLength = len(SN) requiredSize = ctypes.c_int16(stringLength) infoSN = 0x04 status["getUnitInfo_SN"] = ps.ps6000aGetUnitInfo(chandle, SNString,stringLength,ctypes.byref(requiredSize),infoSN) assert_pico_ok(status["getUnitInfo_SN"]) print(SN.value) # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aRapidBlockExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A BLOCK MODE EXAMPLE # This example opens a 6000a driver device, sets up two channels and a trigger then collects 10 blocks of data in rapid block mode. # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as struct import matplotlib.pyplot as plt from picosdk.functions import mV2adc, adc2mV, assert_pico_ok # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) # set channel B-H off for x in range (1, 7, 1): channel = x status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel) assert_pico_ok(status["setChannel",x]) # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps6000aSetSimpleTrigger(chandle, 1, source, mV2adc(100,channelRange,maxADC), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # Get fastest available timebase # handle = chandle enabledChannelFlags = enums.PICO_CHANNEL_FLAGS["PICO_CHANNEL_A_FLAGS"] timebase = ctypes.c_uint32(0) timeInterval = ctypes.c_double(0) # resolution = resolution status["getMinimumTimebaseStateless"] = ps.ps6000aGetMinimumTimebaseStateless(chandle, enabledChannelFlags, ctypes.byref(timebase), ctypes.byref(timeInterval), resolution) assert_pico_ok(status["getMinimumTimebaseStateless"]) print("timebase = ", timebase.value) print("sample interval =", timeInterval.value, "s") # Set number of samples to be collected noOfPreTriggerSamples = 500000 noOfPostTriggerSamples = 1000000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # Set number of memory segments noOfCaptures = 10 maxSegments = ctypes.c_uint64(10) status["memorySegments"] = ps.ps6000aMemorySegments(chandle, noOfCaptures, ctypes.byref(maxSegments)) assert_pico_ok(status["memorySegments"]) # Set number of captures status["setNoOfCaptures"] = ps.ps6000aSetNoOfCaptures(chandle, noOfCaptures) assert_pico_ok(status["setNoOfCaptures"]) # Create buffers bufferAMax = (ctypes.c_int16 * nSamples)() bufferAMin = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax1 = (ctypes.c_int16 * nSamples)() bufferAMin1 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax2 = (ctypes.c_int16 * nSamples)() bufferAMin2 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax3 = (ctypes.c_int16 * nSamples)() bufferAMin3 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax4 = (ctypes.c_int16 * nSamples)() bufferAMin4 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax5 = (ctypes.c_int16 * nSamples)() bufferAMin5 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax6 = (ctypes.c_int16 * nSamples)() bufferAMin6 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax7 = (ctypes.c_int16 * nSamples)() bufferAMin7 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax8 = (ctypes.c_int16 * nSamples)() bufferAMin8 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example bufferAMax9 = (ctypes.c_int16 * nSamples)() bufferAMin9 = (ctypes.c_int16 * nSamples)() # used for downsampling which isn't in the scope of this example # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] status["setDataBuffers"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffers"]) waveform1 = 1 status["setDataBuffers1"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), nSamples, dataType, waveform1, downSampleMode, add) assert_pico_ok(status["setDataBuffers1"]) waveform2 = 2 status["setDataBuffers2"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), nSamples, dataType, waveform2, downSampleMode, add) assert_pico_ok(status["setDataBuffers2"]) waveform3 = 3 status["setDataBuffers3"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), nSamples, dataType, waveform3, downSampleMode, add) assert_pico_ok(status["setDataBuffers3"]) waveform4 = 4 status["setDataBuffers4"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), nSamples, dataType, waveform4, downSampleMode, add) assert_pico_ok(status["setDataBuffers4"]) waveform5 = 5 status["setDataBuffers5"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), nSamples, dataType, waveform5, downSampleMode, add) assert_pico_ok(status["setDataBuffers5"]) waveform6 = 6 status["setDataBuffers6"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), nSamples, dataType, waveform6, downSampleMode, add) assert_pico_ok(status["setDataBuffers6"]) waveform7 = 7 status["setDataBuffers7"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), nSamples, dataType, waveform7, downSampleMode, add) assert_pico_ok(status["setDataBuffers7"]) waveform8 = 8 status["setDataBuffers8"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), nSamples, dataType, waveform8, downSampleMode, add) assert_pico_ok(status["setDataBuffers8"]) waveform9 = 9 status["setDataBuffers9"] = ps.ps6000aSetDataBuffers(chandle, channelA, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), nSamples, dataType, waveform9, downSampleMode, add) assert_pico_ok(status["setDataBuffers9"]) # Run block capture # handle = chandle # timebase = timebase timeIndisposedMs = ctypes.c_double(0) # segmentIndex = 0 # lpReady = None Using IsReady rather than a callback # pParameter = None status["runBlock"] = ps.ps6000aRunBlock(chandle, noOfPreTriggerSamples, noOfPostTriggerSamples, timebase, ctypes.byref(timeIndisposedMs), 0, None, None) assert_pico_ok(status["runBlock"]) # Check for data collection to finish using ps6000aIsReady ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps6000aIsReady(chandle, ctypes.byref(ready)) # Get data from scope # handle = chandle # startIndex = 0 noOfSamples = ctypes.c_uint64(nSamples) # downSampleRatio = 1 # segmentIndex = 0 # Creates a overflow location for each segment overflow = (ctypes.c_int16 * 10)() status["getValues"] = ps.ps6000aGetValuesBulk(chandle, 0, ctypes.byref(noOfSamples),0, 9, 1, downSampleMode, ctypes.byref(overflow)) assert_pico_ok(status["getValues"]) # Handle = chandle # triggerInfo = (struct.PICO_TRIGGER_INFO * 10)() # Fromsegmentindex = 0 # Tosegementindex = 9 triggerInfo = (struct.PICO_TRIGGER_INFO * 10)() status["GetTriggerInfo"] = ps.ps6000aGetTriggerInfo(chandle, ctypes.byref(triggerInfo), 0, 10) assert_pico_ok(status["GetTriggerInfo"]) print("TimestampCounter values in samples (only relative timestamps one segment to the next)") # print("Timestamp samples for 2nd segment (index 1, from segment 0 to 1) = ", triggerInfo(1).timeStampCounter) print("Printing triggerInfo for segments-") for i in triggerInfo: print("segmentIndex is ", i.segmentIndex) print("PICO_STATUS is ", i.status) # print("triggerIndex is ", i.triggerIndex) # print("triggerTime is ", i.triggerTime) # print("timeUnits is ", i.timeUnits) print("timeStampCounter is ", i.timeStampCounter) print("-------------------------------") # convert ADC counts data to mV adc2mVChAMax = adc2mV(bufferAMax, channelRange, maxADC) adc2mVChAMax1 = adc2mV(bufferAMax1, channelRange, maxADC) adc2mVChAMax2 = adc2mV(bufferAMax2, channelRange, maxADC) adc2mVChAMax3 = adc2mV(bufferAMax3, channelRange, maxADC) adc2mVChAMax4 = adc2mV(bufferAMax4, channelRange, maxADC) adc2mVChAMax5 = adc2mV(bufferAMax5, channelRange, maxADC) adc2mVChAMax6 = adc2mV(bufferAMax6, channelRange, maxADC) adc2mVChAMax7 = adc2mV(bufferAMax7, channelRange, maxADC) adc2mVChAMax8 = adc2mV(bufferAMax8, channelRange, maxADC) adc2mVChAMax9 = adc2mV(bufferAMax9, channelRange, maxADC) # Create time data time = np.linspace(0, (nSamples -1) * timeInterval.value * 1000000000, nSamples) # plot data from channel A and B plt.plot(time, adc2mVChAMax[:]) plt.plot(time, adc2mVChAMax1[:]) plt.plot(time, adc2mVChAMax2[:]) plt.plot(time, adc2mVChAMax3[:]) plt.plot(time, adc2mVChAMax4[:]) plt.plot(time, adc2mVChAMax5[:]) plt.plot(time, adc2mVChAMax6[:]) plt.plot(time, adc2mVChAMax7[:]) plt.plot(time, adc2mVChAMax8[:]) plt.plot(time, adc2mVChAMax9[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aSigGenExample.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A SIGNAL GENERATOR EXAMPLE # This example opens a 6000a driver device, sets 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 import numpy as np from picosdk.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.functions import adc2mV, assert_pico_ok import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set signal generator waveform # handle = chandle wavetype = enums.PICO_WAVE_TYPE["PICO_SINE"] bufferlength = 1000 buffer = (ctypes.c_int16 * bufferlength)() status["sigGenWaveform"] = ps.ps6000aSigGenWaveform(chandle, wavetype, ctypes.byref(buffer), bufferlength) assert_pico_ok(status["sigGenWaveform"]) # Set signal generator range # handle = chandle peakToPeakVolts = 2 offsetVolts = 0 status["sigGenRange"] = ps.ps6000aSigGenRange(chandle, peakToPeakVolts, offsetVolts) assert_pico_ok(status["sigGenRange"]) # Set signal generator duty cycle # handle = chandle dutyCyclePercent = 50 status["sigGenDutyCycle"] = ps.ps6000aSigGenWaveformDutyCycle(chandle, dutyCyclePercent) assert_pico_ok(status["sigGenDutyCycle"]) # Set signal generator frequency # handle = chandle frequencyHz = 1000 status["sigGenFreq"] = ps.ps6000aSigGenFrequency(chandle, frequencyHz) assert_pico_ok(status["sigGenFreq"]) # Apply signal generator settings # handle = chandle sigGenEnabled = 1 sweepEnabled = 0 triggerEnabled = 0 automaticClockOptimisationEnabled = 0 overrideAutomaticClockAndPrescale = 0 frequency = ctypes.c_int16(frequencyHz) #stopFrequency = None #frequencyIncrement = None #dwellTime = None status["sigGenApply"] = ps.ps6000aSigGenApply(chandle, sigGenEnabled, sweepEnabled, triggerEnabled, automaticClockOptimisationEnabled, overrideAutomaticClockAndPrescale, ctypes.byref(frequency), None, None, None ) assert_pico_ok(status["sigGenApply"]) time.sleep(5) # Pause signal generator # handle = chandle status["sigGenPause"] = ps.ps6000aSigGenPause(chandle) assert_pico_ok(status["sigGenPause"]) time.sleep(5) # Resume signal generator # handle = chandle status["sigGenRestart"] = ps.ps6000aSigGenRestart(chandle) assert_pico_ok(status["sigGenRestart"]) time.sleep(5) # Pause signal generator # handle = chandle status["sigGenPause"] = ps.ps6000aSigGenPause(chandle) assert_pico_ok(status["sigGenPause"]) # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: ps6000aExamples/ps6000aStreamingModeExample.py ================================================ # # Copyright (C) 2020-2024 Pico Technology Ltd. See LICENSE file for terms. # # PS6000 A STREAMING MODE EXAMPLE # This example opens a 6000a driver device, sets up one channel then collects a streamed set of data. # This data is then plotted as mV against time in ns. import ctypes import numpy as np from picosdk.ps6000a import ps6000a as ps from picosdk.PicoDeviceEnums import picoEnum as enums from picosdk.PicoDeviceStructs import picoStruct as structs import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok, mV2adc from picosdk.constants import PICO_STATUS import time # Create chandle and status ready for use chandle = ctypes.c_int16() status = {} # Open 6000 A series PicoScope # returns handle to chandle for use in future API functions resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_8BIT"] status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution) assert_pico_ok(status["openunit"]) # Set channel A on # handle = chandle channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"] coupling = enums.PICO_COUPLING["PICO_DC_50OHM"] channelRange = 5 # analogueOffset = 0 V bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"] status["setChannelA"] = ps.ps6000aSetChannelOn(chandle, channelA, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelA"]) channelB = enums.PICO_CHANNEL["PICO_CHANNEL_B"] status["setChannelB"] = ps.ps6000aSetChannelOn(chandle, channelB, coupling, channelRange, 0, bandwidth) assert_pico_ok(status["setChannelB"]) # set channel C-H off for x in range(2, 7, 1): channel = x status["setChannel", x] = ps.ps6000aSetChannelOff(chandle, channel) assert_pico_ok(status["setChannel", x]) # Set number of samples to be collected noOfPreTriggerSamples = 100000 noOfPostTriggerSamples = 900000 nSamples = noOfPostTriggerSamples + noOfPreTriggerSamples # get max ADC value # handle = chandle minADC = ctypes.c_int16() maxADC = ctypes.c_int16() status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC)) assert_pico_ok(status["getAdcLimits"]) # Set simple trigger on channel A, 1 V rising with 1 s autotrigger # handle = chandle # enable = 1 source = channelA # threshold = 100 mV direction = enums.PICO_THRESHOLD_DIRECTION["PICO_RISING"] # delay = 0 s # autoTriggerMicroSeconds = 1000000 us status["setSimpleTrigger"] = ps.ps6000aSetSimpleTrigger(chandle, 1, source, (mV2adc(100,channelRange,maxADC)), direction, 0, 1000000) assert_pico_ok(status["setSimpleTrigger"]) # create buffers maxBuffers = 10 bufferA = ((ctypes.c_int16 * nSamples) * 10)() bufferB = ((ctypes.c_int16 * nSamples) * 10)() # Set data buffers # handle = chandle # channel = channelA # bufferMax = bufferAMax # bufferMin = bufferAMin # nSamples = nSamples dataType = enums.PICO_DATA_TYPE["PICO_INT16_T"] waveform = 0 downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"] clear = enums.PICO_ACTION["PICO_CLEAR_ALL"] add = enums.PICO_ACTION["PICO_ADD"] action = clear | add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"] actionAdd = add status["setDataBuffersA"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[0]), nSamples, dataType, waveform, downSampleMode, action) assert_pico_ok(status["setDataBuffersA"]) status["setDataBuffersB"] = ps.ps6000aSetDataBuffer(chandle, channelB, ctypes.byref(bufferB[0]), nSamples, dataType, waveform, downSampleMode, actionAdd) assert_pico_ok(status["setDataBuffersB"]) # Run streaming sampleInterval = ctypes.c_double(1) sampleIntervalTimeUnits = enums.PICO_TIME_UNITS["PICO_US"] autoStop = 0 downSampleRatio = 1 status["runStreaming"] = ps.ps6000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleIntervalTimeUnits, noOfPreTriggerSamples, noOfPostTriggerSamples, autoStop, downSampleRatio, downSampleMode) assert_pico_ok(status["runStreaming"]) streamData = (structs.PICO_STREAMING_DATA_INFO * 2)() streamData[0] = structs.PICO_STREAMING_DATA_INFO(channelA, downSampleMode, dataType, 0, 0, 0, 0) streamData[1] = structs.PICO_STREAMING_DATA_INFO(channelB, downSampleMode, dataType, 0, 0, 0, 0) streamTrigger = structs.PICO_STREAMING_DATA_TRIGGER_INFO(0, 0, 0) count = 0 picoOk = PICO_STATUS["PICO_OK"] collectedSamples = 0 while collectedSamples < (maxBuffers*nSamples): status["getStreamingLatestValues"] = ps.ps6000aGetStreamingLatestValues(chandle, ctypes.byref(streamData), 1, ctypes.byref(streamTrigger)) if status["getStreamingLatestValues"] == picoOk: # do nothing time.sleep(0.01) else: count = count + 1 if count < maxBuffers: status["setDataBufferA"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[count]), nSamples, dataType, waveform, downSampleMode, actionAdd) assert_pico_ok(status["setDataBufferA"]) status["setDataBufferB"] = ps.ps6000aSetDataBuffer(chandle, channelB, ctypes.byref(bufferB[count]), nSamples, dataType, waveform, downSampleMode, actionAdd) assert_pico_ok(status["setDataBufferB"]) print(count) collectedSamples = collectedSamples + streamData[0].noOfSamples # stop scope streaming status["stop"] = ps.ps6000aStop(chandle) assert_pico_ok(status["stop"]) # get total number of streamed data points noOfStreamedSamples=ctypes.c_uint64() status["noOfStreamedSamples"] = ps.ps6000aNoOfStreamingValues(chandle, ctypes.byref(noOfStreamedSamples)) assert_pico_ok(status["noOfStreamedSamples"]) print("streaming finished") print("Number of samples collected during streaming") print(noOfStreamedSamples.value) # convert ADC counts data to mV bufferAmV = [] for k in range (0, maxBuffers, 1): mvValues = adc2mV(bufferA[k], channelRange, maxADC) bufferAmV.append(mvValues) time = np.linspace(0, ((nSamples -1)*maxBuffers) * sampleInterval.value * 1000000, (nSamples*maxBuffers)) startTime = 0 endTime = nSamples # plot ADC data for h in range (0, maxBuffers, 1): plt.plot(time[startTime:endTime],bufferAmV[h]) startTime += nSamples endTime += nSamples # plt.xlabel('Time (us)') # plt.ylabel('Voltage (mV)') # plt.show() # Close the scope status["closeunit"] = ps.ps6000aCloseUnit(chandle) assert_pico_ok(status["closeunit"]) print(status) ================================================ FILE: pt104Examples/pt104DirectEthernet.py ================================================ # # Copyright (C) 2026 Pico Technology Ltd. See LICENSE file for terms. # # PT-104 DIRECT ETHERNET EXAMPLE (NO SDK) # ###################################################################### """ Pure‑Ethernet PT‑104 client – mode. Assumptions (as you confirmed): * The PT‑104 has already been configured (via usb with picolog app) to output temperature directly. * The configuration is 4 channels with PT100 4 wires with average enabled. * No SDK/DLL is used – everything is done with raw UDP packets. """ import socket import struct import time import threading import codecs # ---------------------------------------------------------------------- # --------------------------- USER SETTINGS ---------------------------- # ---------------------------------------------------------------------- DEVICE_IP = "172.26.178.124" # ← change if needed DEVICE_PORT = 1 # listening port reported by the PT‑104 DEVICE_ADDR = (DEVICE_IP, DEVICE_PORT) # Lookup table for Resistance (Ohms) to Temperature (Celsius) # Format: (Temperature, Resistance) RESISTANCE_TEMP_LOOKUP = [ (-50, 80.306282), (-49, 80.703340), (-48, 81.100257), (-47, 81.497036), (-46, 81.893677), (-45, 82.290179), (-44, 82.686545), (-43, 83.082774), (-42, 83.478868), (-41, 83.874827), (-40, 84.270652), (-39, 84.666343), (-38, 85.061901), (-37, 85.457327), (-36, 85.852622), (-35, 86.247785), (-34, 86.642818), (-33, 87.037721), (-32, 87.432495), (-31, 87.827140), (-30, 88.221657), (-29, 88.616046), (-28, 89.010309), (-27, 89.404445), (-26, 89.798455), (-25, 90.192339), (-24, 90.586099), (-23, 90.979734), (-22, 91.373246), (-21, 91.766634), (-20, 92.159898), (-19, 92.553041), (-18, 92.946061), (-17, 93.338960), (-16, 93.731737), (-15, 94.124394), (-14, 94.516930), (-13, 94.909346), (-12, 95.301643), (-11, 95.693820), (-10, 96.085879), (-9, 96.477819), (-8, 96.869641), (-7, 97.261345), (-6, 97.652931), (-5, 98.044401), (-4, 98.435753), (-3, 98.826989), (-2, 99.218109), (-1, 99.609112), (0, 100.000000), (1, 100.390772), (2, 100.781429), (3, 101.171970), (4, 101.562396), (5, 101.952706), (6, 102.342901), (7, 102.732980), (8, 103.122944), (9, 103.512792), (10, 103.902525), (11, 104.292142), (12, 104.681644), (13, 105.071030), (14, 105.460301), (15, 105.849456), (16, 106.238496), (17, 106.627420), (18, 107.016229), (19, 107.404922), (20, 107.793500), (21, 108.181962), (22, 108.570309), (23, 108.958540), (24, 109.346656), (25, 109.734656), (26, 110.122541), (27, 110.510310), (28, 110.897964), (29, 111.285502), (30, 111.672925), (31, 112.060232), (32, 112.447424), (33, 112.834500), (34, 113.221461), (35, 113.608306), (36, 113.995036), (37, 114.381650), (38, 114.768149), (39, 115.154532), (40, 115.540800), (41, 115.926952), (42, 116.312989), (43, 116.698910), (44, 117.084716), (45, 117.470406), (46, 117.855981), (47, 118.241440), (48, 118.626784), (49, 119.012012), (50, 119.397125), (51, 119.782122), (52, 120.167004), (53, 120.551770), (54, 120.936421), (55, 121.320956), (56, 121.705376), (57, 122.089680), (58, 122.473869), (59, 122.857942), (60, 123.241900), (61, 123.625742), (62, 124.009469), (63, 124.393080), (64, 124.776576), (65, 125.159956), (66, 125.543221), (67, 125.926370), (68, 126.309404), (69, 126.692322), (70, 127.075125), (71, 127.457812), (72, 127.840384), (73, 128.222840), (74, 128.605181), (75, 128.987406), (76, 129.369516), (77, 129.751510), (78, 130.133389), (79, 130.515152), (80, 130.896800), (81, 131.278332), (82, 131.659749), (83, 132.041050), (84, 132.422236), (85, 132.803306), (86, 133.184261), (87, 133.565100), (88, 133.945824), (89, 134.326432), (90, 134.706925), (91, 135.087302), (92, 135.467564), (93, 135.847710), (94, 136.227741), (95, 136.607656), (96, 136.987456), (97, 137.367140), (98, 137.746709), (99, 138.126162), (100, 138.505500), (101, 138.884722), (102, 139.263829), (103, 139.642820), (104, 140.021696), (105, 140.400456), (106, 140.779101), (107, 141.157630), (108, 141.536044), (109, 141.914342), (110, 142.292525), (111, 142.670592), (112, 143.048544), (113, 143.426380), (114, 143.804101), (115, 144.181706), (116, 144.559196), (117, 144.936570), (118, 145.313829), (119, 145.690972), (120, 146.068000), (121, 146.444912), (122, 146.821709), (123, 147.198390), (124, 147.574956), (125, 147.951406), (126, 148.327741), (127, 148.703960), (128, 149.080064), (129, 149.456052), (130, 149.831925), (131, 150.207682), (132, 150.583324), (133, 150.958850), (134, 151.334261), (135, 151.709556), (136, 152.084736), (137, 152.459800), (138, 152.834749), (139, 153.209582), (140, 153.584300), (141, 153.958902), (142, 154.333389), (143, 154.707760), (144, 155.082016), (145, 155.456156), (146, 155.830181), (147, 156.204090), (148, 156.577884), (149, 156.951562), (150, 157.325125), (151, 157.698572), (152, 158.071904), (153, 158.445120), (154, 158.818221), (155, 159.191206), (156, 159.564076), (157, 159.936830), (158, 160.309469), (159, 160.681992), (160, 161.054400), (161, 161.426692), (162, 161.798869), (163, 162.170930), (164, 162.542876), (165, 162.914706), (166, 163.286421), (167, 163.658020), (168, 164.029504), (169, 164.400872), (170, 164.772125), (171, 165.143262), (172, 165.514284), (173, 165.885190), (174, 166.255981), (175, 166.626656), (176, 166.997216), (177, 167.367660), (178, 167.737989), (179, 168.108202), (180, 168.478300), (181, 168.848282), (182, 169.218149), (183, 169.587900), (184, 169.957536), (185, 170.327056), (186, 170.696461), (187, 171.065750), (188, 171.434924), (189, 171.803982), (190, 172.172925), (191, 172.541752), (192, 172.910464), (193, 173.279060), (194, 173.647541), (195, 174.015906), (196, 174.384156), (197, 174.752290), (198, 175.120309), (199, 175.488212), (200, 175.856000) ] # Define a dictionary to hold the structured "Data" variables based on the memory map data_variables = { "Reserved_1": None, "Batch": None, "Calibration_Date": None, "Ch1_Calibration": None, "Ch2_Calibration": None, "Ch3_Calibration": None, "Ch4_Calibration": None, "MAC_Address": None, "Reserved_2": None, "Checksum": None, "status": "empty" } # Define a dictionary to hold measurement packet data measurement_data = { "Channel_1": [0, 0, 0, 0], # Indices 00-03 "Channel_2": [0, 0, 0, 0], # Indices 04-07 "Channel_3": [0, 0, 0, 0], # Indices 08-0B "Channel_4": [0, 0, 0, 0] # Indices 0C-0F } # ---------------------------------------------------------------------- def interpolate_temperature(resistance): """ Performs linear interpolation on the RESISTANCE_TEMP_LOOKUP table. """ if resistance is None or resistance == 0: return None # Sort the table just in case (though it is provided sorted by temp) # We need it sorted by Resistance for searching table = sorted(RESISTANCE_TEMP_LOOKUP, key=lambda x: x[1]) # Handle cases outside the table range (extrapolation) if resistance <= table[0][1]: p1, p2 = table[0], table[1] elif resistance >= table[-1][1]: p1, p2 = table[-2], table[-1] else: # Find the two points to interpolate between p1, p2 = None, None for i in range(len(table) - 1): if table[i][1] <= resistance <= table[i+1][1]: p1, p2 = table[i], table[i+1] break # Linear Interpolation Formula: y = y1 + (x - x1) * ((y2 - y1) / (x2 - x1)) # y = Temperature, x = Resistance t1, r1 = p1 t2, r2 = p2 temperature = t1 + (resistance - r1) * ((t2 - t1) / (r2 - r1)) return temperature def get_channel_temperatures(resistances): """ Converts a dictionary of resistances to temperatures. """ temps = {} for ch, res in resistances.items(): temps[ch] = interpolate_temperature(res) return temps def calculate_resistances(eeprom_vars, measurements): """ Calculates resistance (in MOhms) for each channel using the formula: result = ((cal * (m3 - m2)) / (m1 - m0)) / 1,000,000 """ results = {} # Mapping EEPROM calibration keys to measurement storage keys channels = [ ("Channel_1", "Ch1_Calibration"), ("Channel_2", "Ch2_Calibration"), ("Channel_3", "Ch3_Calibration"), ("Channel_4", "Ch4_Calibration") ] for m_key, c_key in channels: cal = eeprom_vars.get(c_key) m = measurements.get(m_key) # Ensure we have the calibration and measurement data if cal is None or m is None: results[m_key] = None continue try: # Formula updated to divide by 1,000,000 for Ohms numerator = cal * (m[3] - m[2]) denominator = (m[1] - m[0]) if denominator == 0: print(f"Warning: Division by zero for {m_key} (m1 - m0 = 0).") results[m_key] = 0.0 else: # Calculate and convert to Ohms results[m_key] = (numerator / denominator) / 1_000_000.0 except Exception as e: print(f"Error calculating {m_key}: {e}") results[m_key] = None return results def parse_pkt_data(pkt, storage): """ Parses a 'pkt' variable containing indexed 32-bit values. Format: [Index Byte] [4 Bytes Data (MSB First)] """ if not isinstance(pkt, bytes): print("Error: pkt must be of type 'bytes'") return # Process packet in chunks of 5 bytes (1 index + 4 data) for i in range(0, len(pkt), 5): chunk = pkt[i:i+5] if len(chunk) < 5: break index = chunk[0] # Convert 4 bytes to integer (Big Endian / MSB First as specified) value = int.from_bytes(chunk[1:5], byteorder='big') # Map indices to the appropriate channel array if 0x00 <= index <= 0x03: storage["Channel_1"][index] = value elif 0x04 <= index <= 0x07: storage["Channel_2"][index - 4] = value elif 0x08 <= index <= 0x0B: storage["Channel_3"][index - 8] = value elif 0x0C <= index <= 0x0F: storage["Channel_4"][index - 12] = value print(f"Success: Parsed packet data into measurement storage.") def parse_and_store_data(raw_input, data_store): """ Parses a bytes object or string by stripping the command prefix and correcting escape sequences to reach the 128-byte payload. """ #print(f"DEBUG1:{raw_input!r}") # 1. Convert input to bytes if isinstance(raw_input, str): # latin-1 preserves byte-value integrity for characters 0-255 raw_bytes = raw_input.encode('latin-1') elif isinstance(raw_input, bytes): raw_bytes = raw_input else: print("Error: Input must be a bytes object or string.") return #print(f"DEBUG2:{raw_bytes!r}") # 2. Extract Data after the '=' prefix if b'=' in raw_bytes: data_payload = raw_bytes.split(b'=', 1)[1] else: data_payload = raw_bytes #print(f"DEBUG3: {data_payload!r}") # 3. Fix literal escaping (e.g., b'\\x00' -> b'\x00') try: if b'\\' in data_payload: data_payload = codecs.escape_decode(data_payload)[0] except Exception as e: print(f"Warning during unescape: {e}") # 4. Final Alignment and Validation actual_len = len(data_payload) if actual_len < 128: data_payload = data_payload.ljust(128, b'\x00') elif actual_len > 128: data_payload = data_payload[:128] #print(f"DEBUG4: {data_payload!r}") try: # Helper to decode ASCII and strip null/whitespace def decode_text(b_slice): return b_slice.decode('ascii', errors='ignore').split('\x00')[0].strip() # Helper for LSB-first 4-byte integers (Little Endian) def to_int_lsb(b_slice): return int.from_bytes(b_slice, byteorder='little') # --- Adjusted Parsing Alignment --- # 0 to 19: Reserved data_store["Reserved_1"] = data_payload[0:19].hex().upper() # 19 to 29: Batch (10 bytes) data_store["Batch"] = decode_text(data_payload[19:29]) # 29 to 37: Calibration Date (8 bytes) data_store["Calibration_Date"] = decode_text(data_payload[29:37]) # 37 to 53: 4 Channels @ 4 bytes each data_store["Ch1_Calibration"] = to_int_lsb(data_payload[37:41]) data_store["Ch2_Calibration"] = to_int_lsb(data_payload[41:45]) data_store["Ch3_Calibration"] = to_int_lsb(data_payload[45:49]) data_store["Ch4_Calibration"] = to_int_lsb(data_payload[49:53]) # 53 to 59: MAC Address (6 bytes) mac_bytes = data_payload[53:59] data_store["MAC_Address"] = ":".join(f"{b:02x}" for b in mac_bytes).upper() # 59 to 126: Reserved data_store["Reserved_2"] = data_payload[59:126].hex().upper() # 126 to 128: Checksum data_store["Checksum"] = data_payload[126:128].hex().upper() data_store["status"] = "parsed_successfully" print(f"Success: Parsed {len(data_payload)} bytes using adjusted offsets.") except Exception as e: data_store["status"] = "error_parsing" print(f"Error during parsing: {e}") # ---------------------------------------------------------------------- # UDP helpers # ---------------------------------------------------------------------- def udp_send(sock: socket.socket, payload: bytes, addr): """Send a UDP packet.""" sock.sendto(payload, addr) def udp_recv(sock: socket.socket, timeout: float = 2.0) -> bytes: """Receive a UDP packet; return empty bytes on timeout.""" sock.settimeout(timeout) try: data, _ = sock.recvfrom(4096) return data except socket.timeout: return b"" # ---------------------------------------------------------------------- # Keep‑alive thread (0x34) – required every ≤ 15 s # ---------------------------------------------------------------------- def start_keep_alive(sock: socket.socket, dest): """Continuously send 0x34 (keep‑alive) every ~9 s.""" def loop(): while True: udp_send(sock, b"\x34", dest) # 0x34 = Keep‑alive time.sleep(9) # a little under 10 s t = threading.Thread(target=loop, daemon=True) t.start() return t # ---------------------------------------------------------------------- # Lock the device (ASCII "lock") and interpret the reply # ---------------------------------------------------------------------- def lock_device(sock: socket.socket, dest) -> bool: LOCK_CMD = b"lock" # ASCII lock command per the manual udp_send(sock, LOCK_CMD, dest) reply = udp_recv(sock, timeout=2.0) if not reply: print("⚠️ No reply to lock request – proceeding anyway.") return False txt = reply.decode(errors="ignore").lower() if "lock success" in txt: if "already locked" in txt: print("ℹ️ Device already locked to this machine.") else: print("✅ Lock acquired successfully.") return True else: print(f"⚠️ Lock request failed / unexpected reply: {reply!r}") return False # ---------------------------------------------------------------------- # Send the “read_EEPROM” command (0x32 ) # ---------------------------------------------------------------------- def read_EEPROM(sock: socket.socket, dest): """ 0x32 = read_EEPROM """ START_CMD = b'\x32' udp_send(sock, START_CMD, dest) # Optional diagnostic reply (usually “Converting”) resp = udp_recv(sock, timeout=1.0) if resp: temp = resp.decode(errors="ignore").lower() # 2. Parse and store into our variables if "eeprom=" in temp: print("✅ read_EEPROM started – done") else: print(f"ℹ️ Unexpected read_EEPROM reply: {resp!r}") else: print("⚠️ No immediate reply to read_EEPROM command (still OK).") parse_and_store_data(resp, data_variables) # 3. Display results print("\n--- Parsed EEPROM data ---") for key, value in data_variables.items(): if key != "status": print(f"{key.replace('_', ' '):<20}: {value}") # ---------------------------------------------------------------------- # Send the “mains rejection” command (0x30, 0x00 ) # ---------------------------------------------------------------------- def mains_rejection(sock: socket.socket, dest): """ 0x30 = mains_rejection command 0x00 = For 50Hz """ START_CMD = b'\x30\x00' udp_send(sock, START_CMD, dest) # Optional diagnostic reply (usually “Converting”) resp = udp_recv(sock, timeout=1.0) if resp: txt = resp.decode(errors="ignore").lower() if "" in txt: print("✅ mains rejection started OK") else: print(f"ℹ️ Unexpected mains rejection reply: {resp!r}") else: print("⚠️ No immediate reply to mains rejection command (still OK).") # ---------------------------------------------------------------------- # Send the “start converting” command (0x31 0x0F) # ---------------------------------------------------------------------- def start_converting(sock: socket.socket, dest): """ 0x31 = start converting 0x0F = enable channels 1‑4 (bits 0‑3 = 1) and gain ×1 (bits 4‑7 = 0) """ START_CMD = b'\x31\x0F' udp_send(sock, START_CMD, dest) # Optional diagnostic reply (usually “Converting”) resp = udp_recv(sock, timeout=1.0) if resp: txt = resp.decode(errors="ignore").lower() if "converting" in txt: print("✅ Converter started – data will now stream.") else: print(f"ℹ️ Unexpected start‑convert reply: {resp!r}") else: print("⚠️ No immediate reply to start‑convert command (still OK).") # ---------------------------------------------------------------------- # Main routine – receive raw temperature packets and print °C # ---------------------------------------------------------------------- def main(): # -------------------------------------------------------------- # 0️⃣ Create a UDP socket (bind to any free local port) # -------------------------------------------------------------- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(("", 0)) # OS picks a free local port # -------------------------------------------------------------- # 1️⃣ Lock the device # -------------------------------------------------------------- have_lock = lock_device(sock, DEVICE_ADDR) # -------------------------------------------------------------- # 2️⃣ Set read_EEPROM # -------------------------------------------------------------- read_EEPROM(sock, DEVICE_ADDR) # -------------------------------------------------------------- # 2️⃣ Set mains_rejection # -------------------------------------------------------------- mains_rejection(sock, DEVICE_ADDR) # -------------------------------------------------------------- # 2️⃣ Tell the logger to start converting (stream data) # -------------------------------------------------------------- start_converting(sock, DEVICE_ADDR) # -------------------------------------------------------------- # 3️⃣ Start keep‑alive (required whether we own the lock or not) # -------------------------------------------------------------- start_keep_alive(sock, DEVICE_ADDR) print(f"✅ Keep‑alive started (0x34 every ~9 s) → {DEVICE_IP}:{DEVICE_PORT}") print("\nWaiting for streamed data… (Ctrl‑C to stop)\n") # -------------------------------------------------------------- # 4️⃣ Receive and decode measurement packets # -------------------------------------------------------------- try: while True: pkt = udp_recv(sock, timeout=3.0) if not pkt: continue # -------------------------------------------------- # a) Discard any textual packets (Lock replies, Alive, etc.) # -------------------------------------------------- if pkt.startswith(b'PT104') or pkt.startswith(b'Lock') or pkt.startswith(b'Alive'): continue # -------------------------------------------------- # b) Binary measurement data: 5 bytes per channel # -------------------------------------------------- if len(pkt) < 20: # 4 channels × 5 bytes = 20 bytes # Incomplete packet – ignore it. continue parse_pkt_data(pkt, measurement_data) # Display raw channel data # print("\n--- Measurement Packet Results ---") # for channel, vals in measurement_data.items(): # print(f"{channel:<20}: {vals}") # Calculate Results res_results = calculate_resistances(data_variables, measurement_data) print("\n--- Calculated Resistances (Ohms) ---") for channel, res in res_results.items(): if res is not None: print(f"{channel:<20}: {res:.6f} Ohms") else: print(f"{channel:<20}: Data Missing") # Convert to Temperature temperatures = get_channel_temperatures(res_results) print("\n--- Temperature Results (Celsius) ---") for ch, temp in temperatures.items(): if temp is not None: print(f"{ch:<20}: {temp:.2f} °C") else: print(f"{ch:<20}: Invalid Data") # The logger up dates # roughly every 720 ms per active channel. time.sleep(0.5) except KeyboardInterrupt: print("\n🛑 Stopped by user.") finally: # ---------------------------------------------------------- # Optional: cleanly unlock the device if we own the lock # ---------------------------------------------------------- if have_lock: udp_send(sock, b"lock", DEVICE_ADDR) # sending “lock” again releases it print("🔓 Unlock command sent.") sock.close() if __name__ == "__main__": main() ================================================ FILE: pt104Examples/pt104EnumerateTestsExample.py ================================================ # # Copyright (C) 2025 Pico Technology Ltd. See LICENSE file for terms. # # PT104 Example # This example opens a pt104, sets up a single channel and collects data before closing the pt104 import ctypes from picosdk.usbPT104 import usbPt104 as pt104 import numpy as np from picosdk.functions import assert_pico_ok from time import sleep import matplotlib.pyplot as plt # Create status ready for use status = {} # Setup Enumerating function data types Enumerate_string = ctypes.create_string_buffer(b"------------------------------------------------------------------") EnumUnitString = ctypes.cast(Enumerate_string,ctypes.c_char_p) stringLength = len(Enumerate_string) requiredSize = ctypes.c_uint32(stringLength) unit_connection_method = pt104.COMMUNICATION_TYPE["CT_USB"] print("Enumerating Unit(s)...") status["EnumerateUnit"] = pt104.UsbPt104Enumerate(EnumUnitString, ctypes.byref(requiredSize) , unit_connection_method ) assert_pico_ok(status["EnumerateUnit"]) print("serial number(s) are-") print(EnumUnitString.value) # Create variables for unit handles chandle = ctypes.c_int16() chandle2 = ctypes.c_int16() # Open the device print("Opening device...") status["openUnit"] = pt104.UsbPt104OpenUnit(ctypes.byref(chandle),0) assert_pico_ok(status["openUnit"]) print("handle is: ", chandle) SN = ctypes.create_string_buffer(b"AA000/0000") SNString = ctypes.cast(SN,ctypes.c_char_p) stringLength = len(SN) requiredSize = ctypes.c_int16(stringLength) infoSN = 0x04 status["getUnitInfo_SN"] = pt104.UsbPt104GetUnitInfo(chandle, SNString,stringLength,ctypes.byref(requiredSize),infoSN) assert_pico_ok(status["getUnitInfo_SN"]) print("Serial number is...") print(SN.value) # Open the 2nd device print("Opening the 2nd device...") status["openUnit"] = pt104.UsbPt104OpenUnit(ctypes.byref(chandle2),0) assert_pico_ok(status["openUnit"]) print("handle is: ", chandle2) status["getUnitInfo_SN"] = pt104.UsbPt104GetUnitInfo(chandle2, SNString,stringLength,ctypes.byref(requiredSize),infoSN) assert_pico_ok(status["getUnitInfo_SN"]) print("Serial number is...") print(SN.value) # Close the unit(s) print("Closing Unit(s)...") status["closeUnit"] = pt104.UsbPt104CloseUnit(chandle) assert_pico_ok(status["closeUnit"]) status["closeUnit"] = pt104.UsbPt104CloseUnit(chandle2) assert_pico_ok(status["closeUnit"]) print(status) ================================================ FILE: pt104Examples/pt104Example.py ================================================ # # Copyright (C) 2022 Pico Technology Ltd. See LICENSE file for terms. # # PT104 Example # This example opens a pt104, sets up a single channel and collects data before closing the pt104 import ctypes from picosdk.usbPT104 import usbPt104 as pt104 import numpy as np from picosdk.functions import assert_pico_ok from time import sleep import matplotlib.pyplot as plt # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Open the device status["openUnit"] = pt104.UsbPt104OpenUnit(ctypes.byref(chandle),0) assert_pico_ok(status["openUnit"]) # Set mains noise filtering sixty_hertz = 0 #50 Hz status["setMains"] = pt104.UsbPt104SetMains(chandle, sixty_hertz) assert_pico_ok(status["setMains"]) # Setup channel 1 channel = pt104.PT104_CHANNELS["USBPT104_CHANNEL_1"] #channel 1 datatype = pt104.PT104_DATA_TYPE["USBPT104_PT100"] #pt100 noOfWires = 4 #wires status["setChannel1"] = pt104.UsbPt104SetChannel(chandle, channel, datatype, noOfWires) assert_pico_ok(status["setChannel1"]) #collect data print("collecting data") numSamples = 20 data = (ctypes.c_int32 * numSamples)() for i in range(numSamples): #pause sleep(2) # Get values measurement = ctypes.c_int32() filtered = 1 # true status["getValue"] = pt104.UsbPt104GetValue(chandle, channel, ctypes.byref(measurement), filtered) assert_pico_ok(status["getValue"]) data[i] = measurement.value samples = np.linspace(0, numSamples*2, numSamples) dataTemp = [x /1000 for x in data] plt.plot(samples, dataTemp) plt.xlabel('Time (s)') plt.ylabel('Temperature ($^o$C)') plt.show() # Close the device status["closeUnit"] = pt104.UsbPt104CloseUnit(chandle) assert_pico_ok(status["closeUnit"]) print(status) ================================================ FILE: requirements-for-examples.txt ================================================ matplotlib>=1.5.3 toml>=0.10.2 ================================================ FILE: requirements.txt ================================================ numpy>=1.12.1 ================================================ FILE: setup.py ================================================ # # Copyright (C) 2017-2018 Pico Technology Ltd. # from __future__ import print_function from setuptools import setup import ctypes from ctypes import * from ctypes.util import find_library import sys import os.path signalfile = ".sdkwarning" atleast1dll = 0 if not os.path.exists(signalfile): for name in ['ps2000', 'ps3000', 'ps4000', 'ps5000', 'ps2000a', 'ps3000a', 'ps4000a', 'ps5000a', 'ps6000a', 'ps6000', 'psospa']: try: if sys.platform == 'win32': result = ctypes.WinDLL(find_library(name)) else: result = cdll.LoadLibrary(find_library(name)) atleast1dll = 1 except OSError: print(f"Warning: PicoSDK installation is missing {name}.dll") if not atleast1dll: print("Please install the PicoSDK in order to use this wrapper." "Visit https://www.picotech.com/downloads") exit(1) open(signalfile, 'a').close() with open("README.md") as f: readme = f.read() setup( name='picosdk', packages=['picosdk'], install_requires=["numpy>=1.12.1"], version='1.0', description='PicoSDK Python wrapper', long_description=readme, author='Pico Technology Ltd', author_email='support@picotech.com', license="ISC", url='https://www.picotech.com', classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Science/Research", "License :: OSI Approved :: ISC License (ISCL)", "Natural Language :: English", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering", ], ) ================================================ FILE: setupPicosynth.py ================================================ # # Copyright (C) 2017-2018 Pico Technology Ltd. # from __future__ import print_function from distutils.core import setup import ctypes from ctypes import * from ctypes.util import find_library import sys import os.path signalfile = ".sdkwarning" if not os.path.exists(signalfile): name = 'picosynth' try: if sys.platform == 'win32': result = ctypes.WinDLL(find_library(name)) print(result) else: result = cdll.LoadLibrary(find_library(name)) except OSError: print("Please install PicoSynth software in order to use this wrapper." "Visit https://www.picotech.com/downloads") exit(1) open(signalfile, 'a').close() setup(name='PicoSDK', version='1.0', description='PicoSDK Python wrapper', author='Pico Technology Ltd', author_email='support@picotech.com', url='https://www.picotech.com', packages=['picosdk']) ================================================ FILE: test/__init__.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # ================================================ FILE: test/run_examples.sh ================================================ #! /bin/bash cd "${BASH_SOURCE%/*}" || exit FILE_ERRORS="" NEWLINE=$'\n' for file in ../ps*Examples/* do if [[ -f $file ]]; then echo $file PYTHONPATH=`pwd`/.. python $file if [ $? -ne 0 ]; then FILE_ERRORS="$FILE_ERRORS$file$NEWLINE" fi fi done echo $FILE_ERRORS if [ -z "$FILE_ERRORS" ]; then exit 0 fi exit 1 ================================================ FILE: test/test_discover.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Unit tests for the wrapper functions for discovering devices """ from __future__ import print_function from test.test_helpers import DriverTest, drivers_with_device_connected from picosdk.device import Device from picosdk.errors import DeviceNotFoundError import picosdk.discover as dut class OpenCloseTest(DriverTest): def test_find_unit_success(self): """test_find_unit_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return device = dut.find_unit() try: self.assertIsInstance(device, Device) self.assertIn(device.driver.name, drivers_with_device_connected) finally: device.close() def test_find_all_units_success(self): """test_find_all_units_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return devices = dut.find_all_units() try: for device in devices: self.assertIsInstance(device, Device) self.assertIn(device.driver.name, drivers_with_device_connected) self.assertEqual(set(device.driver.name for device in devices), set(drivers_with_device_connected)) finally: for device in devices: device.close() def test_find_unit_failure(self): devices = [] threw = False try: while len(devices) <= len(drivers_with_device_connected): devices.append(dut.find_unit()) except DeviceNotFoundError: threw = True finally: for device in devices: device.close() self.assertEqual(len(drivers_with_device_connected), len(devices)) self.assertTrue(threw) def test_find_all_units_failure(self): devices = [] threw = False try: devices = dut.find_all_units() dut.find_all_units() except DeviceNotFoundError: threw = True finally: for device in devices: device.close() self.assertTrue(threw) ================================================ FILE: test/test_get_unit_info.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Unit tests for the wrapper function for retrieving device information. """ from __future__ import print_function from test.test_helpers import DriverTest, drivers_with_device_connected from picosdk.errors import DeviceNotFoundError, ArgumentOutOfRangeError try: STRING_TYPES = (str, unicode) except: STRING_TYPES = (bytes, str) class GetInfoTest(DriverTest): def test_get_info_success(self): """test_get_info_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): devices = [] try: devices.append(driver.open_unit()) except DeviceNotFoundError: return "no device found." device = devices.pop() info = driver.get_unit_info(device) device.close() self.assertEqual(info.driver, driver) self.assertIsInstance(info.variant, STRING_TYPES) self.assertIsInstance(info.serial, STRING_TYPES) self.run_snippet_and_count_problems(drivers_to_use, test) def test_get_info_advanced_success(self): """test_get_info_advanced_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): devices = [] try: devices.append(driver.open_unit()) except DeviceNotFoundError: return "no device found." device = devices.pop() # three keys present on ALL devices. info = driver.get_unit_info(device, "PICO_DRIVER_VERSION", "PICO_USB_VERSION", "PICO_HARDWARE_VERSION") device.close() self.assertEqual(len(info), 3) self.assertIsInstance(info.PICO_DRIVER_VERSION, STRING_TYPES) self.assertIsInstance(info.PICO_USB_VERSION, STRING_TYPES) self.assertIsInstance(info.PICO_HARDWARE_VERSION, STRING_TYPES) self.run_snippet_and_count_problems(drivers_to_use, test) def test_get_info_with_invalid_key_fails(self): """test_get_info_advanced_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): devices = [] try: devices.append(driver.open_unit()) except DeviceNotFoundError: return "no device found." device = devices.pop() threw = False try: # some valid and some invalid keys. People may pass PICO_CAL_DATE to ps2000 etc. info = driver.get_unit_info(device, "PICO_DRIVER_VERSION", "aillk_jasgKLASDFG_Jlasdkgfj", "PICO_HARDWARE_VERSION") except ArgumentOutOfRangeError: threw = True finally: device.close() if not threw: return "get_unit_info didn't throw exception on bad key." self.run_snippet_and_count_problems(drivers_to_use, test) ================================================ FILE: test/test_helpers.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Helper methods for tests, and test configuration information. """ import importlib as _importlib import unittest as _unittest drivers_to_load = [ 'ps2000', 'ps2000a', 'ps3000', 'ps3000a', 'ps4000', 'ps4000a', 'ps5000a', 'ps6000', ] modules = {} for _d in drivers_to_load: modules[_d] = _importlib.import_module("picosdk.%s" % _d) # PLEASE MODIFY this list before running, to indicate which drivers should # expect to find a device. drivers_with_device_connected = [ # 'ps2000', # 'ps2000a', # 'ps3000', # 'ps3000a', # 'ps4000', # 'ps4000a', # 'ps5000a', # 'ps6000', ] class TestFailAndError(Exception): pass class TestError(Exception): pass class DriverTest(_unittest.TestCase): @staticmethod def _find_driver(name): # e.g. ps2000.ps2000 m = modules[name] return getattr(m, name) def run_snippet_and_count_problems(self, drivers_to_use, fn): errors = [] failures = [] for d in drivers_to_use: driver = self._find_driver(d) try: result = fn(driver) if result is not None: failures.append((d, result)) except Exception as e: errors.append((d, e)) # format the errors and failure messages for printing: errors = ", ".join(["%s (%r)" % e for e in errors]) failures = ", ".join(["%s (%s)" % f for f in failures]) if failures and errors: raise TestFailAndError("drivers error'd: %s\nand drivers failed: %s" % (errors, failures)) elif errors: raise TestError("drivers error'd: %s" % errors) else: self.assertEqual(len(failures), 0, "Drivers failed: %s" % failures) ================================================ FILE: test/test_open_close_unit.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Unit tests for the wrapper functions for opening and closing devices. """ from __future__ import print_function from test.test_helpers import DriverTest, drivers_to_load, drivers_with_device_connected from picosdk.errors import DeviceNotFoundError class OpenCloseTest(DriverTest): def test_open_unit_failure(self): """test_open_unit_failure note: test assumes that at maximum one device is attached for each driver.""" drivers_to_use = drivers_to_load def test(driver): threw = False devices = [] try: devices.append(driver.open_unit()) devices.append(driver.open_unit()) except DeviceNotFoundError: threw = True finally: for device in devices: device.close() if not threw: return "didn't throw a DeviceNotFoundError." self.run_snippet_and_count_problems(drivers_to_use, test) def test_open_unit_success(self): """test_open_unit_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected[:] def test(driver): threw = False devices = [] try: devices.append(driver.open_unit()) except DeviceNotFoundError as e: threw = e finally: for device in devices: print("closing device %s" % device.handle) device.close() if threw is not False: return "no device found (%s)." % threw self.run_snippet_and_count_problems(drivers_to_use, test) def test_close_unit_success(self): """test_close_unit_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): devices = [] try: devices.append(driver.open_unit()) except DeviceNotFoundError as e: return "no device found (%s)." % e device = devices.pop() info = device.info device.close() # To test the success of close(), we try to re-open the device. # If we fail, then we have not closed it correctly. try: devices.append(driver.open_unit(serial=info.serial)) except DeviceNotFoundError as e: return "Could not close and then re-open the device (%s)." % e finally: for device in devices: device.close() self.run_snippet_and_count_problems(drivers_to_use, test) def test_with_statement_open_close(self): """test_with_statement_open_close note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected[:] def test(driver): threw = False was_open = False was_closed = False outer_scope_device = None try: with driver.open_unit() as device: was_open = device.is_open outer_scope_device = device was_closed = not outer_scope_device.is_open except DeviceNotFoundError as e: threw = e finally: if outer_scope_device is not None and not was_closed: outer_scope_device.close() if threw is not False: return "no device found (%s)." % threw elif not was_open: return "device was not opened correctly" elif not was_closed: return "device was not closed after exiting the scope" self.run_snippet_and_count_problems(drivers_to_use, test) ================================================ FILE: test/test_set_channel.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Unit tests for the wrapper functions for configuring channels """ from __future__ import print_function from test.test_helpers import DriverTest, drivers_with_device_connected from picosdk.errors import ArgumentOutOfRangeError from picosdk.device import ChannelConfig class SetChannelTest(DriverTest): # Both 3000a and 5000a define a 50V enum member, but neither actually has a device which # supports that range. max_volts_by_driver = { "ps2000": 20, "ps2000a": 20, "ps3000": 400, "ps3000a": 20, "ps4000": 100, "ps4000a": 50, "ps5000a": 20, } def test_set_channel_success(self): """test_set_channel_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): expected_max_volts = self.max_volts_by_driver[driver.name] with driver.open_unit() as device: config = ChannelConfig(name='A', enabled=True, coupling='DC', range_peak=expected_max_volts) actual_max_voltage = device.set_channel(config) self.assertEqual(expected_max_volts, actual_max_voltage) self.run_snippet_and_count_problems(drivers_to_use, test) def test_set_channel_very_small_peak(self): if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected # Some drivers specify more ranges than some of their devices actually support. Check that we handle this error # at the lowest voltages (at the upper range, see the relevant test below, there's nothing we can do but raise.) def test(driver): five_millivolts = 0.005 with driver.open_unit() as device: config = ChannelConfig(name='A', enabled=True, coupling='DC', range_peak=five_millivolts) actual_max_voltage = device.set_channel(config) self.assertGreaterEqual(actual_max_voltage, five_millivolts) self.run_snippet_and_count_problems(drivers_to_use, test) def test_set_channel_range_too_large(self): """test_set_channel_range_too_large note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): with driver.open_unit() as device: threw = False try: driver.set_channel(device, range_peak=float('inf')) except ArgumentOutOfRangeError: threw = True if not threw: return "didn't throw an ArgumentOutOfRangeError." self.run_snippet_and_count_problems(drivers_to_use, test) ================================================ FILE: test/test_timebase.py ================================================ # # Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. # """ Unit tests for the wrapper functions for computing and validating timebases """ from __future__ import print_function from test.test_helpers import DriverTest, drivers_with_device_connected import unittest from picosdk.library import TimebaseInfo from picosdk.errors import InvalidTimebaseError, NoValidTimebaseForOptionsError from picosdk.device import Device, TimebaseOptions import math class FindTimebaseTest(DriverTest): def assertValidTimebases(self, input_config, output_info): if input_config.max_time_interval is not None: self.assertLessEqual(output_info.time_interval, input_config.max_time_interval) if input_config.no_of_samples is not None: self.assertGreaterEqual(output_info.max_samples, input_config.no_of_samples) if input_config.min_collection_time is not None: self.assertGreaterEqual(output_info.time_interval * output_info.max_samples, input_config.min_collection_time) def test_find_timebase_success(self): """test_find_timebase_success note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): with driver.open_unit() as device: five_milliseconds = 0.005 config = TimebaseOptions(max_time_interval=five_milliseconds, no_of_samples=None, min_collection_time=five_milliseconds * 30, oversample=1) timebase_info = device.find_timebase(config) self.assertValidTimebases(config, timebase_info) self.run_snippet_and_count_problems(drivers_to_use, test) def test_find_timebase_terrasample(self): """test_find_timebase_terrasample note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): with driver.open_unit() as device: threw = False try: # we ask for a config which requires 1TS (one terra-sample) of memory on device. smallest_timebase = 1.e-8 one_terra_sample = 1.e12 duration = smallest_timebase * one_terra_sample config = TimebaseOptions(max_time_interval=smallest_timebase, no_of_samples=one_terra_sample, min_collection_time=duration) timebase_info = device.find_timebase(config) except NoValidTimebaseForOptionsError: threw = True if not threw: return "didn't throw an NoValidTimebaseForOptionsError." self.run_snippet_and_count_problems(drivers_to_use, test) def test_find_timebase_impossible(self): """test_find_timebase_impossible note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): with driver.open_unit() as device: threw = False try: # we ask for a config which cannot be achieved (specifying all 3 variables can lead to invalid # configs.) no_of_samples = 150 duration = 0.4 computed_timebase = duration / no_of_samples max_timebase_requested = computed_timebase / 4 config = TimebaseOptions(max_time_interval=max_timebase_requested, no_of_samples=no_of_samples, min_collection_time=duration) timebase_info = device.find_timebase(config) except NoValidTimebaseForOptionsError: threw = True if not threw: return "didn't throw an NoValidTimebaseForOptionsError." self.run_snippet_and_count_problems(drivers_to_use, test) def test_get_timebase_throws_on_bad_params(self): """test_get_timebase_impossible note: test assumes you have set test_helpers.drivers_with_device_connected""" if not drivers_with_device_connected: return drivers_to_use = drivers_with_device_connected def test(driver): with driver.open_unit() as device: threw = False try: # we ask for a config which cannot be achieved (specifying all 3 variables can lead to invalid # configs.) no_of_samples = 150 duration = 0.4 computed_timebase = duration / no_of_samples max_timebase_requested = computed_timebase / 4 # we manually invoke the Library method, to check that if invalid options sneak through, we throw # a different error: timebase_info = device.driver.get_timebase(device, 1, no_of_samples) except InvalidTimebaseError: threw = True if not threw: return "didn't throw an InvalidTimebaseError." self.run_snippet_and_count_problems(drivers_to_use, test) class TimebaseValidationTest(unittest.TestCase): def test_valid_config(self): request = TimebaseOptions(max_time_interval=0.005, no_of_samples=None, min_collection_time=1.) actual_timebase = 0.004 required_max_samples = int(math.ceil(request.min_collection_time / actual_timebase)) response = TimebaseInfo(timebase_id=7, time_interval=0.004, time_units=None, max_samples=required_max_samples+1, segment_id=0) self.assertTrue(Device._validate_timebase(request, response)) def test_invalid_config(self): request = TimebaseOptions(max_time_interval=0.005, no_of_samples=None, min_collection_time=1.) actual_timebase = 0.004 required_max_samples = int(math.ceil(request.min_collection_time / actual_timebase)) response = TimebaseInfo(timebase_id=7, time_interval=0.004, time_units=None, max_samples=required_max_samples-5, segment_id=0) self.assertFalse(Device._validate_timebase(request, response)) ================================================ FILE: usbdrdaqExamples/usbdrdaqPhBlockExample.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # # USBDRDAQ SCOPE BLOCK MODE EXAMPLE # This example opens a UsbDrDaq driver device, sets up the scope channel and a trigger then collects a single block of data. # This data is then plotted as mV against time in ns. import ctypes import time from picosdk.usbDrDaq import usbDrDaq as drDaq import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device status["openunit"] = drDaq.UsbDrDaqOpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openunit"]) # Set sample interval us_for_block = ctypes.c_int32(1000) ideal_no_of_samples = 1000 channels = ctypes.c_int32(drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_PH"]) no_of_channels = 1 status["setInterval"] = drDaq.UsbDrDaqSetInterval(chandle, ctypes.byref(us_for_block), ideal_no_of_samples, ctypes.byref(channels), no_of_channels) assert_pico_ok(status["setInterval"]) # Find scaling information channel = drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_PH"] nScales = ctypes.c_int16(0) currentScale = ctypes.c_int16(0) names = (ctypes.c_char*256)() namesSize = 256 status["getscalings"] = drDaq.UsbDrDaqGetScalings(chandle, channel, ctypes.byref(nScales), ctypes.byref(currentScale), ctypes.byref(names), namesSize) assert_pico_ok(status["getscalings"]) print(nScales.value) print(currentScale.value) print(names.value) # Set channel scaling scalingNumber = 0 # pH scaling status["setscaling"] = drDaq.UsbDrDaqSetScalings(chandle, channel, scalingNumber) assert_pico_ok(status["setscaling"]) # Set temperature compenstation enabled = 1 status["phTemperatureCompensation"] = drDaq.UsbDrDaqPhTemperatureCompensation(chandle, enabled) assert_pico_ok(status["phTemperatureCompensation"]) # Run block capture method = drDaq.USB_DRDAQ_BLOCK_METHOD["BM_SINGLE"] status["run"] = drDaq.UsbDrDaqRun(chandle, ideal_no_of_samples, method) assert_pico_ok(status["run"]) ready = ctypes.c_int16(0) while ready.value == 0: status["ready"] = drDaq.UsbDrDaqReady(chandle, ctypes.byref(ready)) print(ready.value) time.sleep(0.1) # Retrieve data from device values = (ctypes.c_float * ideal_no_of_samples)() noOfValues = ctypes.c_uint32(ideal_no_of_samples) overflow = ctypes.c_uint16(0) triggerIndex = ctypes.c_uint32(0) status["getvaluesF"] = drDaq.UsbDrDaqGetValuesF(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(overflow), ctypes.byref(triggerIndex)) assert_pico_ok(status["getvaluesF"]) # generate time data time = np.linspace(0, us_for_block, ideal_no_of_samples) # plot the data plt.plot(time, values[:]) plt.xlabel('Time (ns)') plt.ylabel('pH') plt.show() # Disconnect the scope # handle = chandle status["close"] = drDaq.UsbDrDaqCloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: usbdrdaqExamples/usbdrdaqScopeBlockExample.py ================================================ # # Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms. # # USBDRDAQ SCOPE BLOCK MODE EXAMPLE # This example opens a UsbDrDaq driver device, sets up the scope channel and a trigger then collects a single block of data. # This data is then plotted as mV against time in ns. import ctypes import time from picosdk.usbDrDaq import usbDrDaq as drDaq import numpy as np import matplotlib.pyplot as plt from picosdk.functions import adc2mV, assert_pico_ok # Create chandle and status ready for use status = {} chandle = ctypes.c_int16() # Opens the device status["openunit"] = drDaq.UsbDrDaqOpenUnit(ctypes.byref(chandle)) assert_pico_ok(status["openunit"]) # Set sample interval us_for_block = ctypes.c_int32(1000) ideal_no_of_samples = 1000 channels = ctypes.c_int32(drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_SCOPE"]) no_of_channels = 1 status["setInterval"] = drDaq.UsbDrDaqSetInterval(chandle, ctypes.byref(us_for_block), ideal_no_of_samples, ctypes.byref(channels), no_of_channels) assert_pico_ok(status["setInterval"]) # Find scaling information channel = drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_SCOPE"] nScales = ctypes.c_int16(0) currentScale = ctypes.c_int16(0) names = (ctypes.c_char*256)() namesSize = 256 status["getscalings"] = drDaq.UsbDrDaqGetScalings(chandle, channel, ctypes.byref(nScales), ctypes.byref(currentScale), ctypes.byref(names), namesSize) assert_pico_ok(status["getscalings"]) print(nScales.value) print(currentScale.value) print(names.value) # Set channel scaling scalingNumber = drDaq.USB_DRDAQ_SCOPE_RANGE["USB_DRDAQ_2V5"] status["setscaling"] = drDaq.UsbDrDaqSetScalings(chandle, channel, scalingNumber) assert_pico_ok(status["setscaling"]) # Set trigger enabled = 1 auto_trigger = 1 auto_ms = 1000 # in ms dir = 0 # rising edge threshold = 1000 # in mV hysteresis = 50 # in ADC counts delay = -50 # trigger in centre of block status["settrigger"] = drDaq.UsbDrDaqSetTrigger(chandle, enabled, auto_trigger, auto_ms, channel, dir, threshold, hysteresis, delay) assert_pico_ok(status["settrigger"]) # Run block capture method = drDaq.USB_DRDAQ_BLOCK_METHOD["BM_SINGLE"] status["run"] = drDaq.UsbDrDaqRun(chandle, ideal_no_of_samples, method) assert_pico_ok(status["run"]) ready = ctypes.c_int16(0) while ready.value == 0: status["ready"] = drDaq.UsbDrDaqReady(chandle, ctypes.byref(ready)) print(ready.value) time.sleep(0.1) # Retrieve data from device values = (ctypes.c_float * ideal_no_of_samples)() noOfValues = ctypes.c_uint32(ideal_no_of_samples) overflow = ctypes.c_uint16(0) triggerIndex = ctypes.c_uint32(0) status["getvaluesF"] = drDaq.UsbDrDaqGetValuesF(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(overflow), ctypes.byref(triggerIndex)) assert_pico_ok(status["getvaluesF"]) # generate time data time = np.linspace(0, us_for_block, ideal_no_of_samples) # plot the data plt.plot(time, values[:]) plt.xlabel('Time (ns)') plt.ylabel('Voltage (mV)') plt.show() # Disconnect the scope # handle = chandle status["close"] = drDaq.UsbDrDaqCloseUnit(chandle) assert_pico_ok(status["close"]) # Display status returns print(status) ================================================ FILE: usbtc08Examples/tc08SingleModeExample.py ================================================ # # 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(chandle) assert_pico2000_ok(status["get_minimum_interval_ms"]) # get single temperature reading temp = (ctypes.c_float * 9)() overflow = ctypes.c_int16(0) units = tc08.USBTC08_UNITS["USBTC08_UNITS_CENTIGRADE"] status["get_single"] = tc08.usb_tc08_get_single(chandle,ctypes.byref(temp), ctypes.byref(overflow), units) assert_pico2000_ok(status["get_single"]) # print data print("Cold Junction ", temp[0]," Channel 1 ", temp[1]) # close unit status["close_unit"] = tc08.usb_tc08_close_unit(chandle) assert_pico2000_ok(status["close_unit"]) # display status returns print(status) ================================================ FILE: usbtc08Examples/tc08StreamingModeExample.py ================================================ # # Copyright (C) 2019 Pico Technology Ltd. See LICENSE file for terms. # # 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 import matplotlib.pyplot as plt # 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) assert_pico2000_ok(status["get_minimum_interval_ms"]) # set tc-08 running status["run"] = tc08.usb_tc08_run(chandle, status["get_minimum_interval_ms"]) assert_pico2000_ok(status["run"]) time.sleep(21) # collect data temp_buffer = (ctypes.c_float * 2 * 100)() times_ms_buffer = (ctypes.c_int32 * 100)() overflow = ctypes.c_int16() status["get_temp"] = tc08.usb_tc08_get_temp(chandle, ctypes.byref(temp_buffer), ctypes.byref(times_ms_buffer), 100, ctypes.byref(overflow), 1, 0, 1) assert_pico2000_ok(status["get_temp"]) # stop unit status["stop"] = tc08.usb_tc08_stop(chandle) assert_pico2000_ok(status["stop"]) # close unit status["close_unit"] = tc08.usb_tc08_close_unit(chandle) assert_pico2000_ok(status["close_unit"]) # plot data plt.plot(temp_buffer[0:status["get_temp"]]) plt.xlabel('Time (ns)') plt.ylabel('Temperature (oC)') plt.show() # display status returns print(status) ================================================ FILE: usbtc08Examples/tc08StreamingModeMultiChExample.py ================================================ # # Copyright (C) 2026 Pico Technology Ltd. See LICENSE file for terms. # # TC-08 STREAMING MODE EXAMPLE import ctypes import time import numpy as np from picosdk.usbtc08 import usbtc08 as tc08 from picosdk.functions import assert_pico2000_ok # --- Configuration --- NUM_SAMPLES = 100 Requested_No_Samples = 5 # per function call - sets the loop delay (min. value is 1) # Define which channels to enable (1-8). 0 is the Cold Junction. ENABLED_CHANNELS = [1, 2, 8] THERMOCOUPLE_TYPE = ord('K') # 'K' type. Use 32 (ASCII space) to disable. # --------------------- # Create status dictionary to track API calls status = {} # Open Unit status["open_unit"] = tc08.usb_tc08_open_unit() assert_pico2000_ok(status["open_unit"]) chandle = status["open_unit"] try: # Set Mains Rejection (50Hz = 0, 60Hz = 1) status["set_mains"] = tc08.usb_tc08_set_mains(chandle, 0) assert_pico2000_ok(status["set_mains"]) # Setup Channels # Always set channel 0 (Cold Junction) #tc08.usb_tc08_set_channel(chandle, 0, ord(' ')) Enabled_chs = 0 for chan in ENABLED_CHANNELS: status[f"set_chan_{chan}"] = tc08.usb_tc08_set_channel(chandle, chan, THERMOCOUPLE_TYPE) assert_pico2000_ok(status[f"set_chan_{chan}"]) Enabled_chs = Enabled_chs + 1 # Get the minimum sampling interval # This determines how fast the device can switch between enabled channels min_interval_ms = tc08.usb_tc08_get_minimum_interval_ms(chandle) status["get_temp_return"] = min_interval_ms assert_pico2000_ok(status["get_temp_return"]) print(f"Minimum sampling interval: {min_interval_ms} ms") # Prepare Data Storage # We need a buffer for each channel's samples # data_store[channel_index][sample_index] #captured_samples=np.zeros(shape=(9, NUM_SAMPLES), dtype=ctypes.c_float) rows, cols = 9, NUM_SAMPLES RowType = ctypes.c_float * cols Array2D = RowType * rows captured_samples = Array2D() # Buffers required by usb_tc08_get_temp # It returns up to 'buffer_length' samples per call temp_buffer = (ctypes.c_float * 600)() # Buffer times_ms_buffer = (ctypes.c_int32 * 600)() overflow = ctypes.c_int16() # set tc-08 running status["run"] = tc08.usb_tc08_run(chandle, min_interval_ms) assert_pico2000_ok(status["run"]) print(f"Starting capture of {NUM_SAMPLES} samples...") current_num_samples = 0 # Collection Loop while current_num_samples in range(NUM_SAMPLES): # We call get_temp for each sample point # The library fills the buffer with the most recent readings # Store the data for our enabled channels for chan in ENABLED_CHANNELS: get_temp_return = tc08.usb_tc08_get_temp( chandle, ctypes.byref(temp_buffer), ctypes.byref(times_ms_buffer), len(temp_buffer), ctypes.byref(overflow), # Chanel over range flag chan, # channel 0, # units (0 = Centigrade) 1 # fill_missing samples ) if(get_temp_return < 0): status["get_temp_return"] = get_temp_return assert_pico2000_ok(status["get_temp_return"]) if(get_temp_return > 0): # If Samples if((current_num_samples+get_temp_return) < NUM_SAMPLES): captured_samples[chan][current_num_samples:(current_num_samples+get_temp_return)] = temp_buffer[0:get_temp_return] current_num_samples = current_num_samples + get_temp_return # Print current values from channels- if(get_temp_return > 0): for chan in ENABLED_CHANNELS: print("Channel: ", chan ) print("Channel Temps: ", captured_samples[chan][current_num_samples-get_temp_return]) # Delay by the minimum interval to ensure hardware is ready for next conversion time.sleep(min_interval_ms * Requested_No_Samples / 1000.0) if current_num_samples % 10 == 0: print(f"Captured {current_num_samples} samples...") print("Capture complete.") finally: # Close Unit status["close_unit"] = tc08.usb_tc08_close_unit(chandle) assert_pico2000_ok(status["close_unit"]) print("Device closed.")