예제 #1
0
    def status(self):
        try:
            self.obtain_lock()

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

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

            # uptime...
            cmd = SPINDIRt1f1Cmd.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()
예제 #2
0
    def reset(self):
        try:
            self.obtain_lock()

            # force reset...
            cmd = SPINDIRt1f1Cmd.find('wr')
            self._transact(cmd)

            time.sleep(cmd.execution_time)

            # clear status...
            cmd = SPINDIRt1f1Cmd.find('wc')
            self._transact(cmd)

        finally:
            self.release_lock()
예제 #3
0
    def _calib_w_float(self, block, index, value):
        cmd = SPINDIRt1f1Cmd.find('cw')

        value_bytes = Encode.float(value, '<')
        self._transact(cmd, (block, index), value_bytes)

        time.sleep(cmd.execution_time)
예제 #4
0
    def _calib_r_float(self, block, index):
        cmd = SPINDIRt1f1Cmd.find('cr')
        cmd.return_count = 4

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

        return value
예제 #5
0
    def record_raw(self, deferral, interval, count):
        try:
            self.obtain_lock()

            # start recording...
            deferral_bytes = Encode.unsigned_int(deferral, '<')
            interval_bytes = Encode.unsigned_int(interval, '<')
            count_bytes = Encode.unsigned_int(count, '<')

            param_bytes = []
            param_bytes.extend(deferral_bytes)
            param_bytes.extend(interval_bytes)
            param_bytes.extend(count_bytes)

            cmd = SPINDIRt1f1Cmd.find('rs')
            self._transact(cmd, param_bytes)

            # wait...
            lamp_period = self._calib_r_unsigned_int(
                0, NDIRCalib.INDEX_LAMP_PERIOD)

            execution_time = (lamp_period + deferral +
                              (interval * count)) / 1000

            time.sleep(execution_time)

            # playback...
            cmd = SPINDIRt1f1Cmd.find('rp')
            cmd.return_count = count * 10

            response = self._transact(cmd)

            values = []

            for i in range(0, cmd.return_count, 10):
                timestamp = Decode.unsigned_int(response[i:i + 2], '<')
                pile_ref = Decode.long(response[i + 2:i + 6], '<')
                pile_act = Decode.long(response[i + 6:i + 10], '<')

                values.append((timestamp, pile_ref, pile_act))

            return values

        finally:
            self.release_lock()
예제 #6
0
    def watchdog_clear(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('wc')
            self._transact(cmd)

        finally:
            self.release_lock()
예제 #7
0
    def sample(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('sp')
            self._transact(cmd)

        finally:
            self.release_lock()
예제 #8
0
    def measure_calibrate(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('mc')
            self._transact(cmd)

            time.sleep(cmd.execution_time)

        finally:
            self.release_lock()
예제 #9
0
    def lamp_run(self, on):
        try:
            self.obtain_lock()

            on_byte = 1 if on else 0

            cmd = SPINDIRt1f1Cmd.find('lr')
            self._transact(cmd, (on_byte, ))

        finally:
            self.release_lock()
예제 #10
0
    def reload_calib(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('cl')
            self._transact(cmd)

            time.sleep(cmd.execution_time)

        finally:
            self.release_lock()
예제 #11
0
    def version(self):
        try:
            self.obtain_lock()

            # version ident...
            cmd = SPINDIRt1f1Cmd.find('vi')
            response = self._transact(cmd)
            id = ''.join([chr(byte) for byte in response]).strip()

            # version tag...
            cmd = SPINDIRt1f1Cmd.find('vt')
            response = self._transact(cmd)
            tag = ''.join([chr(byte) for byte in response]).strip()

            version = NDIRVersion(id, NDIRTag.construct_from_jdict(tag))

            return version

        finally:
            self.release_lock()
예제 #12
0
    def input_voltage(self):
        try:
            self.obtain_lock()

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

            return v_in_voltage

        finally:
            self.release_lock()
예제 #13
0
    def input_raw(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('ir')
            response = self._transact(cmd)
            v_in_value = Decode.unsigned_int(response, '<')

            return v_in_value

        finally:
            self.release_lock()
예제 #14
0
    def get_sample_pressure(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('sb')
            response = self._transact(cmd)

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

            return round(p_a, 1)

        finally:
            self.release_lock()
예제 #15
0
    def measure_raw(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.find('mr')
            response = self._transact(cmd)

            pile_ref_value = Decode.unsigned_int(response[0:2], '<')
            pile_act_value = Decode.unsigned_int(response[2:4], '<')
            thermistor_value = Decode.unsigned_int(response[4:6], '<')

            return pile_ref_value, pile_act_value, thermistor_value

        finally:
            self.release_lock()
예제 #16
0
    def get_sample_gas(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.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()
예제 #17
0
    def measure_voltage(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRt1f1Cmd.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()
예제 #18
0
    def get_sample_raw(self):
        try:
            self.obtain_lock()

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

            pile_ref_amplitude = Decode.unsigned_int(response[0:2], '<')
            pile_act_amplitude = Decode.unsigned_int(response[2:4], '<')
            thermistor_average = Decode.unsigned_int(response[4:6], '<')

            return pile_ref_amplitude, pile_act_amplitude, thermistor_average

        finally:
            self.release_lock()
예제 #19
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()
예제 #20
0
    def get_sample_offsets(self):
        try:
            self.obtain_lock()

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

            min_ref_offset = Decode.unsigned_int(response[0:2], '<')
            min_act_offset = Decode.unsigned_int(response[2:4], '<')
            max_ref_offset = Decode.unsigned_int(response[4:6], '<')
            max_act_offset = Decode.unsigned_int(response[6:8], '<')

            return min_ref_offset, min_act_offset, max_ref_offset, max_act_offset

        finally:
            self.release_lock()