From cc73aec2577b9c3d918629fccd4db18af96552de Mon Sep 17 00:00:00 2001 From: Kaspar Emanuel Date: Wed, 2 Dec 2020 10:43:43 +0000 Subject: [PATCH] Detect picamera in use error --- openflexure_microscope/rescue/check_picamera.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/openflexure_microscope/rescue/check_picamera.py b/openflexure_microscope/rescue/check_picamera.py index c41126c7..1088ca1e 100644 --- a/openflexure_microscope/rescue/check_picamera.py +++ b/openflexure_microscope/rescue/check_picamera.py @@ -13,13 +13,17 @@ picamera_errors = ( "Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.", ) +picamera_mmal_errors = { + "Failed to enable connection: Out of resources": "Camera already in use by another application." +} + def main(): error_sources = [] logging.info("Attempting to import picamera...") try: - from picamerax import PiCamera + import picamerax except Exception as e: # pylint: disable=W0703 # TODO: Parse exception object for a few different issues, and append # different error sources E.g. pi with camera already in use, @@ -27,12 +31,14 @@ def main(): logging.error(e) error_sources.append(picamera_import_error) else: - import picamerax.exc.PiCameraError - try: - cam = PiCamera() - except picamerax.exc.PiCameraError as e: + cam = picamerax.PiCamera() + except picamerax.PiCameraError as e: if e.args[0] in picamera_errors: error_sources.append(ErrorSource(e.args[0])) + elif e.args[0] in picamera_mmal_errors: + error_sources.append(ErrorSource(picamera_mmal_errors[e.args[0]])) + else: + error_sources.append(ErrorSource(e.args[0])) return error_sources