コード例 #1
0
    def i2c_write(self, slot, address, vals):
        """ I2C書き込み(cmdなし)
            slot    : 'S01' ~ 'S10'
            address : I2Cアドレス
            vals    : 書き込みデータ、1 or 2 byte
            戻り    : なし
        """
        slot_num = tpUtils.slot_str_to_int(slot)
        if len(vals) != 1 and len(vals) != 2:
            raise ValueError('I2C write data number error! : ' +
                             str(len(vals)))

        self.i2c_lock.acquire(1)
        try:
            self.__board.i2c_select(slot_num)
            if len(vals) == 1:
                self.__board.i2c_write_1byte(address, vals[0])
            else:  # 2byte
                self.__board.i2c_write_2byte(address, vals[0], vals[1])
        except:
            raise
        finally:
            self.__board.i2c_select()  # slot選択解除
            self.i2c_lock.release()
        return
コード例 #2
0
    def tp52_init(self, slot):
        """ #52 初期化&補正値確保
            slot : 'S01', 'S03', 'S07', 'S09'
            戻り : なし
        """
        slot_num = tpUtils.slot_str_to_int(slot)
        if slot_num != 1 and slot_num != 3 and slot_num != 7 and slot_num != 9:
            raise ValueError('tp52_init error! : slot = ' + slot)
        # Reset
        self.__inter.gpio_write(slot, 'C', 0)
        time.sleep(0.1)
        self.__inter.gpio_write(slot, 'C', 1)
        time.sleep(0.1)

        # 初期化
        # I2Cはconfigで150kbpsに設定すること
        self.__inter.i2c_write(slot, 0x10, [0x03])
        for i in range(4):
            self.__inter.i2c_write_with_cmd(slot, 0x10, 0x02, [i, 0x1C])
            self.__tp52_int_wait(slot)
        #   param read(補正係数)
        self.__inter.i2c_write(slot, 0x10, [0x06])
        self.__tp52_int_wait(slot)
        time.sleep(0.1) # 150Kbpsにしてさらにwait必要
        v = self.__inter.i2c_read_with_cmd(slot, 0x10, 0, 16)
        #print(slot, list(map(hex, v)))
        self.__tp52_err_comp[slot_num - 1][0] = self.__tp52_error_compensation(v[0],  v[1],  v[2],  v[3])
        self.__tp52_err_comp[slot_num - 1][1] = self.__tp52_error_compensation(v[4],  v[5],  v[6],  v[7])
        self.__tp52_err_comp[slot_num - 1][2] = self.__tp52_error_compensation(v[8],  v[9],  v[10], v[11])
        self.__tp52_err_comp[slot_num - 1][3] = self.__tp52_error_compensation(v[12], v[13], v[14], v[15])
        #print(slot, self.__tp52_err_comp[slot_num - 1])
        self.__tp52_int_wait(slot)
        return
コード例 #3
0
 def __tp22_init(self, setting):
     """ tibbit #22設定
         setting : self.settingsの要素
         戻り    : なし
     """
     slot_num = tpUtils.slot_str_to_int(setting['slot'])
     self.__board.tp22_init(slot_num)
コード例 #4
0
 def __gpio_init(self, setting):
     """ tibbit GPIO設定、入力変化時のみ抜出
         setting : self.settingsの要素
         戻り    : なし
     """
     slot_num = tpUtils.slot_str_to_int(setting['slot'])
     for pin in setting['pin']:
         #print(pin)
         if pin['status'] == 'IN' and 'edge' in pin:
             if pin['edge'] == 'on':
                 line_num = tpUtils.line_str_to_int(pin['name'])
                 self.__board.gpio_event_init(self.__gpio_event_callback,
                                              slot_num, line_num)
         if pin['status'] == 'IN':
             line_num = tpUtils.line_str_to_int(pin['name'])
             self.__board.gpio_init(slot_num, line_num, LINE_SETTING_D_IN)
         elif pin['status'] == 'OUT_OD':
             line_num = tpUtils.line_str_to_int(pin['name'])
             self.__board.gpio_init(slot_num, line_num,
                                    LINE_SETTING_D_OUT_OD)
         elif pin['status'] == 'OUT':
             line_num = tpUtils.line_str_to_int(pin['name'])
             self.__board.gpio_init(slot_num, line_num, LINE_SETTING_D_OUT)
         elif pin['status'] == 'IN_Analog':
             line_num = tpUtils.line_str_to_int(pin['name'])
             self.__board.gpio_init(slot_num, line_num, LINE_SETTING_A_IN)
     return
コード例 #5
0
 def tp26_get_record(self, slot):
     """ #26 記録読み込み
         slot : 'S01' ~ 'S10'
         戻り : byte配列
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     return self.__board.tp26_get_record(slot_num)
コード例 #6
0
    def start(self, callback_recv, callback_recv_dsr):
        """
        開始処理
        """

        # confからmodeを取得する
        if (self.host is None or self.host == ''):
            self.host = 'localhost'
        tp_config = TpConfig(self.host, self.slot, self.comm)
        setting = tp_config.get_setting()

        mode = setting['settings']['mode']

        if mode == 'RS232':
            self.__setModeVal(1, 0)
        elif mode == 'RS422':
            self.__setModeVal(1, 1)
        elif mode == 'RS485':
            self.__setModeVal(0, 1)
        else:
            raise ValueError('Tibbit #02 Line error!')

        self.tcp_client = TcpClient(callback_recv)
        self.tcp_client.connect_by_conf_recv(self.host, self.slot, self.comm)

        # DSR
        slot_num = tpUtils.slot_str_to_int(self.slot)
        slot_num = slot_num + 1
        slot_gpio = tpUtils.slot_int_to_str(slot_num)
        self.gpio_tcp_client = TcpClient(callback_recv_dsr)
        self.gpio_tcp_client.connect_by_conf_recv(self.host, slot_gpio, GPIO)
コード例 #7
0
    def spi_access(self, slot, address, vals):
        """ SPI書き込み・読み出し
            slot    : 'S01' ~ 'S10', 'S00'はPICだが、隠し機能
            address : レジスタアドレス 
            vals    : 書き込みデータ, 読み込み時はdummy
            戻り    : 読み込みデータ
        """
        # slot選択
        slot_num = tpUtils.slot_str_to_int(slot)

        # P1は以外はtpPxInterface内部で排他制御
        if self.__board_kind == 'P1': self.spi_lock.acquire(1)

        # SPI情報取得
        mode = 0
        speed = 0
        endian = 0
        for elem in self.settings:
            if elem['slot'] != slot: continue
            setting = elem['settings']
            mode = int(setting['mode'])
            speed = int(setting['speed'])
            endian = int(setting['endian'])
            break

        # SPIアクセス
        data = self.__board.spi_access(slot_num, mode, speed, endian, 0,
                                       address, vals)

        # P1は以外はtpPxInterface内部で排他制御
        if self.__board_kind == 'P1': self.spi_lock.release()

        return data
コード例 #8
0
 def __tp52_init(self, setting):
     """ tibbit #52設定
         setting : self.settingsの要素
         戻り    : なし
     """
     slot_num = tpUtils.slot_str_to_int(setting['slot'])
     self.__board.i2c_init(slot_num, 50)  # 50Kbps
     self.__board.tp52_init(slot_num)
コード例 #9
0
 def tp26_start_play(self, slot):
     """ #26 再生開始
         slot : 'S01' ~ 'S10'
         戻り : なし
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.__board.tp26_start_play(slot_num)
     return
コード例 #10
0
 def tpFPGA_write(self, slot, file_path):
     """ FPGA Tibbit(#26,57), FPGAリセット&書き込み
         slot      : 'S01' ~ 'S10'
         file_path : binイメージのファイル名フルパス
         戻り : なし
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.__board.tpFPGA_write(slot_num, file_path)
     return
コード例 #11
0
 def tp26_put_play(self, slot, vals):
     """ #26 記録書き込み
         slot : 'S01' ~ 'S10'
         vals : 記録したバイナリ配列
         戻り : なし
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.__board.tp26_put_play(slot_num, vals)
     return
コード例 #12
0
 def __spi_init(self, setting):
     """ tibbit SPI設定
         setting : self.settingsの要素
         戻り    : なし
     """
     slot_num = tpUtils.slot_str_to_int(setting['slot'])
     # 通信情報設定
     kbaud = setting['settings']['speed']
     kbaud_num = int(kbaud)
     self.__board.spi_init(slot_num, kbaud_num)
コード例 #13
0
    def serial_write(self, slot, vals):
        """
        Serial書き込み
        slot    : 'S01' ~ 'S10'
        vals    : 書き込みデータ
        """
        # slot選択
        slot_num = tpUtils.slot_str_to_int(slot)

        # Serial書き込み
        self.__board.serial_write(slot_num, vals)
コード例 #14
0
 def __i2c_init(self, setting):
     """ tibbit I2C設定
         setting : self.settingsの要素
         戻り    : なし
     """
     slot_num = tpUtils.slot_str_to_int(setting['slot'])
     # 通信情報設定
     kbaud = setting['settings']['baudRateK']
     #print(slot_num, kbaud)
     kbaud_num = int(kbaud)
     self.__board.i2c_init(slot_num, kbaud_num)
     return
コード例 #15
0
 def gpio_in_out_init(self, slot, line, kind):
     """ GPIO実行時で設定
         slot : 1 ~ 10
         line : 'A' ~ 'D'
         kind : 0 ~ 4(NONE/ANALOG/IN/OUT_OD/OUT)
         戻り : なし
     """
     #print('gpio_in_out_init', slot, line, kind)
     slot_num = tpUtils.slot_str_to_int(slot)
     line_num = tpUtils.line_str_to_int(line)
     self.__board.gpio_in_out_init(slot_num, line_num, kind)
     return
コード例 #16
0
 def tp22_init(self, slot):
     """ Tibbit #22 初期化
         slot : 'S01' ~ 'S10'
         戻り : なし
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     # Reset
     self.__inter.gpio_write(slot, 'C', 0)
     time.sleep(0.1)
     self.__inter.gpio_write(slot, 'C', 1)
     time.sleep(0.1)
     return
コード例 #17
0
 def __gpio_init(self, setting):
     """
     tibbit GPIO設定、入力変化時のみ抜出
     setting : self.settingsの要素
     """
     slot_num = tpUtils.slot_str_to_int(setting['slot'])
     for pin in setting['pin']:
         #print(pin)
         if pin['status'] == 'IN' and 'edge' in pin:
             if pin['edge'] == 'on':
                 line_num = tpUtils.line_str_to_int(pin['name'])
                 self.__board.gpio_event_init(self.__gpio_event_callback,
                                              slot_num, line_num)
コード例 #18
0
 def tp52_get_correct(self, slot, ch):
     """ #52 補正値を返す
         slot : 'S01', 'S03', 'S07', 'S09'
         ch   : 'CH1'~'CH4'
         戻り : 補正値
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     if slot_num != 1 and slot_num != 3 and slot_num != 7 and slot_num != 9:
         raise ValueError('tp52_get_correct error! : slot = ' + slot)
     ch_num = int(ch[2])
     if ch_num < 1 or ch_num > 4:
         raise ValueError('tp52_get_correct error! : ch = ' + ch)
     return self.__tp52_err_comp[slot_num - 1][ch_num - 1]
コード例 #19
0
 def tp22_temp(self, slot):
     """
     Tibbit#22, RTD読み出し
     slot : 'S01' ~ 'S10'
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.i2c_lock.acquire(1)
     try:
         data = self.__board.tp22_temp(slot_num)
     except:
         raise
     finally:
         self.i2c_lock.release()
     return data
コード例 #20
0
 def i2c_write_tp22(self, slot, val):
     """
     Tibbit#22, I2C書き込み
     slot : 'S01' ~ 'S10'
     val  : 書き込みデータ、1byteのみ
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.i2c_lock.acquire(1)
     try:
         self.__board.i2c_write_tp22(slot_num, val)
     except:
         raise
     finally:
         self.i2c_lock.release()
コード例 #21
0
 def i2c_read_tp22(self, slot, num):
     """
     Tibbit#22, I2C読み出し
     slot : 'S01' ~ 'S10'
     num  : 読み込みbyte数
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.i2c_lock.acquire(1)
     try:
         data = self.__board.i2c_read_tp22(slot_num, num)
     except:
         raise
     finally:
         self.i2c_lock.release()
     return data
コード例 #22
0
 def i2c_write_tp22_spi(self, slot, addr, val):
     """
     Tibbit#22, I2C書き込み(内部SPIデバイス)
     slot : 'S01' ~ 'S10'
     addr : SPIアドレス、0x80以上
     val  : 書き込みデータ、1byteのみ
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.i2c_lock.acquire(1)
     try:
         self.__board.i2c_write_tp22(slot_num, val, addr)
     except:
         raise
     finally:
         self.i2c_lock.release()
コード例 #23
0
 def tp22_temp(self, slot):
     """ Tibbit#22, RTD読み出し
         slot : 'S01' ~ 'S10'
         戻り : C戻り値、温度生データ
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.i2c_lock.acquire(1)
     try:
         self.__board.i2c_select(slot_num)
         c_ret, data = self.__board.tp22_temp()
     except:
         raise
     finally:
         self.__board.i2c_select()  # slot選択解除
         self.i2c_lock.release()
     return c_ret, data
コード例 #24
0
    def __serial_init(self, setting):
        """ tibbit Seral設定
            setting : self.settingsの要素
            戻り    : なし
        """
        slot_num = tpUtils.slot_str_to_int(setting['slot'])
        if slot_num % 2 == 0:  # 奇数slotのみ対応
            raise ValueError('Serial slot error! : ' + str(slot_num))
        try:
            # 通信情報設定
            baud = setting['settings']['baudRate']
            flow = setting['settings']['hardwareFlow']
            parity = setting['settings']['parity']
            sep_kind = setting['settings']['splitInput']
            sep_char = setting['settings']['onTheCharactor']
            sep_time = setting['settings']['afterATimeoutOf']
            sep_leng = setting['settings']['intoFixedLengthOf']
        except Exception:
            # 設定エラー
            raise tpUtils.TpCheckError('Please check the serial setting.')

        #print(slot_num, baud, flow, parity, sep_char, sep_time, sep_leng)
        baud_num = int(baud)
        flow_num = 1 if flow == 'on' else 0
        parity_num = 0 if parity == 'none' else 1 if parity == 'odd' else 2
        self.__board.serial_init(self.__serial_event_callback, slot_num,
                                 baud_num, flow_num, parity_num)

        # 受信用情報確保
        pos = int((slot_num - 1) / 2)
        if sep_kind == '1':
            self.__serial_info[pos]['recv_kind'] = 'CHAR'
            self.__serial_info[pos]['char'] = sep_char
        elif sep_kind == '2':
            self.__serial_info[pos]['recv_kind'] = 'TIME'
            self.__serial_info[pos]['time'] = int(sep_time)
            self.__serial_info[pos]['lock'] = thread.allocate_lock()
            thread.start_new_thread(self.__serial_recv_time_thread,
                                    (slot_num, int(sep_time)))
        elif sep_kind == '3':
            self.__serial_info[pos]['recv_kind'] = 'LENG'
            self.__serial_info[pos]['leng'] = int(sep_leng)
        else:
            self.__serial_info[pos]['recv_kind'] = 'NONE'
        #print(self.__serial_info)
        return
コード例 #25
0
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = Serial
        self.host = host

        # LINE C
        self.io_tcp_client = None

        # LINE G/H
        slot_num = tpUtils.slot_str_to_int(self.slot)
        slot_num = slot_num + 1
        slot_gpio = tpUtils.slot_int_to_str(slot_num)
        self.gpio_tcp_client = TcpClient()
        self.gpio_tcp_client.connect_by_conf(self.host, slot_gpio, GPIO)
コード例 #26
0
 def i2c_block_write(self, slot, address, cmd, vals):
     """
     I2Cブロック書き込み、コマンド付き
     slot    : 'S01' ~ 'S10'
     address : I2Cアドレス
     cmd     : コマンド
     vals    : 書き込みデータ、リスト
     """
     slot_num = tpUtils.slot_str_to_int(slot)
     self.i2c_lock.acquire(1)
     try:
         self.__board.i2c_select(slot_num)
         self.__board.i2c_write_block_data(address, cmd, vals)
     except:
         raise
     finally:
         self.__board.i2c_select()  # slot選択解除
         self.i2c_lock.release()
コード例 #27
0
    def analog_read(self, slot, line):
        """ GPIO アナログ値読み出し
            slot : 'S01' ~ 'S10'
            line : 'A' ~ 'D'
            戻り : analog値
        """
        slot_num = tpUtils.slot_str_to_int(slot)
        line_num = tpUtils.line_str_to_int(line)
        dat = 0

        if self.__board_kind == 'P1':
            # P1には機能なし
            return
        elif self.__board_kind == 'P2':
            dat = self.__board.analog_read(slot_num, line_num)
        else:  # P3
            dat = self.__board.analog_read(slot_num, line_num)

        return dat
コード例 #28
0
    def i2c_read(self, slot, address, num):
        """ I2C読み出し(cmdなし)
            slot    : 'S01' ~ 'S10'
            address : I2Cアドレス
            num     : 読み込みbyte数
            戻り    : i2cデータ
        """
        slot_num = tpUtils.slot_str_to_int(slot)

        self.i2c_lock.acquire(1)
        try:
            self.__board.i2c_select(slot_num)
            data = self.__board.i2c_read(address, -1, num)
        except:
            raise
        finally:
            self.__board.i2c_select()  # slot選択解除
            self.i2c_lock.release()
        return data
コード例 #29
0
    def __setModeVal(self, ch_a, ch_b):
        """
        モードをセット
        """

        slot_num = tpUtils.slot_str_to_int(self.slot)
        slot_num = slot_num + 1
        slot_gpio = tpUtils.slot_int_to_str(slot_num)
        temp_tcp_client = TcpClient()
        temp_tcp_client.connect_by_conf(self.host, slot_gpio, GPIO)

        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'A'
        tmp_data["v"] = ch_a
        send_data.append(tmp_data)
        tmp_data = {}
        tmp_data["line"] = 'B'
        tmp_data["v"] = ch_b
        send_data.append(tmp_data)
        temp_tcp_client.send(json.dumps(send_data))
コード例 #30
0
    def gpio_write(self, slot, line, val):
        """ GPIO書き込み
            slot : 'S01' ~ 'S10'
            line : 'A' ~ 'D'
            val  : '0' or '1' (Low or High)
            戻り : なし
        """
        slot_num = tpUtils.slot_str_to_int(slot)
        line_num = tpUtils.line_str_to_int(line)

        if self.__board_kind == 'P1':
            self.i2c_lock.acquire(1)
            self.__board.gpio_write(slot_num, line_num, int(val))
            self.i2c_lock.release()
        elif self.__board_kind == 'P2':
            #self.spi_lock.acquire(1) # P2はtpP2Interface内部で排他制御
            self.__board.gpio_write(slot_num, line_num, int(val))
            #self.spi_lock.release()
        else:  # P3
            self.__board.gpio_write(slot_num, line_num, int(val))
        return