How to use active probe (A3136) through Python SDK wrapper?

Having problems ? let us know the details here
Post Reply
trident
User
User
Posts: 2
Joined: Mon Jun 17, 2024 5:12 am

How to use active probe (A3136) through Python SDK wrapper?

Post by trident »

I'm using Pico6426E and active probe A3136. Everything goes well with Picoscope 7 but i need drive them with my own script.

Refer to progremmer guide PicoScope 6000 section 3.41 https://www.picotech.com/download/manua ... -guide.pdf ps6000aSetChannelOn(), we could not set the range directly when using intelligent probe but implement a custom callback function PicoProbeInteractions().
We should then register this callback function by ps6000aSetProbeInteractionCallback(), so the available range values will pass to our callback when the probe status change.

It seems we should setup the channel (connected to the probe) in our custom callback, since otherwise we could not get the available range values of the probe.
But i cant find a way to achive this.
Below is my code:

Code: Select all

import ctypes
import random
import sys
import tqdm

import matplotlib.pyplot as plt
import numpy as np

from picosdk.functions import mV2adc, assert_pico_ok, adc2mV
from picosdk.ps6000a import ps6000a as ps
from picosdk.PicoDeviceEnums import picoEnum as enums

PICO_CHANNEL = ctypes.c_uint16
PicoConnectProbe = ctypes.c_uint16
PICO_STATUS = ctypes.c_uint32
PICO_CONNECT_PROBE_RANGE = ctypes.c_uint16
PICO_COUPLING = ctypes.c_uint16
PICO_BANDWIDTH_LIMITER_FLAGS = ctypes.c_uint32
PICO_BANDWIDTH_LIMITER = ctypes.c_uint16

class PICO_USER_PROBE_INTERACTIONS(ctypes.Structure):
    _fields_ = [
        ("connected_", ctypes.c_uint16),
        ("channel_", PICO_CHANNEL),
        ("enabled_", ctypes.c_uint16),
        ("probeName_", PicoConnectProbe),
        ("requiresPower_", ctypes.c_uint8),
        ("isPowered_", ctypes.c_uint8),
        ("status_", PICO_STATUS),
        ("probeOff_", PICO_CONNECT_PROBE_RANGE),
        ("rangeFirst_", PICO_CONNECT_PROBE_RANGE),
        ("rangeLast_", PICO_CONNECT_PROBE_RANGE),
        ("rangeCurrent_", PICO_CONNECT_PROBE_RANGE),
        ("couplingFirst_", PICO_COUPLING),
        ("couplingLast_", PICO_COUPLING),
        ("couplingCurrent_", PICO_COUPLING),
        ("filterFlags_", PICO_BANDWIDTH_LIMITER_FLAGS),
        ("filterCurrent_", PICO_BANDWIDTH_LIMITER_FLAGS),
        ("defaultFilter_", PICO_BANDWIDTH_LIMITER),
    ]

# Define the callback function
def PicoProbeInteractions(handle, status, probes, nProbes):
    print(f"Handle: {handle}")
    print(f"Status: {status}")
    print(f"Number of Probes: {nProbes}")
    
    for i in range(nProbes):
        probe = probes[i]
        print(f"Probe {i}:")
        print(f"  connected: {probe.connected_}")
        print(f"  channel: {probe.channel_}")
        print(f"  enabled: {probe.enabled_}")
        print(f"  probeName: {probe.probeName_}")
        print(f"  requiresPower: {probe.requiresPower_}")
        print(f"  isPowered: {probe.isPowered_}")
        print(f"  status: {probe.status_}")
        print(f"  probeOff: {probe.probeOff_}")
        print(f"  rangeFirst: {probe.rangeFirst_}")
        print(f"  rangeLast: {probe.rangeLast_}")
        print(f"  rangeCurrent: {probe.rangeCurrent_}")
        print(f"  couplingFirst: {probe.couplingFirst_}")
        print(f"  couplingLast: {probe.couplingLast_}")
        print(f"  couplingCurrent: {probe.couplingCurrent_}")
        print(f"  filterFlags: {probe.filterFlags_}")
        print(f"  filterCurrent: {probe.filterCurrent_}")
        print(f"  defaultFilter: {probe.defaultFilter_}")
    # probe.rangeCurrent_ = probe.rangeFirst_
    channelA = enums.PICO_CHANNEL["PICO_CHANNEL_A"]
    # coupling = enums.PICO_COUPLING["PICO_DC_50OHM"]
    coupling = enums.PICO_COUPLING["PICO_DC"]
    # chARange = ps.PS6000_RANGE["PS6000_100MV"]
    # chARange = ps6000a_vertical_range["PS6000_10MV"]
    # chARange = 0
    analogue_offset_A = -0.830
    # analogue_offset_A = 0
    bandwidth = enums.PICO_BANDWIDTH_LIMITER["PICO_BW_FULL"]

    print('channelA:', channelA)
    print('coupling:', coupling)
    print('analogue_offset_A:', analogue_offset_A)
    print('bandwidth:',bandwidth)
    print('type ps:', type(ps))

    tmpstatus = ps.ps6000aSetChannelOn(chandle, channelA, coupling, probe.rangeLast_, analogue_offset_A, bandwidth)
    print('tmpstatus:', tmpstatus)
    assert_pico_ok(tmpstatus)

# Define the callback function type
PicoProbeInteractionsCallback = ctypes.CFUNCTYPE(
    None,
    ctypes.c_int16,                 # handle
    PICO_STATUS,                    # status
    ctypes.POINTER(PICO_USER_PROBE_INTERACTIONS),  # probes
    ctypes.c_uint32                 # nProbes
)

# Create a ctypes callback function instance
pico_probe_interactions_cb = PicoProbeInteractionsCallback(PicoProbeInteractions)

# set up for oscilloscope
# Create chandle and status ready for use
status = {}
chandle = ctypes.c_int16()

# Open 6000 A series PicoScope
# returns handle to chandle for use in future API functions
resolution = enums.PICO_DEVICE_RESOLUTION["PICO_DR_10BIT"]
status["openunit"] = ps.ps6000aOpenUnit(ctypes.byref(chandle), None, resolution)
assert_pico_ok(status["openunit"])

status["SetProbeInteraction"] = ps.ps6000aSetProbeInteractionCallback(chandle, pico_probe_interactions_cb)
assert_pico_ok(status["SetProbeInteraction"])
and the output with errors:

trident
User
User
Posts: 2
Joined: Mon Jun 17, 2024 5:12 am

Re: How to use active probe (A3136) through Python SDK wrapper?

Post by trident »

and the output with errors:

Code: Select all

Handle: 16384
Status: 0
Number of Probes: 4
Probe 0:
  connected: 0
  channel: 0
  enabled: 0
  probeName: 0
  requiresPower: 0
  isPowered: 0
  status: 0
  probeOff: 0
  rangeFirst: 1024
  rangeLast: 0
  rangeCurrent: 1024
  couplingFirst: 0
  couplingLast: 1024
  couplingCurrent: 0
  filterFlags: 0
  filterCurrent: 65536
  defaultFilter: 0
Probe 1:
  connected: 0
  channel: 1
  enabled: 0
  probeName: 1
  requiresPower: 0
  isPowered: 0
  status: 0
  probeOff: 1
  rangeFirst: 0
  rangeLast: 0
  rangeCurrent: 0
  couplingFirst: 0
  couplingLast: 0
  couplingCurrent: 0
  filterFlags: 1024
  filterCurrent: 1024
  defaultFilter: 1024
Probe 2:
  connected: 1024
  channel: 0
  enabled: 0
  probeName: 0
  requiresPower: 1
  isPowered: 0
  status: 1
  probeOff: 1
  rangeFirst: 0
  rangeLast: 1
  rangeCurrent: 0
  couplingFirst: 0
  couplingLast: 0
  couplingCurrent: 0
  filterFlags: 0
  filterCurrent: 0
  defaultFilter: 0
Probe 3:
  connected: 0
  channel: 1024
  enabled: 0
  probeName: 1024
  requiresPower: 0
  isPowered: 0
  status: 67108864
  probeOff: 0
  rangeFirst: 0
  rangeLast: 0
  rangeCurrent: 1
  couplingFirst: 0
  couplingLast: 1
  couplingCurrent: 0
  filterFlags: 65536
  filterCurrent: 0
  defaultFilter: 0
channelA: 0
coupling: 1
analogue_offset_A: -0.83
bandwidth: 0
type ps: 
tmpstatus: 67
Exception ignored on calling ctypes callback function: 
Traceback (most recent call last):
  File "d:\py_proj\picosdk-python-wrappers-master-2024\My_collection_ps6000a_for_ssh.py", line 136, in PicoProbeInteractions
    assert_pico_ok(tmpstatus)
  File "d:\py_proj\picosdk-python-wrappers-master-2024\picosdk\functions.py", line 160, in assert_pico_ok
    raise PicoSDKCtypesError("PicoSDK returned '{}'".format(PICO_STATUS_LOOKUP[status]))
picosdk.errors.PicoSDKCtypesError: PicoSDK returned 'PICO_DRIVER_FUNCTION'
Handle: 16384
Status: 0
Number of Probes: 1
Probe 0:
  connected: 1
  channel: 0
  enabled: 0
  probeName: 0
  requiresPower: 114
  isPowered: 23
  status: 257
  probeOff: 0
  rangeFirst: 1024
  rangeLast: 0
  rangeCurrent: 10700
  couplingFirst: 0
  couplingLast: 10705
  couplingCurrent: 0
  filterFlags: 3276800
  filterCurrent: 3276800
  defaultFilter: 0
channelA: 0
coupling: 1
analogue_offset_A: -0.83
bandwidth: 0
type ps: 
tmpstatus: 343
Exception ignored on calling ctypes callback function: 
Traceback (most recent call last):
  File "d:\py_proj\picosdk-python-wrappers-master-2024\My_collection_ps6000a_for_ssh.py", line 136, in PicoProbeInteractions
    assert_pico_ok(tmpstatus)
  File "d:\py_proj\picosdk-python-wrappers-master-2024\picosdk\functions.py", line 160, in assert_pico_ok
    raise PicoSDKCtypesError("PicoSDK returned '{}'".format(PICO_STATUS_LOOKUP[status]))
picosdk.errors.PicoSDKCtypesError: PicoSDK returned 'PICO_WARNING_PROBE_CHANNEL_OUT_OF_SYNC'

Post Reply