Beispiel #1
0
    def setParameter(self, name, value):
        """Set parameter. The value is automatically typecast to the correct data type corresponding to the type of parameter.

        .. note:: Setting a parameter with this function does not automatically change the configuration in the camera. In order to apply all changes, :py:func:`sendConfiguration` has to be called.

        :param str name: Name of the parameter exactly as stated in the PICam SDK manual.
        :param mixed value: New parameter value. If the parameter value cannot be changed, a warning is printed to stdout.
        """
        prm = pit.PicamParameter[name]

        exists = pit.pibln()
        self.lib.Picam_DoesParameterExist(self.cam, prm, ptr(exists))
        if not exists:
            print("Ignoring parameter", name)
            print("  Parameter does not exist for current camera!")
            return

        access = pit.piint()
        self.lib.Picam_GetParameterValueAccess(self.cam, prm, ptr(access))
        if pit.PicamValueAccessLookup[access.value] not in [
                "ReadWrite", "ReadWriteTrivial"
        ]:
            print("Ignoring parameter", name)
            print("  Not allowed to overwrite parameter!")
            return
        if pit.PicamValueAccessLookup[access.value] == "ReadWriteTrivial":
            print("WARNING: Parameter", name, " allows only one value!")

        # get type of parameter
        type = pit.piint()
        self.lib.Picam_GetParameterValueType(self.cam, prm, ptr(type))

        if type.value not in pit.PicamValueTypeLookup:
            print("Ignoring parameter", name)
            print("  Not a valid parameter type:", type.value)
            return

        if pit.PicamValueTypeLookup[type.value] in [
                "Integer", "Boolean", "Enumeration"
        ]:
            val = pit.piint(value)
            self.lib.Picam_SetParameterIntegerValue(self.cam, prm, val)

        if pit.PicamValueTypeLookup[type.value] == "LargeInteger":
            val = pit.pi64s(value)
            self.lib.Picam_SetParameterLargeIntegerValue(self.cam, prm, val)

        if pit.PicamValueTypeLookup[type.value] == "FloatingPoint":
            val = pit.piflt(value)
            self.lib.Picam_SetParameterFloatingPointValue(self.cam, prm, val)

        if pit.PicamValueTypeLookup[type.value] == "Rois":
            self.lib.Picam_SetParameterRoisValue(self.cam, prm, ptr(value))

        if pit.PicamValueTypeLookup[type.value] == "Pulse":
            self.lib.Picam_SetParameterPulseValue(self.cam, prm, ptr(value))

        if pit.PicamValueTypeLookup[type.value] == "Modulations":
            self.lib.Picam_SetParameterModulationsValue(
                self.cam, prm, ptr(value))
Beispiel #2
0
 def StartAcquisition(self, N=1, timeout=10000):
     self.available = pit.PicamAvailableData()
     errors = pit.piint()
     running = pit.pibln()
     self.lib.Picam_IsAcquisitionRunning(self.cam, ptr(running))
     if running.value:
         print("ERROR: acquisition still running")
         return []
     t = time.time()
     self.lib.Picam_Acquire(self.cam, pit.pi64s(N), pit.piint(timeout),
                            ptr(self.available), ptr(errors))
     print("Durée de l'acquisition : %f s" % (time.time() - t))
Beispiel #3
0
 def sendConfiguration(self):
     """This function has to be called once all configurations are done to apply settings to the camera.
     """
     failed = ptr(pit.piint())
     failedCount = pit.piint()
     self.lib.Picam_CommitParameters(self.cam, ptr(failed),
                                     ptr(failedCount))
     if failedCount.value > 0:
         for i in range(failedCount.value):
             print("Could not set parameter",
                   pit.PicamParameterLookup[failed[i]])
     self.lib.Picam_DestroyParameters(failed)
Beispiel #4
0
    def getAvailableCameras(self):
        """Queries a list of IDs of cameras that are connected to the computer and prints some sensor information for each camera to stdout.

        If no physical camera is found, a demo camera is initialized - *for debug only*.
        """
        if self.camIDs is not None and not isinstance(self.camIDs, list):
            self.lib.Picam_DestroyCameraIDs(self.camIDs)
            self.camIDs = None

        # get connected cameras
        self.camIDs = ptr(pit.PicamCameraID())
        id_count = pit.piint()
        self.lib.Picam_GetAvailableCameraIDs(ptr(self.camIDs), ptr(id_count))

        # if none are found, create a demo camera
        print("Available Cameras:")
        if id_count.value < 1:
            self.lib.Picam_DestroyCameraIDs(self.camIDs)

            model_array = ptr(pit.piint())
            model_count = pit.piint()
            self.lib.Picam_GetAvailableDemoCameraModels(
                ptr(model_array), ptr(model_count))

            model_ID = pit.PicamCameraID()
            serial = ctypes.c_char_p(b"Demo Cam 1")
            self.lib.Picam_ConnectDemoCamera(model_array[67], serial,
                                             ptr(model_ID))
            self.camIDs = [model_ID]

            self.lib.Picam_DestroyModels(model_array)

            print('  Model is ', pit.PicamModelLookup[model_ID.model])
            print(
                '  Computer interface is ',
                pit.PicamComputerInterfaceLookup[model_ID.computer_interface])
            print('  Sensor_name is ', model_ID.sensor_name)
            print('  Serial number is', model_ID.serial_number)
            print('\n')
        else:
            for i in range(id_count.value):
                print('  Model is ',
                      pit.PicamModelLookup[self.camIDs[i].model])
                print(
                    '  Computer interface is ',
                    pit.PicamComputerInterfaceLookup[
                        self.camIDs[i].computer_interface])
                print('  Sensor_name is ', self.camIDs[i].sensor_name)
                print('  Serial number is', self.camIDs[i].serial_number)
                print('\n')
Beispiel #5
0
 def Acquisition(self, N=1, timeout=10000):
     print('Acquire')
     self.available = pit.PicamAvailableData()
     errors = pit.piint()
     running = pit.pibln()
     self.lib.Picam_IsAcquisitionRunning(self.cam, ptr(running))
     #print('running value',running.value)
     if running.value:
         print("ERROR: acquisition still running")
         return []
     t = time.time()
     self.lib.Picam_Acquire(self.cam, pit.pi64s(N), pit.piint(timeout),
                            ptr(self.available), ptr(errors))
     #(cameraHandel,readoutcount,readouttimeout,outpoutParameter=avaible,outpouterrors)
     # print(self.getParameter("ReadoutCount"))
     print("Durée de l'acquisition : %f s" % (time.time() - t))
     #        print(errors)
     return t
Beispiel #6
0
    def getParameter(self, name):
        prm = pit.PicamParameter[name]
        exists = pit.pibln()
        self.lib.Picam_DoesParameterExist(self.cam, prm, ptr(exists))

        # get type of parameter
        type = pit.piint()
        self.lib.Picam_GetParameterValueType(self.cam, prm, ptr(type))

        if pit.PicamValueTypeLookup[type.value] in [
                "Integer", "Boolean", "Enumeration"
        ]:
            val = pit.piint()

            # test whether we can read the value directly from hardware
            cr = pit.pibln()
            self.lib.Picam_CanReadParameter(self.cam, prm, ptr(cr))
            if cr.value:
                if self.lib.Picam_ReadParameterIntegerValue(
                        self.cam, prm, ptr(val)) == 0:
                    return val.value
            else:
                if self.lib.Picam_GetParameterIntegerValue(
                        self.cam, prm, ptr(val)) == 0:
                    return val.value

        if pit.PicamValueTypeLookup[type.value] == "LargeInteger":
            val = pit.pi64s()
            if self.lib.Picam_GetParameterLargeIntegerValue(
                    self.cam, prm, ptr(val)) == 0:
                return val.value

        if pit.PicamValueTypeLookup[type.value] == "FloatingPoint":
            val = pit.piflt()

            # NEW
            # test whether we can read the value directly from hardware
            cr = pit.pibln()
            self.lib.Picam_CanReadParameter(self.cam, prm, ptr(cr))
            if cr.value:
                if self.lib.Picam_ReadParameterFloatingPointValue(
                        self.cam, prm, ptr(val)) == 0:
                    return val.value
            else:
                if self.lib.Picam_GetParameterFloatingPointValue(
                        self.cam, prm, ptr(val)) == 0:
                    return val.value

        if pit.PicamValueTypeLookup[type.value] == "Rois":
            val = ptr(pit.PicamRois())
            if self.lib.Picam_GetParameterRoisValue(self.cam, prm,
                                                    ptr(val)) == 0:
                self.roisPtr.append(val)
                return val.contents

        if pit.PicamValueTypeLookup[type.value] == "Pulse":
            val = ptr(pit.PicamPulse())
            if self.lib.Picam_GetParameterPulseValue(self.cam, prm,
                                                     ptr(val)) == 0:
                self.pulsePtr.append(val)
                return val.contents

        if pit.PicamValueTypeLookup[type.value] == "Modulations":
            val = ptr(pit.PicamModulations())
            if self.lib.Picam_GetParameterModulationsValue(
                    self.cam, prm, ptr(val)) == 0:
                self.modPtr.append(val)
                return val.contents

        return None
Beispiel #7
0
    def printAvailableParameters(self):
        """Prints an overview over the parameters to stdout that are available for the current camera and their limits.
        """
        parameter_array = ptr(pit.piint())
        parameter_count = pit.piint()
        self.lib.Picam_GetParameters(self.cam, ptr(parameter_array),
                                     ptr(parameter_count))

        for i in range(parameter_count.value):

            # read / write access
            access = pit.piint()
            self.lib.Picam_GetParameterValueAccess(self.cam,
                                                   parameter_array[i],
                                                   ptr(access))
            readable = pit.PicamValueAccessLookup[access.value]

            # constraints
            contype = pit.piint()
            self.lib.Picam_GetParameterConstraintType(self.cam,
                                                      parameter_array[i],
                                                      ptr(contype))

            if pit.PicamConstraintTypeLookup[contype.value] == "None":
                constraint = "ALL"

            elif pit.PicamConstraintTypeLookup[contype.value] == "Range":

                c = ptr(pit.PicamRangeConstraint())
                self.lib.Picam_GetParameterRangeConstraint(
                    self.cam, parameter_array[i],
                    pit.PicamConstraintCategory['Capable'], ptr(c))

                constraint = "from %f to %f in steps of %f" % (
                    c[0].minimum, c[0].maximum, c[0].increment)

                self.lib.Picam_DestroyRangeConstraints(c)

            elif pit.PicamConstraintTypeLookup[contype.value] == "Collection":

                c = ptr(pit.PicamCollectionConstraint())
                self.lib.Picam_GetParameterCollectionConstraint(
                    self.cam, parameter_array[i],
                    pit.PicamConstraintCategory['Capable'], ptr(c))

                constraint = ""
                for j in range(c[0].values_count):
                    if constraint != "":
                        constraint += ", "
                    constraint += str(c[0].values_array[j])

                self.lib.Picam_DestroyCollectionConstraints(c)

            elif pit.PicamConstraintTypeLookup[contype.value] == "Rois":
                constraint = "N.A."
            elif pit.PicamConstraintTypeLookup[contype.value] == "Pulse":
                constraint = "N.A."
            elif pit.PicamConstraintTypeLookup[contype.value] == "Modulations":
                constraint = "N.A."

            # print(infos
            print(pit.PicamParameterLookup[parameter_array[i]])
            print(" value access:", readable)
            print(" allowed values:", constraint)
            print("\n")

        self.lib.Picam_DestroyParameters(parameter_array)
Beispiel #8
0
    def getAvailableCameras(self):
        """Queries a list of IDs of cameras that are connected to the computer and prints some sensor information for each camera to stdout.

        If no physical camera is found, a demo camera is initialized - *for debug only*.
        """
        if self.camIDs is not None and not isinstance(self.camIDs, list):
            self.lib.Picam_DestroyCameraIDs(self.camIDs)
            self.camIDs = None

        # get connected cameras
        self.camIDs = ptr(pit.PicamCameraID())
        id_count = pit.piint()
        self.lib.Picam_GetAvailableCameraIDs(ptr(self.camIDs), ptr(id_count))
        #        print('ids',self.camIDs,id_count)
        print('number of camera connected : ', id_count.value)
        modele = []
        sensorName = []
        serialNumber = []
        # if none are found, create a demo camera
        #        print("Available Cameras:")
        if id_count.value < 1:
            print('demo')
            msg = QMessageBox()
            msg.setText("Camera not connected")
            msg.setInformativeText(
                "Please check connexions, or driver certificate (see  unsigned Driver procedure)"
            )
            msg.setWindowTitle("Warning")
            msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
            msg.exec_()
            self.lib.Picam_DestroyCameraIDs(self.camIDs)
            connected = False
#            model_array = ptr(pit.piint())
#            model_count = pit.piint()
#            self.lib.Picam_GetAvailableDemoCameraModels(ptr(model_array), ptr(model_count))
#
#            model_ID = pit.PicamCameraID()
#            serial = ctypes.c_char_p(b"Demo Cam 1")
#            self.lib.Picam_ConnectDemoCamera(model_array[67], serial, ptr(model_ID))
#            self.camIDs = [model_ID]
#
#            self.lib.Picam_DestroyModels(model_array)
#
#            print('  Model is ', pit.PicamModelLookup[model_ID.model])
#            print('  Computer interface is ', pit.PicamComputerInterfaceLookup[model_ID.computer_interface])
#            print('  Sensor_name is ', model_ID.sensor_name)
#            print('  Serial number is', model_ID.serial_number)
#            print('\n')
#
        else:
            connected = True
            #            print ('mte')
            for i in range(
                    id_count.value):  # à supprimer si la camera est une MTE
                #                print('  Model is ', pit.PicamModelLookup[self.camIDs[i].model])
                try:
                    modele.append(pit.PicamModelLookup[self.camIDs[i].model])
                except:
                    pass
#                print('  Computer interface is ', pit.PicamComputerInterfaceLookup[self.camIDs[i].computer_interface])
#                print('  Sensor_name is ', self.camIDs[i].sensor_name)
#                print('  Serial number is', self.camIDs[i].serial_number)
#                print('\n')
                try:
                    sensorName.append(self.camIDs[i].sensor_name)
                except:
                    pass
                try:
                    serialNumber.append(self.camIDs[i].serial_number)
                except:
                    pass

        return (modele, sensorName, serialNumber, connected)
Beispiel #9
0
 def WaitForAcquistionUpdate(self, timeout=10000):
     self.available = pit.PicamAvailableData()
     status = ptr(pit.PicamAcquisitionStatus())
     self.lib.Picam_Acquire(self.cam, pit.piint(timeout),
                            ptr(self.available), ptr(status))