set_simple_trigger
Configure basic edge triggering on PicoScope oscilloscopes by setting source channel, voltage threshold, edge direction, and auto-trigger timeout to capture specific signal events.
Instructions
Set up a simple edge trigger.
Args: source: Trigger source channel or external. threshold_mv: Trigger threshold in millivolts. direction: Trigger on rising, falling, or either edge. auto_trigger_ms: Auto-trigger timeout in milliseconds (0 = disabled).
Returns: Dictionary containing trigger configuration status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| auto_trigger_ms | No | ||
| direction | No | Rising | |
| source | Yes | ||
| threshold_mv | Yes |
Implementation Reference
- The MCP tool handler for 'set_simple_trigger'. Parses arguments, maps to TriggerConfig, calls device_manager.set_trigger, and returns status.def set_simple_trigger( source: Literal["A", "B", "C", "D", "External"], threshold_mv: float, direction: Literal["Rising", "Falling", "Rising_Or_Falling"] = "Rising", auto_trigger_ms: int = 1000, ) -> dict[str, Any]: """Set up a simple edge trigger. Args: source: Trigger source channel or external. threshold_mv: Trigger threshold in millivolts. direction: Trigger on rising, falling, or either edge. auto_trigger_ms: Auto-trigger timeout in milliseconds (0 = disabled). Returns: Dictionary containing trigger configuration status. """ try: if not device_manager.is_connected(): return { "status": "error", "error": "No device connected", } # Map direction string to enum direction_map = { "Rising": TriggerDirection.RISING, "Falling": TriggerDirection.FALLING, "Rising_Or_Falling": TriggerDirection.RISING_OR_FALLING, } # Create trigger config config = TriggerConfig( source=source, threshold_mv=threshold_mv, direction=direction_map[direction], auto_trigger_ms=auto_trigger_ms, ) # Set trigger success = device_manager.set_trigger(config) if success: return { "status": "success", "source": source, "threshold_mv": threshold_mv, "direction": direction, "auto_trigger_ms": auto_trigger_ms, } else: return { "status": "error", "error": "Failed to set trigger", } except Exception as e: return { "status": "error", "error": str(e), }
- src/picoscope_mcp/server.py:17-17 (registration)Registration of acquisition tools (including set_simple_trigger) by calling register_acquisition_tools on the MCP server instance.register_acquisition_tools(mcp)
- src/picoscope_mcp/models.py:58-65 (schema)Dataclass defining the TriggerConfig model used to pass trigger parameters to device_manager.set_trigger.class TriggerConfig: """Trigger configuration settings.""" source: str threshold_mv: float direction: TriggerDirection auto_trigger_ms: int
- src/picoscope_mcp/models.py:15-20 (schema)Enum defining TriggerDirection used in TriggerConfig for set_simple_trigger.class TriggerDirection(str, Enum): """Trigger direction options.""" RISING = "Rising" FALLING = "Falling" RISING_OR_FALLING = "Rising_Or_Falling"
- Supporting method in device_manager that implements the trigger setup by calling the PicoSDK ps5000aSetSimpleTrigger function.def set_trigger(self, config: TriggerConfig) -> bool: """Set up trigger. Args: config: Trigger configuration. Returns: True if successful, False otherwise. """ if not self.is_connected(): return False try: # Map source to channel source_map = { "A": ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"], "B": ps.PS5000A_CHANNEL["PS5000A_CHANNEL_B"], "C": ps.PS5000A_CHANNEL["PS5000A_CHANNEL_C"], "D": ps.PS5000A_CHANNEL["PS5000A_CHANNEL_D"], "External": ps.PS5000A_CHANNEL["PS5000A_EXTERNAL"], } if config.source not in source_map: return False # Map trigger direction direction_map = { "Rising": ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_RISING"], "Falling": ps.PS5000A_THRESHOLD_DIRECTION["PS5000A_FALLING"], "Rising_Or_Falling": ps.PS5000A_THRESHOLD_DIRECTION[ "PS5000A_RISING_OR_FALLING" ], } direction = direction_map[config.direction.value] # Convert threshold from mV to ADC counts # Use the configured range for the source channel if available if config.source in self.channel_configs: ch_config = self.channel_configs[config.source] range_map = { 0.02: "PS5000A_20MV", 0.05: "PS5000A_50MV", 0.1: "PS5000A_100MV", 0.2: "PS5000A_200MV", 0.5: "PS5000A_500MV", 1.0: "PS5000A_1V", 2.0: "PS5000A_2V", 5.0: "PS5000A_5V", 10.0: "PS5000A_10V", 20.0: "PS5000A_20V", } closest_range = min( range_map.keys(), key=lambda x: abs(x - ch_config.voltage_range) ) voltage_range = ps.PS5000A_RANGE[range_map[closest_range]] else: voltage_range = ps.PS5000A_RANGE["PS5000A_2V"] # Default threshold_adc = mV2adc( config.threshold_mv, voltage_range, self.device_info.max_adc_value if self.device_info else 32767, ) # Set simple trigger self.status["trigger"] = ps.ps5000aSetSimpleTrigger( self.chandle, 1, # Enable trigger source_map[config.source], threshold_adc, direction, 0, # Delay (samples) config.auto_trigger_ms, # Auto-trigger timeout ) assert_pico_ok(self.status["trigger"]) return True except Exception as e: return False