def acquisition_oneshot(self): """ Simple one shot image grabbing. Returns an autonomous numpy array """ # Arm camera pf.PCO_ArmCamera(self.handle) XResAct, YResAct, XResMax, YResMax = pf.PCO_GetSizes(self.handle) with PCO_Buffer(self.handle, XResAct, YResAct) as buffer: try: pf.PCO_SetImageParameters( self.handle, XResAct, YResAct, pf.IMAGEPARAMETERS_READ_WHILE_RECORDING, ) pf.PCO_SetRecordingState(self.handle, True) pf.PCO_GetImageEx(self.handle, 1, 0, 0, buffer.bufNr, XResAct, YResAct, 16) array = buffer.as_array().copy() finally: pf.PCO_SetRecordingState(self.handle, False) pf.PCO_CancelImages(self.handle) return array
def acquisition_oneshot(self): """Concrete implementation of :meth:`pymanip.video.Camera.acquisition_oneshot` for the PCO camera. """ # Arm camera pf.PCO_ArmCamera(self.handle) XResAct, YResAct, XResMax, YResMax = pf.PCO_GetSizes(self.handle) with PCO_Buffer(self.handle, XResAct, YResAct) as buffer: try: pf.PCO_SetImageParameters( self.handle, XResAct, YResAct, pf.IMAGEPARAMETERS_READ_WHILE_RECORDING, ) pf.PCO_SetRecordingState(self.handle, True) pf.PCO_GetImageEx( self.handle, 1, 0, 0, buffer.bufNr, XResAct, YResAct, 16 ) array = buffer.as_array().copy() finally: pf.PCO_SetRecordingState(self.handle, False) pf.PCO_CancelImages(self.handle) return array
async def acquisition_async( self, num=np.inf, timeout=None, raw=False, initialising_cams=None, raise_on_timeout=True, ): """ Multiple image acquisition yields a shared memory numpy array valid only before generator object cleanup. timeout in milliseconds """ loop = asyncio.get_event_loop() if timeout is None: delay, exposure = self.current_delay_exposure_time() timeout = int(max((2000 * exposure, 1000))) # Arm camera if pf.PCO_GetRecordingState(self.handle): pf.PCO_SetRecordingState(self.handle, False) pf.PCO_ArmCamera(self.handle) warn, err, status = self.health_status() if err != 0: raise RuntimeError("Camera has error status!") XResAct, YResAct, XResMax, YResMax = pf.PCO_GetSizes(self.handle) with PCO_Buffer(self.handle, XResAct, YResAct) as buf1, PCO_Buffer( self.handle, XResAct, YResAct) as buf2, PCO_Buffer( self.handle, XResAct, YResAct) as buf3, PCO_Buffer(self.handle, XResAct, YResAct) as buf4: buffers = (buf1, buf2, buf3, buf4) try: pf.PCO_SetImageParameters( self.handle, XResAct, YResAct, pf.IMAGEPARAMETERS_READ_WHILE_RECORDING, ) pf.PCO_SetRecordingState(self.handle, True) for buffer in buffers: pf.PCO_AddBufferEx(self.handle, 0, 0, buffer.bufNr, XResAct, YResAct, 16) count = 0 buffer_ring = itertools.cycle(buffers) while count < num: if (count == 0 and initialising_cams is not None and self in initialising_cams): initialising_cams.remove(self) waitstat = await loop.run_in_executor( None, win32event.WaitForMultipleObjects, [buffer.event_handle for buffer in buffers], 0, timeout, ) if waitstat == win32event.WAIT_TIMEOUT: if raise_on_timeout: raise CameraTimeout(f"Timeout ({timeout:})") else: stop_signal = yield None if not stop_signal: continue else: break for ii, buffer in zip(range(4), buffer_ring): waitstat = await loop.run_in_executor( None, win32event.WaitForSingleObject, buffer.event_handle, 0) if waitstat == win32event.WAIT_OBJECT_0: win32event.ResetEvent(buffer.event_handle) statusDLL, statusDrv = pf.PCO_GetBufferStatus( self.handle, buffer.bufNr) if statusDrv != 0: raise RuntimeError( "buffer {:} error status {:}".format( buffer.bufNr, statusDrv)) if raw: data = {"buffer": buffer.bytes()} if self.timestamp_mode: counter, dt = PCO_get_binary_timestamp( buffer.bufPtr[:14]) data["counter"] = counter data["timestamp"] = dt stop_signal = yield data else: if self.metadata_mode: metadata = pf.PCO_GetMetaData( self.handle, buffer.bufNr) stop_signal = yield MetadataArray( buffer.as_array(), metadata=metadata) elif self.timestamp_mode: counter, dt = PCO_get_binary_timestamp( buffer.bufPtr[:14]) stop_signal = yield MetadataArray( buffer.as_array(), metadata={ "counter": counter, "timestamp": dt }, ) else: stop_signal = yield buffer.as_array() count += 1 pf.PCO_AddBufferEx(self.handle, 0, 0, buffer.bufNr, XResAct, YResAct, 16) else: break if stop_signal: break if stop_signal: break finally: pf.PCO_SetRecordingState(self.handle, False) pf.PCO_CancelImages(self.handle) if stop_signal: yield True