Ejemplo n.º 1
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
    print("No applet is found")
    exit(0)
else:
    print('Applet found:', applet)

# INIT FRAMEGRABBER

print('Initializing Board ..', end='')

if isSlave:
    fg = s.Fg_InitEx(applet, boardId, 1)
else:
    fg = s.Fg_InitEx(applet, boardId, 0)

# 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: ",