mabl / PyPylon

An experimental python wrapper around the Basler Pylon 5 library
BSD 3-Clause "New" or "Revised" License
53 stars 34 forks source link

Failure to recover from RuntimeError when grabbing multiple images #21

Open RichardLangFromNZ opened 8 years ago

RichardLangFromNZ commented 8 years ago

Running Pylon libraries from within linux Mint 18 VM on Windows 7 VirtualBox host.

Occasionally get

"RuntimeError: The buffer was incompletely grabbed. This can be caused by performance problems of the network hardware used, i.e. network adapter, switch, or ethernet cable. To fix this, try increasing the camera's Inter-Packet Delay in the Transport Layer category to reduce the required bandwidth, and adjust the camera's Packet Size setting to the highest supported frame size."

thrown on camera.grab_image() call (due to delays/issues with VM network adapter bridge to host physical adapter I guess) however if the exception is caught, subsequent calls to grab_image() will complete successfully.

However if I try to grab multiple images using the grab_images() method, as follows

while True:
    try:
        for image in cam.grab_images(N):
            ...    
    except RuntimeError
        ...

once the above mentioned exception has occurred, all further calls to grab_images() fail with an un-commented RuntimeError.

ZacDiggum commented 8 years ago

I made a PR and added a stop_grabbing() function and infinite grabbing and put a StopGrabbing() statement into __del__(). On catching the exception you could try cam.__del__() and then re-initialize. Maybe that helps. BTW, thanks for the nogil trick. My threaded PyQt app runs a lot more stable now.

mabl commented 8 years ago

I think it might be a good idea to check if the camera is still grabbing and stop it before restarting it. Also checking while still being in the iterator. I'll try this sooninsh, as I'm not in the lab and with the camera atm.

RichardLangFromNZ commented 8 years ago

I've pulled down Zac's PR and had a play and a call to stop_grabbing() inside the exception handler fixes this issue.

Once https://github.com/mabl/PyPylon/pull/17 is merged I'll generate a another PR on top of it that wraps the grab_images() internals with an exception handler that calls stop_grabbing() before re-raising, to relieve clients of burden of knowing that they need to do this.

RichardLangFromNZ commented 8 years ago

Fix in PR https://github.com/mabl/PyPylon/pull/22