def _getCameraInfos(self): """ Gets camera info of all attached cameras. :returns: list -- camera info for available cameras. """ # 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: 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) return list(camInfo for camInfo in cameraInfoArray)
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(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 _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 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 revokeFrame(self): """ Revoke a frame from the API. """ errorCode = VimbaDLL.frameRevoke(self._handle, byref(self._frame)) 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 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 closeInterface(self): """ Close the interface. """ errorCode = VimbaDLL.interfaceClose(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 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 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 endCapture(self): """ Stop the API from being able to receive frames. """ errorCode = VimbaDLL.captureEnd(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 startCapture(self): """ Prepare the API for incoming frames. """ errorCode = VimbaDLL.captureStart(self._handle) 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 startup(self): """ Initialize the VimbaC API. """ # Vimba DLL will return an error code errorCode = VimbaDLL.startup() 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 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 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 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 _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 _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 _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 _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 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 _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 _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 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 _getEnumFeature(self): """ Get the value of an enum feature. :returns: enum -- value of the specified feature. """ # create args valueToGet = c_char_p() errorCode = VimbaDLL.featureEnumGet(self._handle, self._name, byref(valueToGet)) if errorCode != 0: raise VimbaException(errorCode) return valueToGet.value
def _getBoolFeature(self): """ Get the value of a bool feature. :returns: bool -- value of the specified feature. """ # create args valueToGet = c_bool() errorCode = VimbaDLL.featureBoolGet(self._handle, self._name, byref(valueToGet)) if errorCode != 0: raise VimbaException(errorCode) return valueToGet.value
def _getInfo(self): """ Get info of the feature. :returns: VimbaFeatureInfo object -- feature information.. """ # args for Vimba call featureInfo = structs.VimbaFeatureInfo() # Vimba DLL will return an error code errorCode = VimbaDLL.featureInfoQuery(self._handle, self._name, byref(featureInfo), sizeof(featureInfo)) if errorCode != 0: raise VimbaException(errorCode) return featureInfo
def _getFloatFeature(self): """ Get the value of a float feature. :returns: float -- value of the specified feature. """ # create args valueToGet = c_double() errorCode = VimbaDLL.featureFloatGet(self._handle, self._name, byref(valueToGet)) if errorCode != 0: raise VimbaException(errorCode) return valueToGet.value
def _getIntFeature(self): """ Get the value of an integer feature. :returns: int -- value of the specified feature. """ # create args valueToGet = c_int64() errorCode = VimbaDLL.featureIntGet(self._handle, self._name, byref(valueToGet)) if errorCode != 0: raise VimbaException(errorCode) return valueToGet.value
def _getInfo(self): """ Get info of the camera. Does not require the camera to be opened. :returns: VimbaCameraInfo object -- camera information. """ # args for Vimba call cameraInfo = structs.VimbaCameraInfo() # Vimba DLL will return an error code errorCode = VimbaDLL.cameraInfoQuery(self._cameraIdString, byref(cameraInfo), sizeof(cameraInfo)) if errorCode != 0: raise VimbaException(errorCode) return cameraInfo