Exemple #1
0
    def start(self):
        """ """
        if self.bus is None:
            raise KeyError("Bus missing for DS18X20Sensor")

        # Initialize the DS18x20 hardware driver.
        onewire_bus = self.bus.adapter
        try:

            use_native_driver = self.bus.settings.get('driver') == 'native'

            # Vanilla MicroPython 1.11
            if platform_info.vendor == platform_info.MICROPYTHON.Vanilla or use_native_driver:
                import ds18x20_native
                self.driver = ds18x20_native.DS18X20(onewire_bus)

            # Pycom MicroPython 1.9.4
            elif platform_info.vendor == platform_info.MICROPYTHON.Pycom:
                import ds18x20_python
                self.driver = ds18x20_python.DS18X20(onewire_bus)

            else:
                raise NotImplementedError(
                    'DS18X20 driver not implemented on this platform')

        except Exception as ex:
            log.exc(ex, 'DS18X20 hardware driver failed')
            return False

        return True
    def start(self):
        """
        Setup the DS18x20 sensor driver.
        :return:
        """

        # Ensure a bus object exists and is ready.
        self.ensure_bus()

        # Initialize the DS18x20 hardware driver.
        onewire_bus = self.bus.adapter
        try:

            use_native_driver = self.bus.settings.get('driver') == 'native'

            platform_info = get_platform_info()

            # Vanilla MicroPython >=1.11
            if platform_info.vendor == platform_info.MICROPYTHON.Vanilla or use_native_driver:
                import ds18x20_native
                self.driver = ds18x20_native.DS18X20(onewire_bus)

            # Pycom MicroPython 1.9.4
            elif platform_info.vendor == platform_info.MICROPYTHON.Pycom:
                import ds18x20_python
                self.driver = ds18x20_python.DS18X20(onewire_bus)

            # RaspberryPi
            elif platform_info.vendor == platform_info.MICROPYTHON.RaspberryPi:
                from terkin.sensor.linux import LinuxSysfsDS18B20
                self.driver = LinuxSysfsDS18B20(onewire_bus)

            else:
                raise NotImplementedError(
                    'DS18x20 driver not implemented on this platform')

            return True

        except Exception as ex:
            log.exc(ex, 'DS18x20 hardware driver failed')
            return False