Exemplo n.º 1
0
    def test_linux_version(self):

        if os.sys.platform.startswith('linux'):
            v = get_linux_version()
            self.assertGreaterEqual(v[0], 2)
            self.assertEqual(len(v), 3)
        else:
            with self.assertRaises(LookupError):
                v = get_linux_version()
Exemplo n.º 2
0
    def test_linux_version(self):

        if sys.platform.startswith('linux'):
            v = get_linux_version()
            self.assertGreaterEqual(v[0], 2)
            self.assertEqual(len(v), 3)
        else:
            with self.assertRaises(LookupError):
                v = get_linux_version()
Exemplo n.º 3
0
    def __init__(self, name, role, device, channels, spectra, pwr_curve,
                 **kwargs):
        """
        device (string): name of the /dev comedi  device (ex: "/dev/comedi0")
        channels (list of (0<=int)): The output channel for each source, as
          numbered in the comedi subdevice.
        spectra (list of 5-tuple of float): the spectra for each output channel used.
         Each tuple represents the wavelength in m for the 99% low, 25% low,
         centre/max, 25% high, 99% high. They do no have to be extremely precise.
         The most important is the centre, and that they are all increasing values.
        pwr_curve (list of dict (float -> 0<float)): Power curve segment map for
           each source. A segment map is a  series of voltage output on the
           analog output -> emission power of the light (W).
           It represents a series of linear segments to map the voltage output
           to the light emission. At least one pair should be provided.
           If no voltage is linked to 0W, then a 0V -> 0W mapping is used.
           The total curve should be monotonic.
        """
        # TODO: allow to give the unit of the power/pwr_curve ?

        model.Emitter.__init__(self, name, role, **kwargs)
        self._shape = ()

        try:
            self._device = comedi.open(device)
        #             self._fileno = comedi.fileno(self._device)
        except comedi.ComediError:
            raise ValueError("Failed to open DAQ device '%s'" % device)

        # Look for the analog output subdevice
        try:
            self._ao_subd = comedi.find_subdevice_by_type(
                self._device, comedi.SUBD_AO, 0)
            nchan = comedi.get_n_channels(self._device, self._ao_subd)
            if nchan < max(channels):
                raise ValueError(
                    "Device only has %d channels, while needed %d" %
                    (nchan, max(channels)))
        except comedi.ComediError:
            raise ValueError(
                "Failed to find an analogue output on DAQ device '%s'" %
                device)

        if len(channels) != len(spectra):
            raise ValueError(
                "spectra argument should have the same length as channels (%d)"
                % len(channels))
        if len(channels) != len(pwr_curve):
            raise ValueError(
                "pwr_curve argument should have the same length as channels (%d)"
                % len(channels))

        self._channels = channels

        # Check and store the power curves
        self._ranges = []
        self._pwr_curve = []
        for c, crv in zip(channels, pwr_curve):
            crv = [v for v in crv.items()]
            # Add 0W = 0V if nothing = 0W
            if 0 not in [w for v, w in crv]:
                crv.append((0, 0))
                logging.info(
                    "Adding 0V -> 0W mapping to pwr_curve for channel %d", c)
            # At least beginning and end values
            if len(crv) < 2:
                raise ValueError(
                    "pwr_curve for channel %d has less than 2 values: %s" %
                    (c, crv))
            # Check it's monotonic
            crv = sorted(crv, key=lambda v: v[0])
            if crv[0][1] < 0:
                raise ValueError(
                    "pwr_curve for channel %d has negative power: %g W" %
                    (c, crv[0][1]))
            if len(crv) != len(set(v for v, w in crv)):
                raise ValueError(
                    "pwr_curve for channel %d has identical voltages: %s" %
                    (c, crv))
            if not all(
                (crv[i][1] < crv[i + 1][1]) for i in range(len(crv) - 1)):
                raise ValueError(
                    "pwr_curve for channel %d is not monotonic: %s" % (c, crv))

            self._pwr_curve.append(crv)

            # Find the best range to use
            try:
                ri = comedi.find_range(self._device, self._ao_subd, c,
                                       comedi.UNIT_volt, crv[0][0], crv[-1][0])
            except comedi.ComediError:
                raise ValueError(
                    "Data range between %g and %g V is too high for hardware."
                    % (crv[0][0], crv[-1][0]))
            self._ranges.append(ri)

        # Check the spectra
        spect = []  # list of the 5 wavelength points
        for c, wls in zip(channels, spectra):
            if len(wls) != 5:
                raise ValueError(
                    "Spectra for channel %d doesn't have exactly 5 wavelength points: %s"
                    % (c, wls))
            if list(wls) != sorted(wls):
                raise ValueError(
                    "Spectra for channel %d has unsorted wavelengths: %s" %
                    (c, wls))
            for wl in wls:
                if not 0 < wl < 100e-6:
                    raise ValueError(
                        "Spectra for channel %d has unexpected wavelength = %f nm"
                        % (c, wl * 1e9))
            spect.append(tuple(wls))

        # Maximum power for channel to be used as a range for power
        max_power = tuple([crv[-1][1] for crv in self._pwr_curve])
        # Power value for each channel of the device
        self.power = model.ListContinuous(
            value=[0.] * len(self._channels),
            range=(
                tuple([0.] * len(self._channels)),
                max_power,
            ),
            unit="W",
            cls=(int, long, float),
        )
        self.power.subscribe(self._updatePower)

        # info on which channel is which wavelength
        self.spectra = model.ListVA(spect, unit="m", readonly=True)

        # make sure everything is off (turning on the HUB will turn on the lights)
        self.power.value = self.power.range[0]

        self._metadata = {model.MD_HW_NAME: self.getHwName()}
        lnx_ver = driver.get_linux_version()
        self._swVersion = "%s (driver %s, linux %s)" % (
            odemis.__version__, self.getSwVersion(), ".".join(
                "%s" % v for v in lnx_ver))
        self._metadata[model.MD_SW_VERSION] = self._swVersion
        self._metadata[model.MD_HW_VERSION] = self._hwVersion  # unknown
Exemplo n.º 4
0
    def __init__(self, name, role, device, channels, spectra, pwr_curve, **kwargs):
        """
        device (string): name of the /dev comedi  device (ex: "/dev/comedi0")
        channels (list of (0<=int)): The output channel for each source, as
          numbered in the comedi subdevice.
        spectra (list of 5-tuple of float): the spectra for each output channel used.
         Each tuple represents the wavelength in m for the 99% low, 25% low,
         centre/max, 25% high, 99% high. They do no have to be extremely precise.
         The most important is the centre, and that they are all increasing values.
        pwr_curve (list of dict (float -> 0<float)): Power curve segment map for
           each source. A segment map is a  series of voltage output on the
           analog output -> emission power of the light (W).
           It represents a series of linear segments to map the voltage output
           to the light emission. At least one pair should be provided.
           If no voltage is linked to 0W, then a 0V -> 0W mapping is used.
           The total curve should be monotonic.
        """
        # TODO: allow to give the unit of the power/pwr_curve ?

        model.Emitter.__init__(self, name, role, **kwargs)
        self._shape = ()

        try:
            self._device = comedi.open(device)
#             self._fileno = comedi.fileno(self._device)
        except comedi.ComediError:
            raise ValueError("Failed to open DAQ device '%s'" % device)

        # Look for the analog output subdevice
        try:
            self._ao_subd = comedi.find_subdevice_by_type(self._device, comedi.SUBD_AO, 0)
            nchan = comedi.get_n_channels(self._device, self._ao_subd)
            if nchan < max(channels):
                raise ValueError("Device only has %d channels, while needed %d" % (nchan, max(channels)))
        except comedi.ComediError:
            raise ValueError("Failed to find an analogue output on DAQ device '%s'" % device)

        if len(channels) != len(spectra):
            raise ValueError("spectra argument should have the same length as channels (%d)" % len(channels))
        if len(channels) != len(pwr_curve):
            raise ValueError("pwr_curve argument should have the same length as channels (%d)" % len(channels))

        self._channels = channels

        # Check and store the power curves
        self._ranges = []
        self._pwr_curve = []
        for c, crv in zip(channels, pwr_curve):
            crv = [v for v in crv.items()]
            # Add 0W = 0V if nothing = 0W
            if 0 not in [w for v, w in crv]:
                crv.append((0, 0))
                logging.info("Adding 0V -> 0W mapping to pwr_curve for channel %d", c)
            # At least beginning and end values
            if len(crv) < 2:
                raise ValueError("pwr_curve for channel %d has less than 2 values: %s" % (c, crv))
            # Check it's monotonic
            crv = sorted(crv, key=lambda v: v[0])
            if crv[0][1] < 0:
                raise ValueError("pwr_curve for channel %d has negative power: %g W" % (c, crv[0][1]))
            if len(crv) != len(set(v for v, w in crv)):
                raise ValueError("pwr_curve for channel %d has identical voltages: %s" % (c, crv))
            if not all((crv[i][1] < crv[i + 1][1]) for i in range(len(crv) - 1)):
                raise ValueError("pwr_curve for channel %d is not monotonic: %s" % (c, crv))

            self._pwr_curve.append(crv)

            # Find the best range to use
            try:
                ri = comedi.find_range(self._device, self._ao_subd,
                                      c, comedi.UNIT_volt, crv[0][0], crv[-1][0])
            except comedi.ComediError:
                raise ValueError("Data range between %g and %g V is too high for hardware." %
                                 (crv[0][0], crv[-1][0]))
            self._ranges.append(ri)

        # Check the spectra
        spect = []  # list of the 5 wavelength points
        for c, wls in zip(channels, spectra):
            if len(wls) != 5:
                raise ValueError("Spectra for channel %d doesn't have exactly 5 wavelength points: %s" % (c, wls))
            if list(wls) != sorted(wls):
                raise ValueError("Spectra for channel %d has unsorted wavelengths: %s" % (c, wls))
            for wl in wls:
                if not 0 < wl < 100e-6:
                    raise ValueError("Spectra for channel %d has unexpected wavelength = %f nm"
                                     % (c, wl * 1e9))
            spect.append(tuple(wls))

        max_power = max(crv[-1][1] for crv in self._pwr_curve)
        # power of the whole device (=> max power of the device with max power)
        self.power = model.FloatContinuous(0., (0., max_power), unit="W")
        self.power.subscribe(self._updatePower)

        # ratio of power per channel
        # => if some channel don't support max power, clamped before 1
        self.emissions = model.ListVA([0.] * len(self._channels), unit="",
                                      setter=self._setEmissions)
        # info on which channel is which wavelength
        self.spectra = model.ListVA(spect, unit="m", readonly=True)

        # make sure everything is off (turning on the HUB will turn on the lights)
        self._updateIntensities(self.power.value, self.emissions.value)

        self._metadata = {model.MD_HW_NAME: self.getHwName()}
        lnx_ver = driver.get_linux_version()
        self._swVersion = "%s (driver %s, linux %s)" % (odemis.__version__,
                                    self.getSwVersion(),
                                    ".".join("%s" % v for v in lnx_ver))
        self._metadata[model.MD_SW_VERSION] = self._swVersion
        self._metadata[model.MD_HW_VERSION] = self._hwVersion # unknown