Microscope now only attaches to hardware once an API request is made.
This commit is contained in:
parent
ad5ec79305
commit
3b28f8c4ca
2 changed files with 46 additions and 13 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"""
|
||||
Defines a microscope object, binding a camera and stage with basic functionality.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import numpy as np
|
||||
|
||||
from openflexure_stage import OpenFlexureStage
|
||||
|
|
@ -20,11 +20,7 @@ class Microscope(object):
|
|||
microscope (:py:class:`openflexure_stage.stage.OpenFlexureStage`): stage object
|
||||
"""
|
||||
def __init__(self, camera: StreamingCamera, stage: OpenFlexureStage):
|
||||
print("Assigning camera")
|
||||
self.camera = camera #: :py:class:`openflexure_microscope.camera.pi.StreamingCamera`: Picamera object
|
||||
print("Assigning stage")
|
||||
self.stage = stage #: :py:class:`openflexure_stage.stage.OpenFlexureStage`: OpenFlexure stage object
|
||||
self.stage.backlash = np.zeros(3, dtype=np.int)
|
||||
self.attach(camera, stage)
|
||||
|
||||
def __enter__(self):
|
||||
"""Create microscope on context enter."""
|
||||
|
|
@ -38,6 +34,27 @@ class Microscope(object):
|
|||
"""Shut down the microscope hardware."""
|
||||
self.camera.close()
|
||||
self.stage.close()
|
||||
|
||||
def attach(self, camera: StreamingCamera, stage: OpenFlexureStage):
|
||||
"""
|
||||
Retroactively attaches a camera and stage to the microscope object.
|
||||
|
||||
Allows the microscope to be created as a "dummy", with hardware communications
|
||||
opened at a later time.
|
||||
|
||||
Args:
|
||||
camera (:py:class:`openflexure_microscope.camera.pi.StreamingCamera`): camera object
|
||||
microscope (:py:class:`openflexure_stage.stage.OpenFlexureStage`): stage object
|
||||
"""
|
||||
|
||||
self.camera = camera #: :py:class:`openflexure_microscope.camera.pi.StreamingCamera`: Picamera object
|
||||
if isinstance(camera, StreamingCamera):
|
||||
logging.info("Attached camera {}".format(camera))
|
||||
|
||||
self.stage = stage #: :py:class:`openflexure_stage.stage.OpenFlexureStage`: OpenFlexure stage object
|
||||
if isinstance(self.stage, OpenFlexureStage): # If a stage object has been attached
|
||||
logging.info("Attached stage {}".format(stage))
|
||||
self.stage.backlash = np.zeros(3, dtype=np.int)
|
||||
|
||||
# Create unified state
|
||||
@property
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue