Skip to content

Commit 6a10994

Browse files
author
neil.hamilton
committed
fix ctypes structure and pointer interaction
1 parent 1f51f10 commit 6a10994

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

ps4000aExamples/ps4000aBlockDropoutTriggerExample.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from picosdk.ps4000a import ps4000a as ps
1111
import matplotlib.pyplot as plt
1212
from picosdk.functions import adc2mV, assert_pico_ok, mV2adc
13+
from math import *
1314

1415
# Create chandle and status ready for use
1516
chandle = ctypes.c_int16()
@@ -56,12 +57,19 @@
5657

5758
# Set up dropout trigger
5859
# set trigger condtions for channel A and pulse width qualifier
59-
conditions =[ps.PS4000A_CONDITION() for i in range (2)]
60-
print(conditions)
61-
conditions[0].source = ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"]
62-
conditions[0].condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]
63-
conditions[1].source = ps.PS4000A_CHANNEL["PS4000A_PULSE_WIDTH_SOURCE"]
64-
conditions[1].condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]
60+
class RECT(ctypes.Structure):
61+
_fields_ = [("channelA",ps.PS4000A_CONDITION),
62+
("pwq",ps.PS4000A_CONDITION)]
63+
64+
#conditions =[ps.PS4000A_CONDITION() for i in range (2)]
65+
66+
channelAConditions = ps.PS4000A_CONDITION(ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"],ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"])
67+
#conditions.channelA.condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]
68+
pulseWidthConditions = ps.PS4000A_CONDITION(ps.PS4000A_CHANNEL["PS4000A_PULSE_WIDTH_SOURCE"],ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"])
69+
#conditions.pwq.condition = ps.PS4000A_TRIGGER_STATE["PS4000A_TRUE"]
70+
71+
conditions = RECT(channelAConditions,pulseWidthConditions)
72+
6573

6674
nConditions = 2
6775
info = ps.PS4000A_CONDITIONS_INFO["PS4000A_ADD"]
@@ -80,21 +88,20 @@
8088
maxADC = ctypes.c_int16(32767)
8189

8290
# set trigger properties for channel ADC
83-
thresholdUpper = mV2adc(500, c, maxADC)
84-
channelProperties = ps.PS4000A_TRIGGER_CHANNEL_PROPERTIES(thresholdUpper, (thresholdUpper * 0.05), (thresholdUpper * -1), (thresholdUpper * 0.05), ps.PS4000A_CHANNEL["PS4000A_CHANNEL_A"], ps.PS4000A_THRESHOLD_MODE["PS4000A_WINDOW"])
91+
thresholdUpper = mV2adc(500, 7, maxADC)
92+
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"])
8593
nChannelProperties = 1
8694
autoTriggerms = 10000
8795
status["setTriggerChannelProperties"] = ps.ps4000aSetTriggerChannelProperties(chandle, ctypes.byref(channelProperties), nChannelProperties, 0, autoTriggerms)
8896
assert_pico_ok(status["setTriggerChannelProperties"])
8997

9098
# set pulse width qualifier conditions
91-
pwqConditions = conditions[1]
9299
pwqNConditions = 1
93-
status["setPulseWidthQualifierConditions"] = ps.ps4000aSetPulseWidthQualifierConditions(chandle, ctypes.byref(pwqConditions), pwqNConditions, info)
100+
status["setPulseWidthQualifierConditions"] = ps.ps4000aSetPulseWidthQualifierConditions(chandle, ctypes.byref(pulseWidthConditions), pwqNConditions, info)
94101
assert_pico_ok(status["setPulseWidthQualifierConditions"])
95102

96103
# set pulse width qualifier properties
97-
direction = ps.PS4000A_DIRECTION[""]
104+
direction = ps.PS4000A_THRESHOLD_DIRECTION["PS4000A_ENTER"]
98105
lower = 15
99106
upper = 100
100107
type = ps.PS4000A_PULSE_WIDTH_TYPE["PW_TYPE_IN_RANGE"]

0 commit comments

Comments
 (0)