Passing an array of structs for advanced triggering in Python

Post general discussions on using our drivers to write your own software here
Post Reply
Caio
Newbie
Posts: 0
Joined: Mon Apr 08, 2019 10:11 pm

Passing an array of structs for advanced triggering in Python

Post by Caio »

Hey there. I am working on getting advanced triggering working and have gotten close, but run into issues when I try to pass an array of the trigger properties structs.

I am using a 6404D and and running PicoSDK 10.6.12 (64-bit) on windows. I am using the master branch of the picosdk-python-wrappers repository on github.

Below are the two structs I have built in python to match the packed structs in C.

Code: Select all

class trigger_channel_properties(c.Structure):
    """ creates a struct to match PS6000_TRIGGER_CHANNEL_PROPERTIES"""
    _pack_ = 1
    _fields_ = [('thresholdUpper', c.c_int16),
                ('hysteresisUpper', c.c_int16),
                ('thresholdLower', c.c_int16),
                ('hysteresisLower', c.c_uint16),
                ('channel', c.c_int8),
                ('thresholdMode', c.c_int8)]

class trigger_conditions(c.Structure):
    """ creates a struct to match PS6000_TRIGGER_CONDITIONS"""
    _pack_ = 1
    _fields_ = [('channelA', c.c_int8),
                ('channelB', c.c_int8),
                ('channelC', c.c_int8),
                ('channelD', c.c_int8),
                ('external', c.c_int8),
                ('aux', c.c_int8),
                ('pulseWidthQualifier', c.c_int8)]
I'm fairly confident these are right because if I pass a single struct as a reference the scope triggers as it should. An example is below.

Code: Select all

conditions = trigger_conditions(PS6000_TRIGGER_STATE.PS6000_CONDITION_TRUE,\
PS6000_TRIGGER_STATE.PS6000_CONDITION_DONT_CARE, PS6000_TRIGGER_STATE.PS6000_CONDITION_DONT_CARE,\
PS6000_TRIGGER_STATE.PS6000_CONDITION_DONT_CARE, PS6000_TRIGGER_STATE.PS6000_CONDITION_DONT_CARE,\
PS6000_TRIGGER_STATE.PS6000_CONDITION_DONT_CARE, PS6000_TRIGGER_STATE.PS6000_CONDITION_DONT_CARE)
	
status = ps.ps6000SetTriggerChannelConditions(chandle, ctypes.byref(trigger_conditions), 1)

Since I want to have multiple trigger conditions supported, I tried building a list of trigger conditions and converting it to an array with the code below.

Code: Select all


trigger_condition_array = (trigger_conditions * len(trigger_condition_list))(*trigger_condition_list)

status = ps.ps6000SetTriggerChannelConditions(chandle, trigger_condition_array, len(trigger_condition_list))

This doesn't seem to pass the array like I want, since ps6000SetTriggerChannelConditions() returns fine, but doesn't correctly set the trigger, and ps6000SetTriggerChannelProperties() returns 'PICO_TRIGGER_ERROR'.

So my guess is either I have a struct that isn't the right size as the c struct, or I am not converting the list into an array correctly. Has anyone gotten this working?

Post Reply