Skip to main content
Glama
markuskreitzer

PicoScope MCP Server

configure_channel

Set up oscilloscope channels by adjusting coupling, voltage range, offset, and enabling/disabling for precise signal measurement.

Instructions

Configure a channel on the oscilloscope.

Args: channel: Channel identifier (A, B, C, or D). enabled: Whether the channel is enabled. coupling: AC or DC coupling. voltage_range: Voltage range in volts (e.g., 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20). analog_offset: DC offset voltage in volts.

Returns: Dictionary containing configuration status and applied settings.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channelYes
enabledNo
couplingNoDC
voltage_rangeNo
analog_offsetNo

Implementation Reference

  • The 'configure_channel' MCP tool handler, decorated with @mcp.tool(). It processes input arguments, constructs a ChannelConfig object, invokes the device_manager to apply the configuration, handles errors, and returns a status dictionary with applied settings.
    @mcp.tool()
    def configure_channel(
        channel: Literal["A", "B", "C", "D"],
        enabled: bool = True,
        coupling: Literal["AC", "DC"] = "DC",
        voltage_range: float = 5.0,
        analog_offset: float = 0.0,
    ) -> dict[str, Any]:
        """Configure a channel on the oscilloscope.
    
        Args:
            channel: Channel identifier (A, B, C, or D).
            enabled: Whether the channel is enabled.
            coupling: AC or DC coupling.
            voltage_range: Voltage range in volts (e.g., 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20).
            analog_offset: DC offset voltage in volts.
    
        Returns:
            Dictionary containing configuration status and applied settings.
        """
        try:
            if not device_manager.is_connected():
                return {
                    "status": "error",
                    "error": "No device connected",
                }
    
            # Create channel config
            config = ChannelConfig(
                channel=channel,
                enabled=enabled,
                coupling=ChannelCoupling.AC if coupling == "AC" else ChannelCoupling.DC,
                voltage_range=voltage_range,
                analog_offset=analog_offset,
            )
    
            # Configure the channel
            success = device_manager.configure_channel(config)
    
            if success:
                return {
                    "status": "success",
                    "channel": channel,
                    "enabled": enabled,
                    "coupling": coupling,
                    "voltage_range": voltage_range,
                    "analog_offset": analog_offset,
                }
            else:
                return {
                    "status": "error",
                    "error": "Failed to configure channel",
                    "channel": channel,
                }
    
        except Exception as e:
            return {
                "status": "error",
                "error": str(e),
                "channel": channel,
            }
  • Low-level 'configure_channel' method in PicoScopeManager class. Maps parameters to PicoSDK enums/constants, computes ADC values, calls ps5000aSetChannel API to configure the hardware channel, stores config, and returns success status.
    def configure_channel(self, config: ChannelConfig) -> bool:
        """Configure a channel.
    
        Args:
            config: Channel configuration.
    
        Returns:
            True if successful, False otherwise.
        """
        if not self.is_connected():
            return False
    
        try:
            # Map channel letter to PS5000A channel constant
            channel_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"],
            }
    
            if config.channel not in channel_map:
                return False
    
            # Map coupling type
            coupling = (
                ps.PS5000A_COUPLING["PS5000A_AC"]
                if config.coupling.value == "AC"
                else ps.PS5000A_COUPLING["PS5000A_DC"]
            )
    
            # Map voltage range to closest available range
            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",
            }
    
            # Find closest range
            closest_range = min(range_map.keys(), key=lambda x: abs(x - config.voltage_range))
            voltage_range = ps.PS5000A_RANGE[range_map[closest_range]]
    
            # Convert analog offset to ADC counts
            if self.device_info:
                analog_offset_adc = mV2adc(
                    config.analog_offset * 1000,  # V to mV
                    voltage_range,
                    self.device_info.max_adc_value
                )
            else:
                analog_offset_adc = 0
    
            # Set the channel
            self.status[f"setCh{config.channel}"] = ps.ps5000aSetChannel(
                self.chandle,
                channel_map[config.channel],
                1 if config.enabled else 0,
                coupling,
                voltage_range,
                analog_offset_adc
            )
    
            assert_pico_ok(self.status[f"setCh{config.channel}"])
    
            # Store configuration
            self.channel_configs[config.channel] = config
            return True
    
        except Exception as e:
            return False
  • ChannelConfig dataclass defining the structure for channel configuration data, used internally by the tool handler and device manager for type safety and validation.
    class ChannelConfig:
        """Channel configuration settings."""
    
        channel: str
        enabled: bool
        coupling: ChannelCoupling
        voltage_range: float
        analog_offset: float
  • Call to register_configuration_tools(mcp) in the main server setup, which registers the 'configure_channel' tool (and other configuration tools) with the FastMCP server instance.
    register_configuration_tools(mcp)

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