Commit a9815863 authored by Joel Collins's avatar Joel Collins
Browse files

Close the camera if the stage cannot be opened

parent 6b9a3443
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from flask import (
    Flask, render_template)

from flask.logging import default_handler
from serial import SerialException

from flask_cors import CORS

@@ -71,8 +72,12 @@ def attach_microscope():
    api_camera = StreamingCamera(config=api_microscope.rc.read())
    
    logging.debug("Creating stage object...")
    try:
        api_stage = Stage("/dev/ttyUSB0")

    except SerialException as e:
        api_camera.close()
        raise e
    else:
        logging.debug("Attaching devices to microscope...")
        api_microscope.attach(
            api_camera,