Skip to content

Screen Capture

Screenshot capture functionality

Screen capture functionality for Siglent oscilloscopes.

This module provides functionality to capture screenshots from the oscilloscope's display in various image formats.

ScreenCapture

ScreenCapture(oscilloscope)

Handles screenshot capture from oscilloscope display.

Supports capturing the oscilloscope screen in PNG, BMP, and JPEG formats.

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 screenshot from oscilloscope display using SCDP command.

Note: The SCDP command returns the screen image in the oscilloscope's native format (typically BMP). The image_format parameter is ignored for Siglent scopes using SCDP. To convert to other formats, use PIL/Pillow after capture.

Parameters:

Name Type Description Default
image_format str

Desired format (currently ignored, SCDP returns BMP)

'BMP'

Returns:

Type Description
bytes

Binary image data (typically BMP format)

Raises:

Type Description
RuntimeError

If capture fails

Example

scope = Oscilloscope('192.168.1.100') scope.connect() image_data = scope.screen_capture.capture_screenshot() with open("screenshot.bmp", "wb") as f: ... f.write(image_data)

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

    Note: The SCDP command returns the screen image in the oscilloscope's
    native format (typically BMP). The image_format parameter is ignored
    for Siglent scopes using SCDP. To convert to other formats, use PIL/Pillow
    after capture.

    Args:
        image_format: Desired format (currently ignored, SCDP returns BMP)

    Returns:
        Binary image data (typically BMP format)

    Raises:
        RuntimeError: If capture fails

    Example:
        >>> scope = Oscilloscope('192.168.1.100')
        >>> scope.connect()
        >>> image_data = scope.screen_capture.capture_screenshot()
        >>> with open("screenshot.bmp", "wb") as f:
        ...     f.write(image_data)
    """
    logger.info(f"Capturing screenshot using SCDP command")

    try:
        # For Siglent oscilloscopes, use SCDP command (Screen Dump)
        # This is the standard command per Siglent programming manual
        logger.debug("Using SCDP command for screenshot capture")
        image_data = self._capture_with_scdp()
        if image_data:
            logger.info(f"Screenshot captured successfully ({len(image_data)} bytes)")
            return image_data
        else:
            raise RuntimeError("SCDP returned empty 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 screenshot to file.

Note: The SCDP command returns images in BMP format. If you specify a different extension (e.g., .png), the file will still contain BMP data. Use get_screenshot_pil() and PIL to convert formats if needed.

Parameters:

Name Type Description Default
filename str

Output file path (recommend using .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 PIL/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 screenshot to file.

    Note: The SCDP command returns images in BMP format. If you specify
    a different extension (e.g., .png), the file will still contain BMP
    data. Use get_screenshot_pil() and PIL to convert formats if needed.

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

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

        To save as PNG (requires PIL/Pillow):
        >>> img = scope.screen_capture.get_screenshot_pil()
        >>> img.save("capture.png", "PNG")
    """
    # Capture screenshot using SCDP (returns BMP format)
    image_data = self.capture_screenshot()

    # Save to file (data will be in BMP format regardless of filename)
    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 screenshot and return as PIL Image object.

Requires PIL/Pillow to be installed. Use this method to convert the BMP screenshot to other formats.

Returns:

Type Description

PIL.Image object (loaded from BMP data)

Raises:

Type Description
ImportError

If PIL is not installed

Example

Capture and display

img = scope.screen_capture.get_screenshot_pil() img.show()

Capture and save as PNG

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

Capture and save as JPEG with quality

img = scope.screen_capture.get_screenshot_pil() img.save("screenshot.jpg", "JPEG", quality=95)

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

    Requires PIL/Pillow to be installed.
    Use this method to convert the BMP screenshot to other formats.

    Returns:
        PIL.Image object (loaded from BMP data)

    Raises:
        ImportError: If PIL is not installed

    Example:
        >>> # Capture and display
        >>> img = scope.screen_capture.get_screenshot_pil()
        >>> img.show()

        >>> # Capture and save as PNG
        >>> img = scope.screen_capture.get_screenshot_pil()
        >>> img.save("screenshot.png", "PNG")

        >>> # Capture and save as JPEG with quality
        >>> img = scope.screen_capture.get_screenshot_pil()
        >>> img.save("screenshot.jpg", "JPEG", quality=95)
    """
    try:
        from PIL import Image
    except ImportError:
        raise ImportError("PIL/Pillow is required for this function. Install with: pip install Pillow")

    # Capture screenshot (returns BMP format from SCDP)
    image_data = self.capture_screenshot()
    return Image.open(BytesIO(image_data))

See Also

  • Oscilloscope - Main oscilloscope control class for SCPI communication