Closing a capture using the Saleae API

I am using the Saleae automation API offered for Logic 2 software. The way my code flow is to be designed is such that I should be able to close a Capture that has already been started whenever I intend to. The API offers the ‘close()’ method for this. However, I am not able to figure out the correct way to use this method in my script. Can anyone please suggest a solution to this issue?

@rosengarg123 Using the with statement (i.e. with manager.start_capture) will automatically call manager.close() when exiting the scope. The advantage of this method is that, if an error occurs before exiting the scope, then manager closes it for you.

Otherwise, if you want to close() manually, you’ll need to call either wait() or stop() before trying to save, export, or close the capture as described here under start_capture.

Hope that helps!

@timreyes It seems like the ‘wait()’ method waits for the capture to complete its duration (in TimedCaptureMode) and then frees the thread. How can I use the ‘close()’ method if I want to stop the capture in between manually ?

@rosengarg123 In that case, you’ll want to call stop() before you call close(). Alternatively, you can call stop() and exit the with statement scope for that capture session afterwards to close that session automatically.

@timreyes Thanks for your help. I was able to stop the capture manually.

1 Like