Skip to content

Screen Capture

Screenshot capture functionality

Screen capture functionality for Siglent oscilloscopes.

Captures the oscilloscope's display via the SCDP (screen dump) command. Modern Siglent scopes (e.g. SDS800X HD) return a raw BMP whose length is carried in the BMP header; older/other models may return an IEEE-488.2 definite-length block. Both are handled by reading exactly the number of bytes the response declares, rather than over-reading a fixed large size (which times out and drops the connection on the modern models).

ScreenCapture

ScreenCapture(oscilloscope)

Handles screenshot capture from an oscilloscope display.

The scope returns its screen as a BMP; use get_screenshot_pil() (requires Pillow) to convert to PNG/JPEG.

Initialize screen capture.

Parameters:

Name Type Description Default
oscilloscope

Parent Oscilloscope instance

required
Source code in scpi_control/screen_capture.py
def __init__(self, oscilloscope):
    """Initialize screen capture.

    Args:
        oscilloscope: Parent Oscilloscope instance
    """
    self._scope = oscilloscope

capture_screenshot

capture_screenshot(image_format: str = 'BMP') -> bytes

Capture a screenshot from the oscilloscope display via SCDP.

The SCDP command returns the screen image in the scope's native format (BMP on current Siglent models). image_format is accepted for backwards compatibility but ignored; use get_screenshot_pil() to convert.

Parameters:

Name Type Description Default
image_format str

Ignored (SCDP returns the scope's native format).

'BMP'

Returns:

Type Description
bytes

Binary image data (BMP).

Raises:

Type Description
RuntimeError

If capture fails.

Example

scope = Oscilloscope('192.168.1.100') scope.connect() data = scope.screen_capture.capture_screenshot() open("screenshot.bmp", "wb").write(data)

Source code in scpi_control/screen_capture.py
def capture_screenshot(self, image_format: str = "BMP") -> bytes:
    """Capture a screenshot from the oscilloscope display via SCDP.

    The SCDP command returns the screen image in the scope's native format
    (BMP on current Siglent models). ``image_format`` is accepted for
    backwards compatibility but ignored; use get_screenshot_pil() to convert.

    Args:
        image_format: Ignored (SCDP returns the scope's native format).

    Returns:
        Binary image data (BMP).

    Raises:
        RuntimeError: If capture fails.

    Example:
        >>> scope = Oscilloscope('192.168.1.100')
        >>> scope.connect()
        >>> data = scope.screen_capture.capture_screenshot()
        >>> open("screenshot.bmp", "wb").write(data)
    """
    logger.info("Capturing screenshot using SCDP command")
    try:
        image_data = self._capture_with_scdp()
        if not image_data:
            raise RuntimeError("SCDP returned empty data")
        logger.info(f"Screenshot captured successfully ({len(image_data)} bytes)")
        return image_data
    except Exception as e:
        logger.error(f"Screenshot capture failed: {e}")
        raise RuntimeError(f"Failed to capture screenshot: {e}")

save_screenshot

save_screenshot(filename: str, image_format: Optional[str] = None) -> None

Capture and save a screenshot to a file.

The SCDP command returns BMP data. If you pass a different extension (e.g. .png), the file will still contain BMP bytes -- use get_screenshot_pil() and Pillow to convert formats.

Parameters:

Name Type Description Default
filename str

Output file path (recommend a .bmp extension).

required
image_format Optional[str]

Ignored (SCDP always returns BMP).

None
Example

scope.screen_capture.save_screenshot("capture.bmp")

To save as PNG (requires Pillow):

img = scope.screen_capture.get_screenshot_pil() img.save("capture.png", "PNG")

Source code in scpi_control/screen_capture.py
def save_screenshot(self, filename: str, image_format: Optional[str] = None) -> None:
    """Capture and save a screenshot to a file.

    The SCDP command returns BMP data. If you pass a different extension
    (e.g. .png), the file will still contain BMP bytes -- use
    get_screenshot_pil() and Pillow to convert formats.

    Args:
        filename: Output file path (recommend a .bmp extension).
        image_format: Ignored (SCDP always returns BMP).

    Example:
        >>> scope.screen_capture.save_screenshot("capture.bmp")

        To save as PNG (requires Pillow):
        >>> img = scope.screen_capture.get_screenshot_pil()
        >>> img.save("capture.png", "PNG")
    """
    image_data = self.capture_screenshot()
    with open(filename, "wb") as f:
        f.write(image_data)
    logger.info(f"Screenshot saved to {filename} (BMP format)")

get_screenshot_pil

get_screenshot_pil()

Capture a screenshot and return it as a PIL Image.

Requires Pillow. Use this to convert the BMP screen dump to other formats.

Returns:

Type Description

PIL.Image loaded from the captured BMP data.

Raises:

Type Description
ImportError

If Pillow is not installed.

Example

img = scope.screen_capture.get_screenshot_pil() img.save("screenshot.png", "PNG")

Source code in scpi_control/screen_capture.py
def get_screenshot_pil(self):
    """Capture a screenshot and return it as a PIL Image.

    Requires Pillow. Use this to convert the BMP screen dump to other formats.

    Returns:
        PIL.Image loaded from the captured BMP data.

    Raises:
        ImportError: If Pillow is not installed.

    Example:
        >>> img = scope.screen_capture.get_screenshot_pil()
        >>> img.save("screenshot.png", "PNG")
    """
    try:
        from PIL import Image
    except ImportError:
        raise ImportError("PIL/Pillow is required for this function. Install with: pip install Pillow")

    image_data = self.capture_screenshot()
    return Image.open(BytesIO(image_data))

See Also

  • Oscilloscope - Main oscilloscope control class for SCPI communication