def _setParamWithInt(self, parameter, value):
        """
        Short form of Fg_setParameterWithInt to reduce line length
        (since self.device and self.device_handle are always passed).

        Parameters
        ----------
        parameter : silicon software enum
            Defines the parameter, which should be read.

        value : int
            Value of parameter.
        """
        # Set retval to value which is not expected to be set a value
        # to ensure at least one iteration through the while loop
        retval = -99
        iterations = 0
        s.Fg_setParameterWithInt(self.device, parameter, value,
                                 self.device_handle)
        while retval != value:
            retval = self._getParamWithInt(parameter)
            if iterations > MAX_ITER:
                raise TimeoutError(
                    "Max iterations reached while waiting to set parameter!")
            iterations += 1
        # Sleep to fully apply setting... there have been timing issues...
        time.sleep(.1)
Beispiel #2
0
 def write_single_fg_command(self, command, value, paramnum=None):
     '''
     SDK Docs http://www.siliconsoftware.de/download/live_docu/RT5/en/documents/SDK/SDK.html#_2.3.1
     2.4.1 lists all parameters and values.
     '''
     if paramnum is None:
         parameter = self.cam_dict[command][1]
     else:
         parameter = self.cam_dict[command][1][paramnum]
     param = globals()[parameter]
     SISO.Fg_setParameterWithInt(self.fg, param, value, 0)
    def __init__(self, device_handle, applet='Acq_FullAreaGray8'):
        """
        Implementation of the microEnable4-VD4 framegrabber.
        Launches the camera in freerun mode (triggerMode 'off').

        # TODO: Init camera with previous applet or store settings?

        Parameters
        ----------
        device_handle : int
            Framegrabber device handle to identify the frame grabber

        applet : str
            String defining the used applet. Settings may differ between
            different applets
        """
        super(Camera, self).__init__(device_handle)
        self.logger = logging.getLogger(__name__)
        if LOGGING_LEVEL is not None:
            self.logger.setLevel(LOGGING_LEVEL)

        if s.Fg_getBoardType(device_handle) != s.PN_MICROENABLE4VD4CL:
            self.logger.error(
                'Board {0} is not supported by this package!'.format(
                    s.Fg_getBoardNameByType(s.Fg_getBoardType(device_handle),
                                            s.Fg_getBoardType(device_handle))))
            raise TypeError("Board {board} is not supported by this package!"
                            "".format(board=s.Fg_getBoardNameByType(s.Fg_getBoardType(device_handle),
                                            s.Fg_getBoardType(device_handle))))
        self._applet = applet
        self.logger.debug('Initializing Framegrabber...')

        self.device = s.Fg_InitEx(self._applet, device_handle, 0)

        # error handling
        err = s.Fg_getLastErrorNumber(self.device)
        if err < 0:
            msg = s.Fg_getErrorDescription(err)
            self.logger.error("Error", err, ":", msg)
            raise _MicroEnableException(err)
        else:
            self.logger.debug("Grabber initialized successfully!")

        self._clser_ref = s.clSerialInit(0)
        # Setting Camera link factory profile
        # Resolution: 1280x1024, Image freq.: 430, Mode: 8x8, CL-Conf.: FULL
        factory_profile = ':f7'
        self._clSerialWrite(command=factory_profile)

        s.Fg_setParameterWithInt(self.device, s.FG_BITALIGNMENT,
                                 s.FG_LEFT_ALIGNED, self.device_handle)
        s.Fg_setParameterWithInt(self.device, s.FG_GEN_ENABLE, s.FG_CAMPORT,
                                 self.device_handle)
        s.Fg_setParameterWithInt(self.device, s.FG_TRIGGER_LEGACY_MODE,
                                 s.FG_ON, self.device_handle)
        self.setTriggerMode('off')

        self._width = \
            s.Fg_getParameterWithInt(self.device, s.FG_WIDTH,
                                     self.device_handle)[1]
        self._height = \
            s.Fg_getParameterWithInt(self.device, s.FG_HEIGHT,
                                     self.device_handle)[1]

        self._free_run_buffer = self._prepareImageBuffer(10)

        self._pics_to_be_recorded = None
        self._buffer_handle = None
        self._img_list = list()

        self._apc_data = None
# error handling
err = s.Fg_getLastErrorNumber(fg)
mes = s.Fg_getErrorDescription(err)

if err < 0:
    print("Error", err, ":", mes)
    sys.exit()
else:
    print("ok")

# allocating memory
memHandle = s.Fg_AllocMemEx(fg, totalBufferSize, nbBuffers)

# Set Applet Parameters
err = s.Fg_setParameterWithInt(fg, s.FG_WIDTH, width, camPort)
if (err < 0):
    print("Fg_setParameter(FG_WIDTH) failed: ",
          s.Fg_getLastErrorDescription(fg))
    s.Fg_FreeMemEx(fg, memHandle)
    s.Fg_FreeGrabber(fg)
    exit(err)

err = s.Fg_setParameterWithInt(fg, s.FG_HEIGHT, height, camPort)
if (err < 0):
    print("Fg_setParameter(FG_HEIGHT) failed: ",
          s.Fg_getLastErrorDescription(fg))
    s.Fg_FreeMemEx(fg, memHandle)
    s.Fg_FreeGrabber(fg)
    exit(err)