Exemplo n.º 1
0
    def __init__(self, device_loc, baud_rate=9600, testing=False):
        super(K30Sensor, self).__init__()
        self.logger = logging.getLogger("mycodo.inputs.k30")
        self._co2 = None

        self.k30_lock_file = None

        if not testing:
            import serial
            # Check if device is valid
            self.serial_device = is_device(device_loc)
            if self.serial_device:
                try:
                    self.ser = serial.Serial(self.serial_device,
                                             baudrate=baud_rate,
                                             timeout=1)
                    self.k30_lock_file = "/var/lock/sen-k30-{}".format(
                        device_loc.replace('/', ''))
                except serial.SerialException:
                    self.logger.exception('Opening serial')
            else:
                self.logger.error(
                    'Could not open "{dev}". '
                    'Check the device location is correct.'.format(
                        dev=device_loc))
Exemplo n.º 2
0
    def __init__(self,
                 interface,
                 device_loc=None,
                 baud_rate=None,
                 i2c_address=None,
                 i2c_bus=None,
                 testing=False):
        super(MHZ16Sensor, self).__init__()
        self.logger = logging.getLogger("mycodo.inputs.mh_z16")
        self._co2 = None
        self.mhz16_lock_file = None
        self.interface = interface

        if not testing:
            import serial
            import smbus
            if self.interface == 'UART':
                self.logger = logging.getLogger(
                    "mycodo.inputs.mh_z16.{dev}".format(
                        dev=device_loc.replace('/', '')))
                # Check if device is valid
                self.serial_device = is_device(device_loc)
                if self.serial_device:
                    try:
                        self.mhz16_lock_file = "/var/lock/sen-mhz16-{}".format(
                            device_loc.replace('/', ''))
                        self.ser = serial.Serial(self.serial_device,
                                                 baudrate=baud_rate,
                                                 timeout=1)
                    except serial.SerialException:
                        self.logger.exception('Opening serial')
                else:
                    self.logger.error(
                        'Could not open "{dev}". '
                        'Check the device location is correct.'.format(
                            dev=device_loc))

            elif self.interface == 'I2C':
                self.logger = logging.getLogger(
                    "mycodo.inputs.mh_z16.{dev}".format(dev=i2c_address))
                self.cmd_measure = [
                    0xFF, 0x01, 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63
                ]
                self.IOCONTROL = 0X0E << 3
                self.FCR = 0X02 << 3
                self.LCR = 0X03 << 3
                self.DLL = 0x00 << 3
                self.DLH = 0X01 << 3
                self.THR = 0X00 << 3
                self.RHR = 0x00 << 3
                self.TXLVL = 0X08 << 3
                self.RXLVL = 0X09 << 3
                self.i2c_address = i2c_address
                self.i2c = smbus.SMBus(i2c_bus)
                self.begin()
Exemplo n.º 3
0
    def __init__(self, device_loc, baud_rate=9600):
        super(MHZ19Sensor, self).__init__()
        self.logger = logging.getLogger("mycodo.sensors.mhz19.{dev}".format(
            dev=device_loc.replace('/', '')))
        self.k30_lock_file = None
        self._co2 = 0

        # Check if device is valid
        self.serial_device = is_device(device_loc)
        if self.serial_device:
            try:
                self.ser = serial.Serial(self.serial_device,
                                         baudrate=baud_rate,
                                         timeout=1)
                self.k30_lock_file = "/var/lock/sen-mhz19-{}".format(
                    device_loc.replace('/', ''))
            except serial.SerialException:
                self.logger.exception('Opening serial')
        else:
            self.logger.error(
                'Could not open "{dev}". '
                'Check the device location is correct.'.format(dev=device_loc))