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()
    def reset(self):
        try:
            self.obtain_lock()

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

            time.sleep(cmd.execution_time)

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

        finally:
            self.release_lock()
    def _calib_w_float(self, block, index, value):
        cmd = SPINDIRx1Cmd.find('cw')

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

        time.sleep(cmd.execution_time)
    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
    def watchdog_clear(self):
        try:
            self.obtain_lock()

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

        finally:
            self.release_lock()
    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 = SPINDIRx1Cmd.find('rs')
            self._transact(cmd, param_bytes)

            # wait...
            execution_time = cmd.execution_time + ((
                (interval * count) + deferral) / 1000)
            # print("execution time: %s" % execution_time, file=sys.stderr)

            time.sleep(execution_time)

            # playback...
            cmd = SPINDIRx1Cmd.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()
    def lamp_level(self, voltage):
        try:
            self.obtain_lock()

            voltage_bytes = Encode.float(voltage, '<')

            cmd = SPINDIRx1Cmd.find('ll')
            self._transact(cmd, voltage_bytes)

        finally:
            self.release_lock()
    def lamp_run(self, on):
        try:
            self.obtain_lock()

            on_byte = 1 if on else 0

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

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

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

            time.sleep(cmd.execution_time)

        finally:
            self.release_lock()
示例#10
0
    def measure_calibrate(self):
        try:
            self.obtain_lock()

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

            time.sleep(cmd.execution_time)

        finally:
            self.release_lock()
示例#11
0
    def version(self):
        try:
            self.obtain_lock()

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

            # version tag...
            cmd = SPINDIRx1Cmd.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 = SPINDIRx1Cmd.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 = SPINDIRx1Cmd.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_mode(self, single_shot):
        try:
            self.obtain_lock()

            mode_byte = 1 if single_shot else 0

            cmd = SPINDIRx1Cmd.find('sm')
            self._transact(cmd, (mode_byte, ))

            time.sleep(cmd.execution_time)

        finally:
            self.release_lock()
示例#15
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()
示例#16
0
    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()
示例#17
0
    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()
示例#18
0
    def measure_raw(self):
        try:
            self.obtain_lock()

            cmd = SPINDIRx1Cmd.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()
示例#19
0
    def get_sample_raw(self):
        try:
            self.obtain_lock()

            # report...
            cmd = SPINDIRx1Cmd.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()
示例#20
0
    def get_sample_offsets(self):
        try:
            self.obtain_lock()

            # report...
            cmd = SPINDIRx1Cmd.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()
示例#21
0
    def get_sample_voltage(self):
        try:
            self.obtain_lock()

            # report...
            cmd = SPINDIRx1Cmd.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], '<')

            # print("pile_ref_amplitude: %s pile_act_amplitude: %s thermistor_average: %s" % \
            #       (pile_ref_amplitude, pile_act_amplitude, thermistor_average))

            return pile_ref_amplitude, pile_act_amplitude, thermistor_average

        finally:
            self.release_lock()