def _getInterfaceInfos(self): """ Gets interface info of all available interfaces. :returns: list -- interface info for available interfaces. """ if self._interfaceInfos is None: # args dummyInterfaceInfo = structs.VimbaInterfaceInfo() numFound = c_uint32(-1) # call once just to get the number of interfaces # Vimba DLL will return an error code errorCode = VimbaDLL.interfacesList(byref(dummyInterfaceInfo), 0, byref(numFound), sizeof(dummyInterfaceInfo)) if errorCode != 0: print errorCode raise VimbaException(errorCode) numInterfaces = numFound.value # args interfaceInfoArray = (structs.VimbaInterfaceInfo * numInterfaces)() # call again to get the features # Vimba DLL will return an error code errorCode = VimbaDLL.interfacesList(interfaceInfoArray, numInterfaces, byref(numFound), sizeof(dummyInterfaceInfo)) if errorCode != 0: raise VimbaException(errorCode) self._interfaceInfos = list( interfaceInfo for interfaceInfo in interfaceInfoArray) return self._interfaceInfos
def _getCameraInfos(self): """ Gets camera info of all attached cameras. :returns: list -- camera info for available cameras. """ if self._cameraInfos is None: # args dummyCameraInfo = structs.VimbaCameraInfo() numFound = c_uint32(-1) # call once just to get the number of cameras # Vimba DLL will return an error code errorCode = VimbaDLL.camerasList(byref(dummyCameraInfo), 0, byref(numFound), sizeof(dummyCameraInfo)) if errorCode != 0 and errorCode != -9: print errorCode raise VimbaException(errorCode) numCameras = numFound.value # args cameraInfoArray = (structs.VimbaCameraInfo * numCameras)() # call again to get the features # Vimba DLL will return an error code errorCode = VimbaDLL.camerasList(cameraInfoArray, numCameras, byref(numFound), sizeof(dummyCameraInfo)) if errorCode != 0: raise VimbaException(errorCode) self._cameraInfos = list(camInfo for camInfo in cameraInfoArray) return self._cameraInfos
def readRegister(self, address): # note that the underlying Vimba function allows reading of an array # of registers, but only one address/value at a time is implemented # here """ Read from a register of the module (camera). :param address: the address of the register to read. :returns: int -- value of register. """ readCount = 1 # check address validity try: regAddress = c_uint64(int(address, 16)) except: raise VimbaException(-52) regData = c_uint64() numCompleteReads = c_uint32() errorCode = VimbaDLL.registersRead(self.handle, readCount, byref(regAddress), byref(regData), byref(numCompleteReads)) if errorCode != 0: raise VimbaException(errorCode) return regData.value
def writeRegister(self, address, value): # note that the underlying Vimba function allows writing of an array # of registers, but only one address/value at a time is implemented # here """ Read from a register of the module (camera). :param address: the address of the register to read. :param value: the value to set in hex. """ writeCount = 1 # check address validity try: regAddress = c_uint64(int(address, 16)) except: raise VimbaException(-52) # check value validity try: regData = c_uint64(int(value, 16)) except: raise VimbaException(-52) numCompleteWrites = c_uint32() errorCode = VimbaDLL.registersWrite(self.handle, writeCount, byref(regAddress), byref(regData), byref(numCompleteWrites)) if errorCode != 0: raise VimbaException(errorCode)
def revokeFrame(self): """ Revoke a frame from the API. """ errorCode = VimbaDLL.frameRevoke(self._handle, byref(self._frame)) if errorCode != 0: raise VimbaException(errorCode)
def announceFrame(self): """ Announce frames to the API that may be queued for frame capturing later. Runs VmbFrameAnnounce Should be called after the frame is created. Call startCapture after this method. """ # size of expected frame sizeOfFrame = self.payloadSize # keep this reference to keep block alive for life of frame self._cMem = VimbaC_MemoryBlock(sizeOfFrame) # set buffer to have length of expected payload size self._frame.buffer = self._cMem.block # set buffer size to expected payload size self._frame.bufferSize = sizeOfFrame errorCode = VimbaDLL.frameAnnounce(self._handle, byref(self._frame), sizeof(self._frame)) if errorCode != 0: raise VimbaException(errorCode)
def queueFrameCapture(self, frameCallback=None): """ Queue frames that may be filled during frame capturing. Runs VmbCaptureFrameQueue Call after announceFrame and startCapture Callback must accept argument of type frame. Remember to requeue the frame by calling frame.queueFrameCapture(frameCallback) at the end of your callback function. """ # remember the given callback function self._frameCallback = frameCallback # define a callback wrapper here so it doesn't bind self def frameCallbackWrapper(cam_handle, p_frame): # call the user's callback with the self bound outside the wrapper # ignore the frame pointer since we already know the callback # refers to this frame self._frameCallback(self) if self._frameCallback is None: self._frameCallbackWrapper_C = None else: # keep a reference to prevent gc issues self._frameCallbackWrapper_C = VimbaDLL.frameDoneCallback( frameCallbackWrapper) errorCode = VimbaDLL.captureFrameQueue(self._handle, byref(self._frame), self._frameCallbackWrapper_C) if errorCode != 0: raise VimbaException(errorCode)
def closeInterface(self): """ Close the interface. """ errorCode = VimbaDLL.interfaceClose(self._handle) if errorCode != 0: raise VimbaException(errorCode)
def closeCamera(self): """ Close the camera. """ errorCode = VimbaDLL.cameraClose(self._handle) if errorCode != 0: raise VimbaException(errorCode)
def flushCaptureQueue(self): """ Flush the capture queue. """ errorCode = VimbaDLL.captureQueueFlush(self._handle) if errorCode != 0: raise VimbaException(errorCode)
def revokeAllFrames(self): """ Revoke all frames assigned to the camera. """ errorCode = VimbaDLL.frameRevokeAll(self._handle) if errorCode != 0: raise VimbaException(errorCode)
def startCapture(self): """ Prepare the API for incoming frames. """ errorCode = VimbaDLL.captureStart(self._handle) if errorCode != 0: raise VimbaException(errorCode)
def endCapture(self): """ Stop the API from being able to receive frames. """ errorCode = VimbaDLL.captureEnd(self._handle) if errorCode != 0: raise VimbaException(errorCode)
def waitFrameCapture(self, timeout=2000): """ Wait for a queued frame to be filled (or dequeued). """ errorCode = VimbaDLL.captureFrameWait(self._handle, byref(self._frame), timeout) if errorCode != 0: raise VimbaException(errorCode)
def startup(self): """ Initialize the VimbaC API. """ # Vimba DLL will return an error code errorCode = VimbaDLL.startup() if errorCode != 0: raise VimbaException(errorCode)
def openInterface(self): """ Open the interface. """ errorCode = VimbaDLL.interfaceOpen(self._interfaceIdString, byref(self._handle)) if errorCode != 0: raise VimbaException(errorCode)
def queueFrameCapture(self): """ Queue frames that may be filled during frame capturing. """ errorCode = VimbaDLL.captureFrameQueue( self._handle, byref(self._frame), None) # callback not implemented, callback example in pico? if errorCode != 0: raise VimbaException(errorCode)
def runFeatureCommand(self, featureName): """ Run a feature command. :param featureName: the name of the feature. """ # run a command errorCode = VimbaDLL.featureCommandRun(self._handle, featureName) if errorCode != 0: raise VimbaException(errorCode)
def _getFeatureInfos(self): """ Gets feature info of all available features. Will cause error if object/camera is not opened. :returns: list -- feature info for available features. """ # check it's populated as can't populate it in __init__ if self._featureInfos is None: # args dummyFeatureInfo = structs.VimbaFeatureInfo() numFound = c_uint32(-1) # call once to get number of available features # Vimba DLL will return an error code errorCode = VimbaDLL.featuresList(self._handle, byref(dummyFeatureInfo), 0, byref(numFound), sizeof(dummyFeatureInfo)) if errorCode != 0: raise VimbaException(errorCode) # number of features specified by Vimba numFeatures = numFound.value # args featureInfoArray = (structs.VimbaFeatureInfo * numFeatures)() # call again to get the features # Vimba DLL will return an error code errorCode = VimbaDLL.featuresList(self._handle, featureInfoArray, numFeatures, byref(numFound), sizeof(dummyFeatureInfo)) if errorCode != 0: raise VimbaException(errorCode) self._featureInfos = list( featInfo for featInfo in featureInfoArray) return self._featureInfos
def __init__(self, blockSize): # assign memory block malloc = self._crtDLL.malloc malloc.argtypes = (c_size_t, ) malloc.restype = c_void_p self._block = malloc(blockSize) # todo check for NULL on failure # this seems to be None if too much memory is requested if self._block is None: raise VimbaException(-51)
def openCamera(self): """ Open the camera. """ # args for Vimba call cameraAccessMode = 1 # full access (see VmbAccessModeType) errorCode = VimbaDLL.cameraOpen(self._cameraIdString, cameraAccessMode, byref(self._handle)) if errorCode != 0: raise VimbaException(errorCode)
def _setIntFeature(self, valueToSet): """ Set the value of an integer feature. :param valueToSet: the int value to set for the feature. """ errorCode = VimbaDLL.featureIntSet(self._handle, self._name, valueToSet) if errorCode != 0: raise VimbaException(errorCode)
def _setFloatFeature(self, valueToSet): """ Set the value of a float feature. :param valueToSet: the float value to set for the feature. """ errorCode = VimbaDLL.featureFloatSet(self._handle, self._name, valueToSet) if errorCode != 0: raise VimbaException(errorCode)
def _setEnumFeature(self, valueToSet): """ Set the value of an enum feature. :param valueToSet: the enum value to set for the feature. """ errorCode = VimbaDLL.featureEnumSet(self._handle, self._name, valueToSet) if errorCode != 0: raise VimbaException(errorCode)
def _setStringFeature(self, valueToSet): """ Set the value of a string feature. :param valueToSet: the string value to set for the feature. """ errorCode = VimbaDLL.featureStringSet(self._handle, self._name, valueToSet) if errorCode != 0: raise VimbaException(errorCode)
def _setBoolFeature(self, valueToSet): """ Set the value of a bool feature. :param valueToSet: the bool value to set for the feature. """ errorCode = VimbaDLL.featureBoolSet(self._handle, self._name, valueToSet) if errorCode != 0: raise VimbaException(errorCode)
def getCameraInfo(self, cameraId): """ Gets camera info object of specified camera. :param cameraId: the ID of the camera object to get. :returns: VimbaCameraInfo object -- the camera info object specified. """ # don't do this live as we already have this info # return info object if it exists for camInfo in self._getCameraInfos(): if camInfo.cameraIdString == cameraId: return camInfo # otherwise raise error raise VimbaException(-50)
def getFeatureInfo(self, featureName): """ Gets feature info object of specified feature. :param featureName: the name of the feature. :returns: VimbaFeatureInfo object -- the feature info object specified. """ # don't do this live as we already have this info # return info object, if it exists for featInfo in self._getFeatureInfos(): if featInfo.name == featureName: return featInfo # otherwise raise error raise VimbaException(-53)
def getInterfaceInfo(self, interfaceId): """ Gets interface info object of specified interface. :param interfaceId: the ID of the interface object to get. :returns: VimbaInterfaceInfo object -- the interface info object specified. """ # don't do this live as we already have this info # return info object if it exists for interfaceInfo in self._getInterfaceInfos(): if interfaceInfo.interfaceIdString == interfaceId: return interfaceInfo # otherwise raise error raise VimbaException(-54)
def getCamera(self, cameraId): """ Gets camera object based on camera ID string. Will not recreate camera object if it already exists. :param cameraId: the ID of the camera. :returns: VimbaCamera object -- the camera object specified. """ # check ID is valid if cameraId in self.getCameraIds(): # create it if it doesn't exist if cameraId not in self._cameras: self._cameras[cameraId] = VimbaCamera(cameraId) return self._cameras[cameraId] raise VimbaException(-50)