ManualCaptureMode stops before calling stop()

I am trying to use ManualCaptureMode() and modify the sample code. However, the capture stops before calling stop(). Please find my code below. Anyone has the same issue? How to resolve it? Thanks!

from saleae import automation
import os
import os.path
from datetime import datetime
import time


class Logic2Operations:
    
    def __init__(self) -> None:
        self.application_path = "W:\\apps\\Logic\\Logic.exe"
        self.capture = None
        self.manager = None

    def open_app_capture_data(self):
        # open app with the Logic.exe location
        with automation.Manager.launch(self.application_path) as self.manager:
            print("Logic 2 is launching")

            # connect with logic2 device, logic2 default port number is 10430
            automation.Manager.connect(port=10430)
            print(f"Logic 2 is connected with port=10430")

            # set up device configuration
            device_configuration = automation.LogicDeviceConfiguration(
                enabled_digital_channels=[0, 1, 2, 3],
                digital_sample_rate=10_000_000,
                digital_threshold_volts=3.3,
            )
            # set up capture configuration
            capture_configuration = automation.CaptureConfiguration(
                # Looping mode in the software. Stop this capture with the stop() function
                capture_mode = automation.ManualCaptureMode(),
            )

            # start capture 
            # need to change device id, this one is demo pro 16
            try:
                self.capture = self.manager.start_capture(
                    device_id='F4241',
                    device_configuration = device_configuration,
                    capture_configuration = capture_configuration)
            except automation.DeviceError as e:
                print(f"Error starting capture:{e}")
            

    def stop_capture_close_app(self):
        if self.capture:
            # stop capturing 
            self.capture.stop()

            # import SPI 
            spi_analyzer = self.capture.add_analyzer('SPI', label=f'Test Analyzer', settings={
                'MISO': 0,
                'Clock': 1,
                'Enable': 2,
                'Bits per Transfer': '8 Bits per Transfer (Standard)'
            })

            # Store output in a timestamped directory
            output_dir = os.path.join(os.getcwd(), f'output-{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}')
            os.makedirs(output_dir)

            # Export analyzer data to a CSV file
            analyzer_export_filepath = os.path.join(output_dir, 'spi_export.csv')
            self.capture.export_data_table(
                filepath=analyzer_export_filepath,
                analyzers=[spi_analyzer]
            )

            # Export raw digital data to a CSV file
            self.capture.export_raw_data_csv(directory=output_dir, digital_channels=[0, 1, 2, 3])

            # Finally, save the capture to a file
            capture_filepath = os.path.join(output_dir, 'example_capture.sal')
            self.capture.save_capture(filepath=capture_filepath)

            # close app
            self.manager.close()

app = Logic2Operations()
app.open_app_capture_data()
print("waiting")
time.sleep(5)
app.stop_capture_close_app

Hi @yujieguo1990,

When using a context manager like with automation.Manager.launch(self.application_path) as self.manager:, self.manager will be cleaned up at the end of the scope. I would expect the Logic 2 application to close altogether when leaving that scope. You can see the relevant enter/exit code here: logic2-automation/python/saleae/automation/manager.py at develop · saleae/logic2-automation · GitHub

If you would prefer not to have this behavior, and manage the lifetime of the manager yourself. you can do:

self.manager = automation.Manager.launch(self.application_path)

and then later call

self.manager.close()

to cleanup the manager.

Hope that helps,

Ryan