Esempio n. 1
0
    def sample(self):
        r = self.__read(self.__CMD_READ_MEASURED_VALUES, 0, 60)

        # density...
        pm1 = Decode.float(r[0:4], '>')
        pm2p5 = Decode.float(r[4:8], '>')
        pm4 = Decode.float(r[8:12], '>')
        pm10 = Decode.float(r[12:16], '>')

        # count...
        pm0p5_count = Decode.float(r[16:20], '>')
        pm1_count = Decode.float(r[20:24], '>')
        pm2p5_count = Decode.float(r[24:28], '>')
        pm4_count = Decode.float(r[28:32], '>')
        pm10_count = Decode.float(r[32:36], '>')

        # typical size...
        tps = Decode.float(r[36:40], '>')

        # time...
        rec = LocalizedDatetime.now()

        # report...
        counts = SPSDatumCounts(pm0p5_count, pm1_count, pm2p5_count, pm4_count,
                                pm10_count)

        return SPSDatum(self.SOURCE, rec, pm1, pm2p5, pm4, pm10, counts, tps)
Esempio n. 2
0
    def sample(self):
        try:
            self.obtain_lock()
            self._spi.open()

            # command...
            self.__cmd(self.__CMD_READ_HISTOGRAM)
            chars = self.__read_bytes(62)

            # time...
            rec = LocalizedDatetime.now()

            # bins...
            bins = [Decode.unsigned_int(chars[i:i + 2], '<') for i in range(0, 32, 2)]

            # bin MToFs...
            bin_1_mtof = chars[32]
            bin_3_mtof = chars[33]
            bin_5_mtof = chars[34]
            bin_7_mtof = chars[35]

            # period...
            period = Decode.float(chars[44:48], '<')

            # checksum...
            required = Decode.unsigned_int(chars[48:50], '<')
            actual = sum(bins) % 65536

            if required != actual:
                raise ValueError("bad checksum: required: 0x%04x actual: 0x%04x" % (required, actual))

            # PMx...
            try:
                pm1 = Decode.float(chars[50:54], '<')
            except TypeError:
                pm1 = None

            try:
                pm2p5 = Decode.float(chars[54:58], '<')
            except TypeError:
                pm2p5 = None

            try:
                pm10 = Decode.float(chars[58:62], '<')
            except TypeError:
                pm10 = None

            return OPCDatum(self.SOURCE, rec, pm1, pm2p5, pm10, period, bins,
                            bin_1_mtof, bin_3_mtof, bin_5_mtof, bin_7_mtof)

        finally:
            self._spi.close()
            self.release_lock()
    def sample(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRx1Cmd.find('sg')
            response = self._transact(cmd)

            cnc = Decode.float(response[0:4], '<')
            cnc_igl = Decode.float(response[4:8], '<')
            temp = Decode.float(response[8:12], '<')

            return NDIRDatum(temp, cnc, cnc_igl)

        finally:
            self.release_lock()
    def measure_voltage(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRx1Cmd.find('mv')
            response = self._transact(cmd)

            pile_ref_voltage = Decode.float(response[0:4], '<')
            pile_act_voltage = Decode.float(response[4:8], '<')
            thermistor_voltage = Decode.float(response[8:12], '<')

            return pile_ref_voltage, pile_act_voltage, thermistor_voltage

        finally:
            self.release_lock()
    def status(self):
        try:
            self.obtain_lock()

            # restart status...
            cmd = SPINDIRx1Cmd.find('ws')
            response = self._transact(cmd)
            watchdog_reset = bool(response)

            # input voltage...
            cmd = SPINDIRx1Cmd.find('iv')
            response = self._transact(cmd)
            pwr_in = Decode.float(response, '<')

            # uptime...
            cmd = SPINDIRx1Cmd.find('up')
            response = self._transact(cmd)
            seconds = Decode.unsigned_long(response, '<')

            status = NDIRStatus(watchdog_reset, pwr_in, NDIRUptime(seconds))

            return status

        finally:
            self.release_lock()
Esempio n. 6
0
    def get_sample_voltage(self):
        try:
            self.obtain_lock()

            # report...
            cmd = SPINDIRt1f1Cmd.find('sv')
            response = self._transact(cmd)

            pile_ref_amplitude = Decode.float(response[0:4], '<')
            pile_act_amplitude = Decode.float(response[4:8], '<')
            thermistor_average = Decode.float(response[8:12], '<')

            return pile_ref_amplitude, pile_act_amplitude, thermistor_average

        finally:
            self.release_lock()
    def _calib_r_float(self, block, index):
        cmd = SPINDIRx1Cmd.find('cr')
        cmd.return_count = 4

        response = self._transact(cmd, (block, index))
        value = Decode.float(response, '<')

        return value
Esempio n. 8
0
    def __read_float(self):
        read_bytes = []

        for _ in range(4):
            time.sleep(OPCN2.__TRANSFER_DELAY)
            read_bytes.extend(self.__spi.read_bytes(1))

        return Decode.float(read_bytes)
    def input_voltage(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRx1Cmd.find('iv')
            response = self._transact(cmd)
            v_in_voltage = Decode.float(response, '<')

            return v_in_voltage

        finally:
            self.release_lock()
Esempio n. 10
0
    def pressure(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRx1Cmd.find('sp')
            response = self._transact(cmd)

            p_a = Decode.float(response[0:4], '<')

            return round(p_a, 1)

        finally:
            self.release_lock()
Esempio n. 11
0
    def sample(self):
        try:
            self.obtain_lock()
            self._spi.open()

            # command...
            self.__cmd(self.__CMD_READ_HISTOGRAM)
            chars = self.__read_bytes(86)

            # checksum...
            required = Decode.unsigned_int(chars[84:86], '<')
            actual = ModbusCRC.compute(chars[:84])

            if required != actual:
                raise ValueError(
                    "bad checksum: required: 0x%04x actual: 0x%04x" %
                    (required, actual))

            # time...
            rec = LocalizedDatetime.now()

            # bins...
            bins = [
                Decode.unsigned_int(chars[i:i + 2], '<')
                for i in range(0, 48, 2)
            ]

            # bin MToFs...
            bin_1_mtof = chars[48]
            bin_3_mtof = chars[49]
            bin_5_mtof = chars[50]
            bin_7_mtof = chars[51]

            # period...
            raw_period = Decode.unsigned_int(chars[52:54], '<')
            period = round(float(raw_period) / 100.0, 3)

            # temperature & humidity
            raw_temp = Decode.unsigned_int(chars[56:58], '<')
            raw_humid = Decode.unsigned_int(chars[58:60], '<')

            sht = SHTDatum(SHT31.humid(raw_humid), SHT31.temp(raw_temp))

            # PMx...
            try:
                pm1 = Decode.float(chars[60:64], '<')
            except TypeError:
                pm1 = None

            try:
                pm2p5 = Decode.float(chars[64:68], '<')
            except TypeError:
                pm2p5 = None

            try:
                pm10 = Decode.float(chars[68:72], '<')
            except TypeError:
                pm10 = None

            return OPCDatum(self.SOURCE, rec, pm1, pm2p5, pm10, period, bins,
                            bin_1_mtof, bin_3_mtof, bin_5_mtof, bin_7_mtof,
                            sht)

        finally:
            self._spi.close()
            self.release_lock()