Skip to content

Commit e7f92d4

Browse files
Small fixes (#61)
* Updated pulse_width_trigger.py - Added pre_trig value for run and plot * Moved advanced trigger fucntions from ps6000a to base.py * Update requirements.txt - Added build and pytest - Added versions to mkdocs packages * Updated base.py - Added list option to trigger and pulse direction control
1 parent a2164d9 commit e7f92d4

File tree

4 files changed

+127
-103
lines changed

4 files changed

+127
-103
lines changed

build-tools/requirements.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ numpy
44
pandas
55
matplotlib
66

7-
mkdocs
8-
mkdocstrings-python
7+
mkdocs >= 1.6
8+
mkdocstrings-python >= 1.16
9+
mkdocs-autorefs >= 1.4
10+
11+
build
12+
pytest
913

examples/pulse_width_trigger.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
)
4141

4242
# Run capture and retrieve data
43-
channel_buffer, time_axis = scope.run_simple_block_capture(TIMEBASE, SAMPLES)
43+
pre_trig = 0.5
44+
channel_buffer, time_axis = scope.run_simple_block_capture(TIMEBASE, SAMPLES, pre_trig_percent=pre_trig*100)
4445

4546
# Close PicoScope connection
4647
scope.close_unit()
@@ -49,7 +50,7 @@
4950
plt.plot(time_axis, channel_buffer[psdk.CHANNEL.A])
5051

5152
# Draw trigger line on graph
52-
plt.axvline(time_axis[int(SAMPLES/2)], color='r')
53+
plt.axvline(time_axis[int(SAMPLES*(pre_trig))], color='r')
5354
plt.xlabel("Time (ns)")
5455
plt.ylabel("Amplitude (mV)")
5556
plt.grid(True)

pypicosdk/base.py

Lines changed: 118 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,107 @@ def set_simple_trigger(self, channel, threshold_mv, enable=True, direction=TRIGG
978978
auto_trigger
979979
)
980980

981+
def set_trigger_channel_conditions(
982+
self,
983+
conditions: list[tuple[CHANNEL, TRIGGER_STATE]],
984+
action: int = ACTION.CLEAR_ALL | ACTION.ADD,
985+
) -> None:
986+
"""Configure a trigger condition.
987+
988+
Args:
989+
conditions (list[tuple[CHANNEL, TRIGGER_STATE]]):
990+
A list of tuples describing the CHANNEL and TRIGGER_STATE for that channel
991+
action (int, optional): Action to apply this condition relateive to any previous
992+
condition. Defaults to ACTION.CLEAR_ALL | ACTION.ADD.
993+
"""
994+
995+
cond_len = len(conditions)
996+
cond_array = (PICO_CONDITION * cond_len)()
997+
for i, (source, state) in enumerate(conditions):
998+
cond_array[i] = PICO_CONDITION(source, state)
999+
1000+
self._call_attr_function(
1001+
"SetTriggerChannelConditions",
1002+
self.handle,
1003+
ctypes.byref(cond_array),
1004+
ctypes.c_int16(cond_len),
1005+
action,
1006+
)
1007+
1008+
def set_trigger_channel_properties(
1009+
self,
1010+
threshold_upper: int,
1011+
hysteresis_upper: int,
1012+
threshold_lower: int,
1013+
hysteresis_lower: int,
1014+
channel: int,
1015+
aux_output_enable: int = 0,
1016+
auto_trigger_us: int = 0,
1017+
) -> None:
1018+
"""Configure trigger thresholds for ``channel``. All
1019+
threshold and hysteresis values are specified in ADC counts.
1020+
1021+
Args:
1022+
threshold_upper (int): Upper trigger level.
1023+
hysteresis_upper (int): Hysteresis for ``threshold_upper``.
1024+
threshold_lower (int): Lower trigger level.
1025+
hysteresis_lower (int): Hysteresis for ``threshold_lower``.
1026+
channel (int): Target channel as a :class:`CHANNEL` value.
1027+
aux_output_enable (int, optional): Auxiliary output flag.
1028+
auto_trigger_us (int, optional): Auto-trigger timeout in
1029+
microseconds. ``0`` waits indefinitely.
1030+
"""
1031+
1032+
prop = PICO_TRIGGER_CHANNEL_PROPERTIES(
1033+
threshold_upper,
1034+
hysteresis_upper,
1035+
threshold_lower,
1036+
hysteresis_lower,
1037+
channel,
1038+
)
1039+
1040+
self._call_attr_function(
1041+
"SetTriggerChannelProperties",
1042+
self.handle,
1043+
ctypes.byref(prop),
1044+
ctypes.c_int16(1),
1045+
ctypes.c_int16(aux_output_enable),
1046+
ctypes.c_uint32(auto_trigger_us),
1047+
)
1048+
1049+
def set_trigger_channel_directions(
1050+
self,
1051+
channel: CHANNEL | list,
1052+
direction: THRESHOLD_DIRECTION | list,
1053+
threshold_mode: THRESHOLD_MODE | list,
1054+
) -> None:
1055+
"""
1056+
Specify the trigger direction for ``channel``.
1057+
If multiple directions are needed, channel, direction and threshold_mode
1058+
can be given a list of values.
1059+
1060+
Args:
1061+
channel (CHANNEL | list): Single or list of channels to configure.
1062+
direction (THRESHOLD_DIRECTION | list): Single or list of directions to configure.
1063+
threshold_mode (THRESHOLD_MODE | list): Single or list of threshold modes to configure.
1064+
"""
1065+
1066+
if type(channel) == list:
1067+
dir_len = len(channel)
1068+
dir_struct = (PICO_DIRECTION * dir_len)()
1069+
for i in range(dir_len):
1070+
dir_struct[i] = PICO_DIRECTION(channel[i], direction[i], threshold_mode[i])
1071+
else:
1072+
dir_len = 1
1073+
dir_struct = PICO_DIRECTION(channel, direction, threshold_mode)
1074+
1075+
self._call_attr_function(
1076+
"SetTriggerChannelDirections",
1077+
self.handle,
1078+
ctypes.byref(dir_struct),
1079+
ctypes.c_int16(dir_len),
1080+
)
1081+
9811082
def set_advanced_trigger(
9821083
self,
9831084
channel: int,
@@ -1142,19 +1243,29 @@ def set_pulse_width_qualifier_directions(
11421243
threshold_mode: int,
11431244
) -> None:
11441245
"""Set pulse width qualifier direction for ``channel``.
1145-
Args:
1146-
channel: Channel identifier.
1147-
direction: Trigger direction value.
1148-
threshold_mode: Analog or digital threshold mode.
1149-
"""
1246+
If multiple directions are needed, channel, direction and threshold_mode
1247+
can be given a list of values.
11501248
1151-
dir_struct = PICO_DIRECTION(channel, direction, threshold_mode)
1249+
Args:
1250+
channel (CHANNEL | list): Single or list of channels to configure.
1251+
direction (THRESHOLD_DIRECTION | list): Single or list of directions to configure.
1252+
threshold_mode (THRESHOLD_MODE | list): Single or list of threshold modes to configure.
1253+
"""
1254+
if type(channel) == list:
1255+
dir_len = len(channel)
1256+
dir_struct = (PICO_DIRECTION * dir_len)()
1257+
for i in range(dir_len):
1258+
print(channel[i], direction[i], threshold_mode[i])
1259+
dir_struct[i] = PICO_DIRECTION(channel[i], direction[i], threshold_mode[i])
1260+
else:
1261+
dir_len = 1
1262+
dir_struct = PICO_DIRECTION(channel, direction, threshold_mode)
11521263

11531264
self._call_attr_function(
11541265
"SetPulseWidthQualifierDirections",
11551266
self.handle,
11561267
ctypes.byref(dir_struct),
1157-
ctypes.c_int16(1),
1268+
ctypes.c_int16(dir_len),
11581269
)
11591270

11601271
def set_pulse_width_digital_port_properties(

pypicosdk/ps6000a.py

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -600,98 +600,6 @@ def set_simple_trigger(
600600
auto_trigger_us = auto_trigger_ms * 1000
601601
return super().set_simple_trigger(channel, threshold_mv, enable, direction, delay, auto_trigger_us)
602602

603-
def set_trigger_channel_conditions(
604-
self,
605-
conditions: list[tuple[CHANNEL, TRIGGER_STATE]],
606-
action: int = ACTION.CLEAR_ALL | ACTION.ADD,
607-
) -> None:
608-
"""Configure a trigger condition.
609-
610-
Args:
611-
conditions (list[tuple[CHANNEL, TRIGGER_STATE]]):
612-
A list of tuples describing the CHANNEL and TRIGGER_STATE for that channel
613-
action (int, optional): Action to apply this condition relateive to any previous
614-
condition. Defaults to ACTION.CLEAR_ALL | ACTION.ADD.
615-
"""
616-
617-
cond_len = len(conditions)
618-
cond_array = (PICO_CONDITION * cond_len)()
619-
for i, (source, state) in enumerate(conditions):
620-
cond_array[i] = PICO_CONDITION(source, state)
621-
622-
self._call_attr_function(
623-
"SetTriggerChannelConditions",
624-
self.handle,
625-
ctypes.byref(cond_array),
626-
ctypes.c_int16(cond_len),
627-
action,
628-
)
629-
630-
def set_trigger_channel_properties(
631-
self,
632-
threshold_upper: int,
633-
hysteresis_upper: int,
634-
threshold_lower: int,
635-
hysteresis_lower: int,
636-
channel: int,
637-
aux_output_enable: int = 0,
638-
auto_trigger_us: int = 0,
639-
) -> None:
640-
"""Configure trigger thresholds for ``channel``. All
641-
threshold and hysteresis values are specified in ADC counts.
642-
643-
Args:
644-
threshold_upper (int): Upper trigger level.
645-
hysteresis_upper (int): Hysteresis for ``threshold_upper``.
646-
threshold_lower (int): Lower trigger level.
647-
hysteresis_lower (int): Hysteresis for ``threshold_lower``.
648-
channel (int): Target channel as a :class:`CHANNEL` value.
649-
aux_output_enable (int, optional): Auxiliary output flag.
650-
auto_trigger_us (int, optional): Auto-trigger timeout in
651-
microseconds. ``0`` waits indefinitely.
652-
"""
653-
654-
prop = PICO_TRIGGER_CHANNEL_PROPERTIES(
655-
threshold_upper,
656-
hysteresis_upper,
657-
threshold_lower,
658-
hysteresis_lower,
659-
channel,
660-
)
661-
662-
self._call_attr_function(
663-
"SetTriggerChannelProperties",
664-
self.handle,
665-
ctypes.byref(prop),
666-
ctypes.c_int16(1),
667-
ctypes.c_int16(aux_output_enable),
668-
ctypes.c_uint32(auto_trigger_us),
669-
)
670-
671-
def set_trigger_channel_directions(
672-
self,
673-
channel: int,
674-
direction: int,
675-
threshold_mode: int,
676-
) -> None:
677-
"""Specify the trigger direction for ``channel``.
678-
679-
Args:
680-
channel (int): Channel to configure.
681-
direction (int): Direction value from
682-
:class:`PICO_THRESHOLD_DIRECTION`.
683-
threshold_mode (int): Threshold mode from
684-
:class:`PICO_THRESHOLD_MODE`.
685-
"""
686-
687-
dir_struct = PICO_DIRECTION(channel, direction, threshold_mode)
688-
689-
self._call_attr_function(
690-
"SetTriggerChannelDirections",
691-
self.handle,
692-
ctypes.byref(dir_struct),
693-
ctypes.c_int16(1),
694-
)
695603

696604
def set_data_buffer(
697605
self,

0 commit comments

Comments
 (0)