示例#1
0
 def gain(self):
     """Set and get the camera gain of the active camera."""
     if self._activecam:
         return self._activecam.gain
     else:
         log.error('No camera selected.')
         return None
示例#2
0
 def exposurebounds(self):
     """Get the active camera exposure bounds in ms."""
     if self._activecam:
         return self._activecam.exposurebounds
     else:
         log.error('No camera selected.')
         return None
示例#3
0
 def pixelsize(self):
     """Return the pixelsize in micrometer of the camera. Non square pixels are not supported."""
     if self._activecam:
         return self._activecam.pixelsize
     else:
         log.error('No camera selected.')
         return None
示例#4
0
 def maxval(self):
     """Get the maximum counts per pixel allowed for the active camera."""
     if self._activecam:
         return self._activecam.maxval
     else:
         log.error('No camera selected.')
         return None
示例#5
0
 def exposure(self):
     """Set and get the active camera exposure in ms."""
     if self._activecam:
         return self._activecam.exposure
     else:
         log.error('No camera selected.')
         return None
示例#6
0
 def getimage(self):
     """Return the last image from the active camera."""
     if self._activecam:
         return self._activecam.getimage()
     else:
         log.error('No camera selected.')
         return None
示例#7
0
 def queuedimages(self):
     """Return the number of queued images."""
     if self._activecam:
         return self._activecam.queuedimages()
     else:
         log.error('No camera selected.')
         return None
示例#8
0
    def _initiatesensorlist(self):
        """Initiates a list of sensors with the specified parameters in sensorconfig.xml."""
        ret = []
        for par in self._paramlist:
            if par['type'] == 'camera':
                roipar = eval(par['roiparams'])
                ret.append(
                    Beam(self._connectedcamexp[(par['vendor'], par['camid'])],
                         par['beam'], roipar, 'national'))
            if par['type'] == 'temperature':
                channellist = []
                for i in range(0, 9):
                    keystr = 'channel' + str(i + 1)
                    channellist.append(par[keystr])
                ret.append(
                    Temperature(ctypes.windll.LoadLibrary(DLLPATH),
                                par['handle'], par['tempid'],
                                self._connectedtemp, 'periodic', channellist))

            if par['type'] == 'nianalog':
                if par["devstr"] in self._connectedni:
                    ret.append(
                        NIAnalog(par["devstr"], par["trigger"],
                                 par["channeldict"], float(par["eich"])))
                else:
                    log.error(
                        "The NI device with the devkey %s does not seem to be connected."
                        % par["devstr"])

        return ret
示例#9
0
 def hasimages(self):
     """True if activecam has new images available"""
     if self._activecam:
         return self._activecam.hasimages()
     else:
         log.error('No camera selected.')
         return None
示例#10
0
    def findallcams(self):
        """Find all cameras of this vendor

        Returns
        -------
        cams : dictionary
            Dictionary of all connected cameras where the key is the unique id
            that can be used to obtain a camera handle. The value is a
            description of the camera presented to the user.

        """
        res = {}
        cams = [xiapi.Camera(0)]
        ndev = cams[0].get_number_devices()
        log.info('Found %i ximea cameras' % ndev)
        if ndev == 0:
            log.error('No cameras found')
        for ii in range(ndev - 1):
            cams.append(xiapi.Camera(ii + 1))
        for ii in range(ndev):
            serial = cams[ii].get_device_info_string("device_sn").decode(
                "utf8")
            res[serial] = {
                "serial":
                serial,
                "type":
                cams[ii].get_device_info_string("device_type").decode("utf8"),
                "name":
                cams[ii].get_device_info_string("device_name").decode("utf8"),
            }
        return res
示例#11
0
 def gainvals(self):
     """Get the possible camera gain values of the active camera."""
     if self._activecam:
         return self._activecam.gainvals
     else:
         log.error('No camera selected.')
         return None
示例#12
0
 def caminfo(self):
     """Get information on the active camera."""
     if self._activecam:
         return (self._activecam.VENDOR, self._activecam.camid)
     else:
         log.error('No camera selected.')
         return None
示例#13
0
 def start(self):
     """Start the active camera in continous acqisition mode."""
     if self._activecam:
         self._activecam.startcontacq()
         self.isaquiring = True
     else:
         self.isaquiring = False
         log.error('No camera selected.')
         return None
示例#14
0
 def close(self):
     """Close the active camera."""
     if self._activecam:
         #log.debug('Closing cam')
         self._activecam.close()
         self._activecam = None
     else:
         log.error('No camera selected.')
         return None
示例#15
0
 def gain(self, val):
     if self._activecam:
         if self.isaquiring:
             self._activecam.stopcontacq()
             self._activecam.gain = val
             self._activecam.startcontacq()
         else:
             self._activecam.gain = val
     else:
         log.error('No camera selected.')
示例#16
0
 def pixelsize(self):
     """Return the pixelsize in micrometer of the camera. Non square pixels are not supported."""
     if self._devinfo['name'] == 'MD028MU-SY':
         res = 4.54
     else:
         log.error('Unknown pixel size for {}. Using 5mum.'.format(
             self._devinfo['name']))
         res = 5.0
     #log.info('Using pixel size %f.' % res)
     return res
示例#17
0
 def stop(self):
     """Stop the active camera."""
     if self._activecam:
         #log.debug('Stopping camera')
         self._activecam.stopcontacq()
         self.isaquiring = False
         #log.debug('Camera stopped')
     else:
         self.isaquiring = False
         log.error('No camera selected.')
         return None
示例#18
0
 def __init__(self, dll, handle, tempid, tempsensors, trigger, channellist):
     if handle in tempsensors:
         super(Temperature, self).__init__("temperature", str(tempid),
                                           trigger)
         self._dll = dll
         self._handle = handle
         self._channellist = channellist
     else:
         log.error(
             'No temperature sensor with the handle %s is connected.' %
             (handle))
示例#19
0
 def open(self, camid):
     """Open the camera and obtain a camera handle"""
     #log.debug('Try opening cam with camid: %s' % camid)
     try:
         self._cam.open_device_by_SN(camid)
         self._camid = camid
         self._devinfo = self._getdevinfo()
         #log.debug('Success in opening cam with camid: %s' % camid)
         self._setupcam()
     except xiapi.Xi_error as e:
         self._camid = None
         log.error("XIMEA ERROR in open_device: {}".format(e))
示例#20
0
 def open(self, camid):
     """Open the camera and obtain a camera handle"""
     self._camid = camid
     #log.debug('Try opening cam with camid: %s' % camid)
     # get the devkey
     self._devkey = self._getdevkey(camid)
     if not self._devkey.contents.m_busy == 1:
         self._handle = vrm.VRmUsbCamDevice()
         self._ce(vrm.VRmUsbCamOpenDevice(self._devkey,
                                          byref(self._handle)))
         #log.debug('Success in opening cam with camid: %s' % camid)
     else:
         log.error('Could not open camera with camid: %s: BUSY' % camid)
示例#21
0
    def open(self, camserial):
        """Open the camera and obtain a camera handle"""
        self._camserial = camserial
        #log.debug('Try opening cam with serial: %s' % camserial)
        # get the devkey
        self._devid, available = self._getdevid(camserial)
        if not int(available) == 1:
            err0, self._handle = self.ueyeapi.is_CreateHandle(self._devid)
            self._ce(err0)
            #log.debug('Success in opening cam with camid: %s' % camserial)

        else:
            log.error('Could not open camera with camid: %s: BUSY' % camserial)
示例#22
0
 def pixelsize(self):
     """Return the pixelsize in micrometer of the camera. Non square pixels are not supported."""
     if self._devkey.contents.mp_product_str.data.decode(
             'utf-8') == 'VRmC-12/BW':
         res = 6.0
     elif self._devkey.contents.mp_product_str.data.decode(
             'utf-8') == 'VRmmC-12/BW':
         res = 6.0
     elif self._devkey.contents.mp_product_str.data.decode(
             'utf-8') == 'VRmC-9+/BW':
         res = 5.2
     else:
         log.error(
             'Unknown pixel size for %s. Using 1mum.' %
             self._devkey.contents.mp_product_str.data.decode('utf-8'))
         res = 1.0
     #log.info('Using pixel size %f.' % res)
     return res
示例#23
0
    def startcontacq(self):
        """Start continuous picture acquisition.

        Put acquired images on in the image queue.

        """
        #log.debug('Trying to start camera %s' % self._camid)
        self._cam.start_acquisition()
        if self._imagecapturethread is not None:
            log.error("XIMEA ERROR in start_capture: Capture running")
        else:
            log.info("XIMEA: Start capture.")
            self._imagecapturethread = XiapiDataWatcher(
                "Xiapi_watcher_{}".format(self._camid),
                self,
                self.get_image,
                self._imagequeue,
                daemon=True,
                stop_event_interval=0.05,
            )
            self._imagecapturethread.start()
示例#24
0
 def getdata(self):
     """Exports data field in dictionary format"""
     try:
         self.IA.image = self._cam.getanimage()
         try:
             self.IA.setroi()
         except:
             log.error('Could not set ROI of sensor %s, %s.' %
                       (self.type, self.sensor))
         try:
             fitdata = self.IA.getfitdata()
             if not None in fitdata:
                 #first safes the latest image for fit data to be in sync with live cam view
                 self.latestimage = self.IA.image
                 self.latestroi = self.IA.roiimage
                 self.latestroiparams = (self.IA.roiposx, self.IA.roiposy,
                                         self.IA.roiimgwidth,
                                         self.IA.roiimgheight)
                 #then proceeds to return field values such as fit data and roi params in directionary format
                 lib = {}
                 lib["hcenter"] = fitdata[0]
                 lib["vcenter"] = fitdata[1]
                 lib["largewaist"] = fitdata[2]
                 lib["smallwaist"] = fitdata[3]
                 lib["angle"] = fitdata[4]
                 return lib
             else:
                 if fitdata[0] == None:
                     log.error(
                         'Error while fitting horizontal position of sensor %s, %s.'
                         % (self.type, self.sensor))
                 if fitdata[1] == None:
                     log.error(
                         'Error while fitting vertical position of sensor %s, %s.'
                         % (self.type, self.sensor))
                 if fitdata[2] == None:
                     log.error(
                         'Error while fitting large waist of sensor %s, %s.'
                         % (self.type, self.sensor))
                 if fitdata[3] == None:
                     log.error(
                         'Error while fitting small waist of sensor %s, %s.'
                         % (self.type, self.sensor))
                 if fitdata[4] == None:
                     log.error(
                         'Error while fitting angle of sensor %s, %s.' %
                         (self.type, self.sensor))
                 return None
         except:
             log.error('Could not aquire fit data of sensor %s, %s.' %
                       (self.type, self.sensor))
             return None
     except:
         log.error('Sensor %s, %s could not get image.' %
                   (self.type, self.sensor))
         return None
示例#25
0
 def _ce(self, val):
     """Check for errors"""
     if val != 0:
         err = ueye.EC[val]
         log.error('UEYE ERROR: %s' % err)
示例#26
0
    def __init__(self):

        self._cameramanager = self._initiatecamman()

        self._connectedcams = self._connectedcams()

        self._connectedtemp = self._initiatetemplist()

        self._connectedni = self._initiateni()

        self._paramlist = self._paramfromfile()

        self._triggerconf = self._triggerfromfile()

        self._tobeconfigured = self._getmissingsensors()

        self._overlyconfigured = self._getnonconnectedsensors()

        #Rewrite sensorxml file

        for ov in self._overlyconfigured.keys():
            if ov == "camera":
                for cam in self._overlyconfigured[ov]:
                    log.info(
                        "The connected camera %s %s is mentioned in sensorconfig.xml and yet does not seem to be connected."
                        % cam)
                    delnow = input(
                        "Delete camera %s %s from sensorconfig.xml? (y/n)" %
                        cam)
                    if delnow == "y":
                        self._delcamerasensorfromxml(cam[0], cam[1])
                        log.info(
                            "Camera %s %s was deleted from sensorconfig.xml." %
                            cam)
            if ov == "temperature":
                for temp in self._overlyconfigured[ov]:
                    log.info(
                        "The connected temperature sensor %s is mentioned in sensorconfig.xml and yet does not seem to be connected."
                        % temp)
                    delnow = input(
                        "Delete temperature sensor with the handle %s from sensorconfig.xml? (y/n)"
                        % temp)
                    if delnow == "y":
                        self._deltempsensorfromxml(temp)
                        log.info(
                            "Temperature sensor with the handle %s was deleted from sensorconfig.xml."
                            % temp)
            if ov == "nianalog":
                for ni in self._overlyconfigured[ov]:
                    log.info(
                        "The connected national instruments sensor %s is mentioned in sensorconfig.xml and yet does not seem to be connected."
                        % ni)
                    delnow = input(
                        "Delete national instruments sensor with the devstring %s from sensorconfig.xml? (y/n)"
                        % ni)
                    if delnow == "y":
                        self._delnisensorfromxml(ni)
                        log.info(
                            "National instruments sensor with the handle %s was deleted from sensorconfig.xml."
                            % ni)

        for miss in self._tobeconfigured.keys():
            if miss == "camera":
                for cam in self._tobeconfigured[miss]:
                    log.info(
                        "The connected camera %s %s is not yet configured in sensorconfig.xml."
                        % cam)
                    configurenow = input("Configure %s %s now? (y/n) " % cam)
                    if configurenow == "y":
                        nobeams = input(
                            "How many beams are tracked with this camera? ")
                        try:
                            beamlist = range(int(nobeams))
                        except:
                            log.error("Bad input. Config process stopped.")
                            break

                        for beam in beamlist:
                            beamname = input(
                                "What name should beam number %i be logged as? "
                                % (beam + 1))
                            self._addcamerasensortoxml(cam[0], cam[1],
                                                       beamname,
                                                       "(0,0,100,100)")
            if miss == "temperature":
                for temp in self._tobeconfigured[miss]:
                    log.info(
                        "The connected temperature sensor with the handle %s is not yet configured in sensorconfig.xml."
                        % temp)
                    configurenow = input("Configure %s now? (y/n) " % temp)
                    if configurenow == "y":
                        tempid = input(
                            "What name should this sensor be logged as? ")
                        defaultlist = []
                        for i in range(0, 9):
                            st = 'Channel ' + str(i + 1)
                            defaultlist.append(st)
                        self._addtempsensortoxml(tempid, miss, defaultlist)
            if miss == "nianalog":
                for ni in self._tobeconfigured[miss]:
                    log.info(
                        "The connected national instruments sensor with the devstring %s is not yet mentioned in sensorconfig.xml."
                        % ni)
                    configurenow = input("Configure %s now? (y/n) " % ni)
                    if configurenow == "y":
                        eich = input("What eich factor should be used? ")
                        self._addnisensortoxml(ni, eich, "national")

        #Reread edited xml file
        self._paramlist = self._paramfromfile()

        self._tobeconfigured = []

        self._overlyconfigured = []

        self._connectedcamexp = self._initiatecamexpdict()

        self._sensorlist = self._initiatesensorlist()

        self._sensordict = self._initiatesensordict()
示例#27
0
 def _ce(self, val):
     """Check for errors"""
     if val == 0:
         err = vrm.VRmUsbCamGetLastError()
         log.error('VRM ERROR: %s' % err.data.decode('utf-8'))
     return val
示例#28
0
 def emptyqueue(self):
     """Empty the _imagequeue."""
     if self._activecam:
         self._activecam.emptyqueue()
     else:
         log.error('No camera selected.')
示例#29
0
    def _initiatetemplist(self):
        """Uses DLL in order to find an connect to all temperature handles. Returns list for said handles."""
        try:
            mydll = ctypes.windll.LoadLibrary(DLLPATH)
        except:
            log.error('Failed to load DLL file usbtc08.dll')
            return None
        id = 1
        templist = []
        devlist = []
        while id != 0:
            id = mydll.usb_tc08_open_unit(
            )  #Returns device handle, or 0 if no device was found, or -1 if an error occured
            if id != -1:
                if id != 0:
                    log.info("Temperature sensor of handle %i encountered." %
                             id)
                    templist.append(str(id))
                    devlist.append(id)
            else:
                err = mydll.usb_tc08_get_last_error(0)
                if err == 1:
                    log.error(
                        'Failed to connect to temperature sensor: USBTC08_ERROR_OS_NOT_SUPPORTED'
                    )
                if err == 2:
                    log.error(
                        'Failed to connect to temperature sensor: USBTC08_ERROR_NO_CHANNELS_SET'
                    )
                if err == 3:
                    log.error(
                        'Failed to connect to temperature sensor: USBTC08_ERROR_INVALID_PARAMETER'
                    )
                if err == 4:
                    log.error(
                        'Failed to connect to temperature sensor: USBTC08_ERROR_VARIANT_NOT_SUPPORTED'
                    )
                if err == 5:
                    log.error(
                        'Failed to connect to temperature sensor: USBTC08_ERROR_INCORRECT_MODE'
                    )
                if err == 6:
                    log.error(
                        'Failed to connect to temperature sensor: USBTC08_ERROR_ENUMERATION_INCOMPLETE'
                    )
                break

        return templist