def allocMemory(self, numBuffers, imageBytes, imageWidth, imageHeight,
                    strides, timeout):
        '''
        Clear the current array of memory and allocate a new one. Kill off the 
        old image-retrieval thread. Empty the imageQueue. Spawn a new thread to 
        replace the old one. We do this as the image size may have changed, which
        makes the old readImages() function invalid.
        '''
        # Halt any active read thread
        if self.readThread.isAlive():
            self.shouldReadImages = False
            self.readThread.join()

        # Wipe the list of images waiting to be read out
        with self.imageQueueLock:
            while not self.imagesQueue.empty():
                self.imagesQueue.get()

        # Flush the camera buffer and wipe the superBuffer, if it exists
        if not self.buffersQueue.empty():
            try:
                SDK3.Flush(self.handle)
            except SDK3.CameraError:
                print('Andor buffer could not be flushed')
                return 1
            while not self.buffersQueue.empty():
                self.buffersQueue.get()

        # Recreate the buffer
        for i in range(numBuffers):
            imageArray = np.zeros(imageBytes, dtype='uint16', order='C')
            self.buffersQueue.put(imageArray.data)
            try:
                SDK3.QueueBuffer(
                    self.handle,
                    imageArray.ctypes.data_as(SDK3.POINTER(SDK3.AT_U8)),
                    imageBytes)
            except SDK3.CameraError:
                print('ERROR: Cannot queue buffers')
                return 1

        # Starts the image polling thread
        self.shouldReadImages = True
        self.readThread = threading.Thread(
            target=self.readImages,
            args=(imageWidth, imageHeight, strides, timeout
                  ))  # a thread that is reading the images out of the buffers
        self.readThread.start()

        return 0
 def min(self):
     return SDK3.GetFloatMin(self.handle, self.propertyName).value
 def setValue(self, val):
     SDK3.SetFloat(self.handle, self.propertyName, val)
 def getValue(self):
     return SDK3.GetFloat(self.handle, self.propertyName).value
    def getUpdatedMemory(self,
                         imageWidth,
                         imageHeight,
                         imageBytes,
                         strides,
                         timeout=100):
        '''
        Wraps around AT_WaitBuffer. Retrieve a buffer of image data from Andor,
        then copy it to the provided buffer. The buffer from Andor consists of 
        either 11-bit or 16-bit pixels (in the 11-bit case, padded
        to 12 bits with a 0).
        Once we've copied the data out to outputBuffer, we re-zero the buffer
        that Andor wrote to, and then enqueue it so it can be re-used.
        '''
        try:
            bufferLocation, bufferLength = SDK3.WaitBuffer(
                self.handle, timeout)
        except SDK3.TimeoutError as e:
            # Both AT_ERR_TIMEDOUT and AT_ERR_NODATA get caught as TimeoutErrors
            if e.errNo == SDK3.AT_ERR_TIMEDOUT:
                #                 print('Timeout error') # TODO: add up log error report
                pass
            return
        except SDK3.CameraError as e:
            if not e.errNo == SDK3.AT_ERR_NODATA:
                print('No data error')  # TODO: add up log error report
            return

        # Get next element in the bufferQueue an verify that is the same as the one gotten by WaitBuffer
        imageBuffer = self.buffersQueue.get()
        if not imageBuffer.ctypes.data == ctypes.addressof(
                bufferLocation.contents):
            # Buffers are not the same. Raise error
            # TODO: add a clear buffers
            print((ctypes.addressof(bufferLocation.contents),
                   imageBuffer.ctypes.data))
            raise RuntimeError('Returned buffer not equal to expected buffer')
        else:
            # Buffers are correct
            # Make a new np array using the provided buffer but shaping the array correctly
            tempImageArray = np.ndarray(shape=[imageWidth, imageHeight],
                                        dtype='uint16',
                                        strides=[2, strides],
                                        buffer=imageBuffer)

            # Copy the np Array into a fresh array that will be returned
            imageArray = np.copy(tempImageArray)

            # Re-zero data in the buffer
            tempImageArray[:] = 0

            # requeue the buffer
            self.buffersQueue.put(imageBuffer)

            # requeue to andors buffer
            SDK3.QueueBuffer(
                self.handle,
                tempImageArray.ctypes.data_as(SDK3.POINTER(SDK3.AT_U8)),
                imageBytes)

            # delete the temporary array
            del tempImageArray

        return imageArray
 def __getitem__(self, key):
     return SDK3.GetEnumStringByIndex(self.handle, self.propertyName, key, 255).value
 def setString(self, val):
     SDK3.SetEnumString(self.handle, self.propertyName, val)
 def getIndex(self):
     return SDK3.GetEnumIndex(self.handle, self.propertyName).value
 def Init(self):
     self.handle = SDK3.Open(self.camNum)
     self.connectProperties()
def GetSoftwareVersion():
    return SDK3.GetString(SDK3.AT_HANDLE_SYSTEM, 'SoftwareVersion', 255)
def GetNumCameras():
    return SDK3.GetInt(SDK3.AT_HANDLE_SYSTEM, 'DeviceCount').value
 def unregCamera(cls):
     cls.numCameras -= 1
     if cls.numCameras == 0:
         SDK3.FinaliseLibrary()
    def regCamera(cls):
        if cls.numCameras == 0:
            SDK3.InitialiseLibrary()

        cls.numCameras += 1
 def __call__(self):
     return SDK3.Command(self.handle, self.propertyName)
 def getValue(self):
     return SDK3.GetString(self.handle, self.propertyName, 255).value
 def maxLength(self):
     return SDK3.GetStingMaxLength(self.handle, self.propertyName).value
 def GetSerialNumber(self):
     return SDK3.GetString(self.handle, 'SerialNumber', 64)
 def setIndex(self, val):
     SDK3.SetEnumIndex(self.handle, self.propertyName, val)
 def shutdown(self):
     SDK3.Close(self.handle)
     SDK3.FinaliseLibrary()
     print('Camera Closed and Andor library finalized.')
 def __len__(self):
     return SDK3.GetEnumCount(self.handle, self.propertyName).value
 def max(self):
     return SDK3.GetIntMax(self.handle, self.propertyName).value
    def getAvailableValues(self):
        n = SDK3.GetEnumCount(self.handle, self.propertyName).value

        return [SDK3.GetEnumStringByIndex(self.handle, self.propertyName, i, 255).value for i in range(n) if SDK3.IsEnumIndexAvailable(self.handle, self.propertyName, i).value]
 def getValue(self):
     return SDK3.GetBool(self.handle, self.propertyName).value > 0