@@ -140,6 +140,8 @@ def __init__(
140
140
self ._objective : Optional [Objective ] = None
141
141
self ._slow_mode : Optional [bool ] = None
142
142
143
+ self ._acquiring = False
144
+
143
145
async def setup (self , use_cam : bool = False ) -> None :
144
146
logger .info ("[cytation5] setting up" )
145
147
@@ -438,6 +440,9 @@ async def _load_objectives(self):
438
440
raise RuntimeError (f"Unsupported version: { self .version } " )
439
441
440
442
async def stop (self ) -> None :
443
+ if self ._acquiring :
444
+ self .stop_acquisition ()
445
+
441
446
logger .info ("[cytation5] stopping" )
442
447
await self .stop_shaking ()
443
448
await self .io .stop ()
@@ -844,6 +849,18 @@ def _get_device_info(self, cam):
844
849
845
850
return device_info
846
851
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
+
847
864
async def led_on (self , intensity : int = 10 ):
848
865
if not 1 <= intensity <= 10 :
849
866
raise ValueError ("intensity must be between 1 and 10" )
@@ -1222,6 +1239,7 @@ async def capture(
1222
1239
overlap : Optional [float ] = None ,
1223
1240
color_processing_algorithm : int = SPINNAKER_COLOR_PROCESSING_ALGORITHM_HQ_LINEAR ,
1224
1241
pixel_format : int = PixelFormat_Mono8 ,
1242
+ auto_stop_acquisition = True ,
1225
1243
) -> ImagingResult :
1226
1244
"""Capture image using the microscope
1227
1245
@@ -1245,7 +1263,9 @@ async def capture(
1245
1263
if self .cam is None :
1246
1264
raise ValueError ("Camera not initialized. Run setup(use_cam=True) first." )
1247
1265
1248
- self .cam .BeginAcquisition ()
1266
+ if not self ._acquiring :
1267
+ self .start_acquisition ()
1268
+
1249
1269
try :
1250
1270
await self .set_objective (objective )
1251
1271
await self .set_imaging_mode (mode , led_intensity = led_intensity )
@@ -1305,7 +1325,8 @@ def image_size(magnification: float) -> Tuple[float, float]:
1305
1325
t1 - t0 ,
1306
1326
)
1307
1327
finally :
1308
- self .cam .EndAcquisition ()
1328
+ if auto_stop_acquisition :
1329
+ self .stop_acquisition ()
1309
1330
1310
1331
exposure_ms = float (self .cam .ExposureTime .GetValue ()) / 1000
1311
1332
assert self ._focal_height is not None , "Focal height not set. Run set_focus() first."
0 commit comments