@@ -123,7 +123,7 @@ def _open_unit(self, serial_number:int=None, resolution:RESOLUTION=0) -> None:
123123 )
124124 self .resolution = resolution
125125
126- def close_unit (self ) -> int :
126+ def close_unit (self ) -> None :
127127 """
128128 Closes the PicoScope device and releases the hardware handle.
129129
@@ -135,6 +135,15 @@ def close_unit(self) -> int:
135135
136136 self ._get_attr_function ('CloseUnit' )(self .handle )
137137
138+ def stop (self ) -> None :
139+ """
140+ This function stops the scope device from sampling data
141+ """
142+ self ._call_attr_function (
143+ 'Stop' ,
144+ self .handle
145+ )
146+
138147 def is_ready (self ) -> None :
139148 """
140149 Blocks execution until the PicoScope device is ready.
@@ -204,7 +213,7 @@ def _get_enabled_channel_flags(self) -> int:
204213 enabled_channel_byte += 2 ** channel
205214 return enabled_channel_byte
206215
207- def get_nearest_sampling_interval (self , sample_rate :float ) -> dict :
216+ def get_nearest_sampling_interval (self , interval_s :float ) -> dict :
208217 """
209218 This function returns the nearest possible sample interval to the requested
210219 sample interval. It does not change the configuration of the oscilloscope.
@@ -213,18 +222,18 @@ def get_nearest_sampling_interval(self, sample_rate:float) -> dict:
213222 increase sample interval.
214223
215224 Args:
216- sample_rate (float): Time value in seconds (s) you would like to obtain.
225+ interval_s (float): Time value in seconds (s) you would like to obtain.
217226
218227 Returns:
219- dict: Dictionary of suggested timebase and actual sample interval.
228+ dict: Dictionary of suggested timebase and actual sample interval in seconds (s) .
220229 """
221230 timebase = ctypes .c_uint32 ()
222231 time_interval = ctypes .c_double ()
223232 self ._call_attr_function (
224233 'NearestSampleIntervalStateless' ,
225234 self .handle ,
226235 self ._get_enabled_channel_flags (),
227- ctypes .c_double (sample_rate ),
236+ ctypes .c_double (interval_s ),
228237 self .resolution ,
229238 ctypes .byref (timebase ),
230239 ctypes .byref (time_interval ),
@@ -293,6 +302,39 @@ def _get_timebase_2(self, timebase: int, samples: int, segment:int=0):
293302 return {"Interval(ns)" : time_interval_ns .value ,
294303 "Samples" : max_samples .value }
295304
305+ def sample_rate_to_timebase (self , sample_rate :float , unit = SAMPLE_RATE .MSPS ):
306+ """
307+ Converts sample rate to a PicoScope timebase value based on the
308+ attached PicoScope.
309+
310+ This function will return the closest possible timebase.
311+ Use `get_nearest_sample_interval(interval_s)` to get the full timebase and
312+ actual interval achieved.
313+
314+ Args:
315+ sample_rate (int): Desired sample rate
316+ unit (SAMPLE_RATE): unit of sample rate.
317+ """
318+ interval_s = 1 / (sample_rate * unit )
319+
320+ return self .get_nearest_sampling_interval (interval_s )["timebase" ]
321+
322+ def interval_to_timebase (self , interval :float , unit = TIME_UNIT .S ):
323+ """
324+ Converts a time interval (between samples) into a PicoScope timebase
325+ value based on the attached PicoScope.
326+
327+ This function will return the closest possible timebase.
328+ Use `get_nearest_sample_interval(interval_s)` to get the full timebase and
329+ actual interval achieved.
330+
331+ Args:
332+ interval (float): Desired time interval between samples
333+ unit (TIME_UNIT, optional): Time unit of interval.
334+ """
335+ interval_s = interval / unit
336+ return self .get_nearest_sampling_interval (interval_s )["timebase" ]
337+
296338 def _get_adc_limits (self ) -> tuple :
297339 """
298340 Gets the ADC limits for specified devices.
@@ -442,7 +484,7 @@ def _set_channel(self, channel, range, enabled=True, coupling=COUPLING.DC, offse
442484 )
443485 return self ._error_handler (status )
444486
445- def set_simple_trigger (self , channel , threshold_mv , enable = True , direction = TRIGGER_DIR .RISING , delay = 0 , auto_trigger_ms = 3000 ):
487+ def set_simple_trigger (self , channel , threshold_mv , enable = True , direction = TRIGGER_DIR .RISING , delay = 0 , auto_trigger = 0 ):
446488 """
447489 Sets up a simple trigger from a specified channel and threshold in mV
448490
@@ -452,7 +494,7 @@ def set_simple_trigger(self, channel, threshold_mv, enable=True, direction=TRIGG
452494 enable (bool, optional): Enables or disables the trigger.
453495 direction (TRIGGER_DIR, optional): Trigger direction (e.g., TRIGGER_DIR.RISING, TRIGGER_DIR.FALLING).
454496 delay (int, optional): Delay in samples after the trigger condition is met before starting capture.
455- auto_trigger_ms (int, optional): Timeout in milliseconds after which data capture proceeds even if no trigger occurs.
497+ auto_trigger (int, optional): Timeout after which data capture proceeds even if no trigger occurs.
456498 """
457499 threshold_adc = self .mv_to_adc (threshold_mv , self .range [channel ])
458500 self ._call_attr_function (
@@ -463,7 +505,7 @@ def set_simple_trigger(self, channel, threshold_mv, enable=True, direction=TRIGG
463505 threshold_adc ,
464506 direction ,
465507 delay ,
466- auto_trigger_ms
508+ auto_trigger
467509 )
468510
469511 def set_data_buffer_for_enabled_channels ():
@@ -747,6 +789,21 @@ def set_channel(self, channel:CHANNEL, range:RANGE, enabled=True, coupling:COUPL
747789 super ()._set_channel_on (channel , range , coupling , offset , bandwidth )
748790 else :
749791 super ()._set_channel_off (channel )
792+
793+ def set_simple_trigger (self , channel , threshold_mv , enable = True , direction = TRIGGER_DIR .RISING , delay = 0 , auto_trigger_ms = 5_000 ):
794+ """
795+ Sets up a simple trigger from a specified channel and threshold in mV
796+
797+ Args:
798+ channel (int): The input channel to apply the trigger to.
799+ threshold_mv (float): Trigger threshold level in millivolts.
800+ enable (bool, optional): Enables or disables the trigger.
801+ direction (TRIGGER_DIR, optional): Trigger direction (e.g., TRIGGER_DIR.RISING, TRIGGER_DIR.FALLING).
802+ delay (int, optional): Delay in samples after the trigger condition is met before starting capture.
803+ auto_trigger_ms (int, optional): Timeout in milliseconds after which data capture proceeds even if no trigger occurs.
804+ """
805+ auto_trigger_us = auto_trigger_ms * 1000
806+ return super ().set_simple_trigger (channel , threshold_mv , enable , direction , delay , auto_trigger_us )
750807
751808 def set_data_buffer (self , channel :CHANNEL , samples :int , segment :int = 0 , datatype :DATA_TYPE = DATA_TYPE .INT16_T ,
752809 ratio_mode :RATIO_MODE = RATIO_MODE .RAW , action :ACTION = ACTION .CLEAR_ALL | ACTION .ADD ) -> ctypes .Array :
@@ -870,6 +927,20 @@ def set_channel(self, channel, range, enabled=True, coupling=COUPLING.DC, offset
870927 def get_timebase (self , timebase , samples , segment = 0 ):
871928 return super ()._get_timebase_2 (timebase , samples , segment )
872929
930+ def set_simple_trigger (self , channel , threshold_mv , enable = True , direction = TRIGGER_DIR .RISING , delay = 0 , auto_trigger_ms = 5000 ):
931+ """
932+ Sets up a simple trigger from a specified channel and threshold in mV
933+
934+ Args:
935+ channel (int): The input channel to apply the trigger to.
936+ threshold_mv (float): Trigger threshold level in millivolts.
937+ enable (bool, optional): Enables or disables the trigger.
938+ direction (TRIGGER_DIR, optional): Trigger direction (e.g., TRIGGER_DIR.RISING, TRIGGER_DIR.FALLING).
939+ delay (int, optional): Delay in samples after the trigger condition is met before starting capture.
940+ auto_trigger_ms (int, optional): Timeout in milliseconds after which data capture proceeds even if no trigger occurs.
941+ """
942+ return super ().set_simple_trigger (channel , threshold_mv , enable , direction , delay , auto_trigger_ms )
943+
873944 def set_data_buffer (self , channel , samples , segment = 0 , ratio_mode = 0 ):
874945 return super ()._set_data_buffer_ps5000a (channel , samples , segment , ratio_mode )
875946
0 commit comments