@@ -140,6 +140,8 @@ def __init__(
140140 self ._objective : Optional [Objective ] = None
141141 self ._slow_mode : Optional [bool ] = None
142142
143+ self ._acquiring = False
144+
143145 async def setup (self , use_cam : bool = False ) -> None :
144146 logger .info ("[cytation5] setting up" )
145147
@@ -438,6 +440,9 @@ async def _load_objectives(self):
438440 raise RuntimeError (f"Unsupported version: { self .version } " )
439441
440442 async def stop (self ) -> None :
443+ if self ._acquiring :
444+ self .stop_acquisition ()
445+
441446 logger .info ("[cytation5] stopping" )
442447 await self .stop_shaking ()
443448 await self .io .stop ()
@@ -844,6 +849,18 @@ def _get_device_info(self, cam):
844849
845850 return device_info
846851
852+ def start_acquisition (self ):
853+ if self .cam is None :
854+ raise RuntimeError ("Camera is not initialized." )
855+ self .cam .BeginAcquisition ()
856+ self ._acquiring = True
857+
858+ def stop_acquisition (self ):
859+ if self .cam is None :
860+ raise RuntimeError ("Camera is not initialized." )
861+ self .cam .EndAcquisition ()
862+ self ._acquiring = False
863+
847864 async def led_on (self , intensity : int = 10 ):
848865 if not 1 <= intensity <= 10 :
849866 raise ValueError ("intensity must be between 1 and 10" )
@@ -1222,6 +1239,7 @@ async def capture(
12221239 overlap : Optional [float ] = None ,
12231240 color_processing_algorithm : int = SPINNAKER_COLOR_PROCESSING_ALGORITHM_HQ_LINEAR ,
12241241 pixel_format : int = PixelFormat_Mono8 ,
1242+ auto_stop_acquisition = True ,
12251243 ) -> ImagingResult :
12261244 """Capture image using the microscope
12271245
@@ -1245,7 +1263,9 @@ async def capture(
12451263 if self .cam is None :
12461264 raise ValueError ("Camera not initialized. Run setup(use_cam=True) first." )
12471265
1248- self .cam .BeginAcquisition ()
1266+ if not self ._acquiring :
1267+ self .start_acquisition ()
1268+
12491269 try :
12501270 await self .set_objective (objective )
12511271 await self .set_imaging_mode (mode , led_intensity = led_intensity )
@@ -1305,7 +1325,8 @@ def image_size(magnification: float) -> Tuple[float, float]:
13051325 t1 - t0 ,
13061326 )
13071327 finally :
1308- self .cam .EndAcquisition ()
1328+ if auto_stop_acquisition :
1329+ self .stop_acquisition ()
13091330
13101331 exposure_ms = float (self .cam .ExposureTime .GetValue ()) / 1000
13111332 assert self ._focal_height is not None , "Focal height not set. Run set_focus() first."
0 commit comments