disconnect_device
Disconnect from a connected PicoScope oscilloscope device to end measurement sessions or switch instruments. Returns disconnection status confirmation.
Instructions
Disconnect from the currently connected PicoScope device.
Returns: Dictionary containing disconnection status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The core handler function for the 'disconnect_device' tool. It is decorated with @mcp.tool() and implements the disconnection logic by calling device_manager methods and returning a status dictionary.@mcp.tool() def disconnect_device() -> dict[str, Any]: """Disconnect from the currently connected PicoScope device. Returns: Dictionary containing disconnection status. """ try: if not device_manager.is_connected(): return { "status": "warning", "message": "No device was connected", "connected": False, } success = device_manager.disconnect() if success: return { "status": "success", "message": "Device disconnected successfully", "connected": False, } else: return { "status": "error", "error": "Failed to disconnect device", } except Exception as e: return { "status": "error", "error": str(e), }
- src/picoscope_mcp/server.py:15-15 (registration)The call to register_discovery_tools(mcp) in the main server file, which triggers the registration of the disconnect_device tool (along with other discovery tools).register_discovery_tools(mcp)
- The underlying disconnect method in PicoScopeManager (instantiated as device_manager) that performs the actual device disconnection using PicoSDK calls.def disconnect(self) -> bool: """Disconnect from current device. Returns: True if disconnection successful, False otherwise. """ try: if self.chandle: # Stop any running capture ps.ps5000aStop(self.chandle) # Close the unit ps.ps5000aCloseUnit(self.chandle) self.chandle = None self.current_device = None self.device_info = None self.channel_configs.clear() self.status.clear() return True except Exception as e: return False
- The is_connected helper method used by the disconnect_device tool to check connection status before attempting disconnect.def is_connected(self) -> bool: """Check if a device is currently connected. Returns: True if connected, False otherwise. """ return self.current_device is not None