Skip to main content
Glama
markuskreitzer

PicoScope MCP Server

set_simple_trigger

Configure basic edge triggering on PicoScope oscilloscopes by setting source channel, voltage threshold, edge direction, and auto-trigger timeout for signal capture.

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
NameRequiredDescriptionDefault
sourceYes
threshold_mvYes
directionNoRising
auto_trigger_msNo

Implementation Reference

  • Handler function for set_simple_trigger tool: validates inputs, maps to TriggerConfig, calls device_manager.set_trigger, returns status.
    @mcp.tool()
    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),
            }
  • Registration block calling register_acquisition_tools(mcp), which defines and registers the set_simple_trigger tool via @mcp.tool() decorator.
    register_discovery_tools(mcp)
    register_configuration_tools(mcp)
    register_acquisition_tools(mcp)
    register_analysis_tools(mcp)
    register_advanced_tools(mcp)
  • Supporting method in device_manager that implements the actual trigger setup using PicoSDK's ps5000aSetSimpleTrigger, called by the tool handler.
    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
  • Dataclass defining the TriggerConfig structure used by the tool for input validation and passing to device_manager.set_trigger.
    @dataclass
    class TriggerConfig:
        """Trigger configuration settings."""
    
        source: str
        threshold_mv: float
        direction: TriggerDirection
        auto_trigger_ms: int
  • Enum defining TriggerDirection options matching the tool's direction parameter Literals.
    class TriggerDirection(str, Enum):
        """Trigger direction options."""
    
        RISING = "Rising"
        FALLING = "Falling"
        RISING_OR_FALLING = "Rising_Or_Falling"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/markuskreitzer/picoscope_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server