class Tp12_out:
    """
    #12 Low-power +15/-15V power supply, 5V input
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = GPIO
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """

        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'A'
        tmp_data["v"] = msg
        send_data.append(tmp_data)

        self.tcp_client.send(json.dumps(send_data))
Exemplo n.º 2
0
class Tp26:
    """
    #26 IR code processor
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = 'TP26'
        self.host = host

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # FPGA内容書き込み
        file = os.path.dirname(os.path.abspath(__file__)) + \
            '/bin/IR_Remote_bitmap.bin'

        if os.path.exists(file) == False:
            raise FileNotFoundError("Not Found: " + file)
        self.tcp_client.send(json.dumps({"act": "fw", "file_path": file}))

    def send(self, msg):
        """
        データを送信します。
        """

        _result = self.tcp_client.send(msg)
        return _result.decode('utf-8')
Exemplo n.º 3
0
class Tp03_out:
    """
    #03 Two low-power relays (configuration 1)
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = GPIO
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """

        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 4
0
class Tp07_out:
    """
    #07 Two solid state relays
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = GPIO
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """

        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 5
0
class Tp22:
    """
    #22 RTD Temperature Meter
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = 'TP22'
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # 一度読み込む
        self.tcp_client.send(json.dumps({"act": "t"}))

    def get_data(self):
        """
        データを取得します。
        """

        _result = self.tcp_client.send(json.dumps({"act": "t"}))
        result_data = tpUtils.to_float(_result.decode())
        return result_data
Exemplo n.º 6
0
class TpcBuzzer:
    """
    TP Buzzer
    """
    def __init__(self, host=None):
        """
        コンストラクタ
        """
        self.slot = "S00"
        self.comm = TP_BUZZER
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """
        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 7
0
class Tp58_out:
    """
    #58 Two 24V NPN isolated open collector outputs
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = GPIO
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """

        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 8
0
class Tp01:
    """
    #01 Four-line RS232 port
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = Serial
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """
        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 9
0
class Tp54:
    """
    #54 Four dry contact inputs
    """

    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = GPIO
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """

        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 10
0
class Tp00:
    """
    #00 direct I/O lines
    """
    def __init__(self, slot, comm, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = comm
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """
        recv_data = self.tcp_client.send(msg)
        return recv_data
Exemplo n.º 11
0
class Tp52:
    """
    #52 Four-channel isolated +/-10V ADC
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = 'TP52'
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # 初期化処理
        self.tcp_client.send(json.dumps({"act": "init"}))

    def get_data(self, msg):
        """
        値を取得します。
        """

        _result = self.tcp_client.send(msg)
        result_data = json.loads(_result.decode())

        return result_data
class Tp05_out:
    """
    # 05 RS485 port
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = Serial
        self.host = host

    def start(self):
        """
        開始処理
        """

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # IN/OUT
        self.io_tcp_client = TcpClient()
        self.io_tcp_client.connect_by_conf(self.host, self.slot, GPIO)

    def send(self, msg):
        """
        データを送信します。
        """
        recv_data = self.tcp_client.send(msg)
        return recv_data

    def set_io(self, high_low):
        """
        送受信を切り替えます
        """

        # the line shall be LOW for data input and HIGH for output.
        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'C'
        tmp_data["v"] = high_low
        send_data.append(tmp_data)
        self.io_tcp_client.send(json.dumps(send_data))
class Tp57_out:
    """
    # 57 FPGA Tibbit
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = 'TP57'
        self.host = host

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """

        self.tcp_client.send(msg)
Exemplo n.º 14
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))
Exemplo n.º 15
0
class Tp53:
    """
    #53 Isolated 4-20mA ADC
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = I2C
        self.host = host

        # アドレス
        self.i2c_addr = 0x48

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # cmd書き込み
        send_data = []
        send_data.append({
            "act": "r",
            "add": self.i2c_addr,
            "cmd": 0x0C,
            "len": 3
        })
        self.__send(json.dumps(send_data))

    def __send(self, msg):
        """
        データを送信します。
        """

        recv_data = self.tcp_client.send(msg)
        return recv_data

    def get_data(self, msg):
        """
        値を取得します。
        """

        # 前回の変換結果を取得
        send_data = []
        send_data.append({"act": "r", "add": self.i2c_addr, "len": 2})
        _result = self.__send(json.dumps(send_data))
        result_data = json.loads(_result.decode())

        byte_hi = result_data[0][0]
        byte_lo = result_data[0][1]

        val = byte_hi * 256 + byte_lo

        # LSB_V = 0.000152587890625 # 5 V / 32768
        # mA_On_V = 0.0032 # (20 mA - 4 mA) / 5000 mV

        # # 電圧(V)への変換例
        # if val <= 0x7FFF:
        #     rtn_v = val * LSB_V
        # else:
        #     rtn_v = 0xFFFF - val + 1
        #     rtn_v = -(rtn_v * LSB_V)
        # print(rtn_v)

        # if rtn_v < -0.6:
        #     return

        # # 電流(A)への変換例
        # rtn_a = rtn_v * mA_On_V
        # rtn_a = rtn_a + 0.004
        # print(rtn_a)

        return val
Exemplo n.º 16
0
class Tp13:
    """
    #13 Four-channel ADC
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = I2C
        self.host = host

        # アドレス
        self.i2c_addr = 0x08

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def __send(self, msg):
        """
        データを送信します。
        """

        recv_data = self.tcp_client.send(msg)
        return recv_data

    def get_data(self, msg):
        """
        値を取得します。
        """

        # 戻り値配列
        rtn = []

        datas = json.loads(msg)

        for data in datas:

            # ch
            ch = None

            # channel select
            if data['ch'] == 1:
                ch = 0x88
            elif data['ch'] == 2:
                ch = 0x98
            elif data['ch'] == 3:
                ch = 0xA8
            elif data['ch'] == 4:
                ch = 0xB8
            else:
                raise ValueError('Tibbit #13 ch error!')

            send_data = []
            # 前回の値が取得できるため、1個目は読み捨てる
            send_data.append({
                "act": "r",
                "add": self.i2c_addr,
                "cmd": ch,
                "len": 2
            })
            # 取得する値
            send_data.append({
                "act": "r",
                "add": self.i2c_addr,
                "cmd": ch,
                "len": 2
            })
            _result = self.__send(json.dumps(send_data))
            result_data = json.loads(_result.decode())

            # 1個目は不要
            byte_hi = result_data[1][0]
            byte_lo = result_data[1][1]
            val = byte_lo / 16 + byte_hi * 16

            # mvへの変換例
            #val = (val*488281-1000000000)/100000
            #val = int(val)

            rtn.append(val)

        return rtn
class Tp14_out:
    """
    #14 Four-channel DAC
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = I2C
        self.host = host

        # アドレス
        self.i2c_addr = 0x60

    def start(self):
        """
        開始処理
        """

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # 初期化(0V)
        data = '[{"ch":1,"v":2048},{"ch":2,"v":2048},{"ch":3,"v":2048},{"ch":4,"v":2048}]'
        self.send(data)

    def send(self, msg):
        """
        データを送信します。
        """

        datas = json.loads(msg)

        for data in datas:

            # ch
            ch = None

            # channel select
            if data['ch'] == 1:
                ch = 0
            elif data['ch'] == 2:
                ch = 1
            elif data['ch'] == 3:
                ch = 2
            elif data['ch'] == 4:
                ch = 3
            else:
                raise ValueError('Tibbit #14 ch error!')

            dw = int(data['v'])

            # mvから変換例
            #dw = dw*100000
            #dw = dw+1000000000
            #v = round(dw/488281)
            v = dw

            if v > 4095:
                v = 4095
            if v < 0:
                v = 0

            tmp = 0x40 + (ch % 4) * 2
            tmp0 = int(0x90 + v / 256)
            tmp1 = v & 0x00FF

            send_data = []
            send_data.append({
                "act": "w",
                "add": self.i2c_addr,
                "cmd": tmp,
                "v": [tmp0, tmp1]
            })
            self.tcp_client.send(json.dumps(send_data))
Exemplo n.º 18
0
class Tp42:
    """
    #42 RTC and NVRAM with backup
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = SPI
        self.host = host

    def start(self):
        """
        開始処理
        """
        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """
        recv_data = self.tcp_client.send(msg)
        return recv_data

    def get_data(self):
        """
        日付を取得
        """

        send_data = []

        READ = 0x00
        vals = [0] * 7
        send_data.append({"add": READ, "v": vals})

        recv = self.send(json.dumps(send_data))
        return self.__convert(recv)

    def __convert(self, msg):
        """
        日付に変換
        """

        buff = json.loads(msg.decode())

        # 年
        year = 2000 + tpUtils.bcd_to_dec(buff[0][6])
        # 月
        month = tpUtils.bcd_to_dec(buff[0][5])
        # 日
        day = tpUtils.bcd_to_dec(buff[0][4])
        # 時
        hour = tpUtils.bcd_to_dec(buff[0][2])
        # 分
        minute = tpUtils.bcd_to_dec(buff[0][1])
        # 秒
        sec = tpUtils.bcd_to_dec(buff[0][0])

        dt = datetime(year, month, day, hour, minute, sec)
        return dt.strftime("%Y/%m/%d %H:%M:%S")

    def send_data(self, msg):
        """
        日付をセット
        """

        # check
        try:
            datetime.strptime(msg, '%Y/%m/%d %H:%M:%S')
        except ValueError:
            raise ValueError(
                "Incorrect data format, should be yyyy-MM-dd HH:mm:ss - " +
                msg)

        send_data = []

        vals = []
        # 秒
        vals.append(tpUtils.dec_to_bcd(int(msg[17:19])))
        # 分
        vals.append(tpUtils.dec_to_bcd(int(msg[14:16])))
        # 時
        vals.append(tpUtils.dec_to_bcd(int(msg[11:13])))

        WRITE = 0x80
        send_data.append({"add": WRITE, "v": vals})

        vals = []
        # 日
        vals.append(tpUtils.dec_to_bcd(int(msg[8:10])))
        # 月
        vals.append(tpUtils.dec_to_bcd(int(msg[5:7])))
        # 年
        vals.append(tpUtils.dec_to_bcd(int(msg[2:4])))

        WRITE = 0x84
        send_data.append({"add": WRITE, "v": vals})

        # send
        self.send(json.dumps(send_data))

        # SET
        return "SET: " + msg
class Tp40_out:
    """
    # 40 Digital potentiometer
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """
        self.slot = slot
        self.comm = I2C
        self.host = host

        # アドレス
        self.i2c_addr = 0x2F

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # 初期化
        send_data = []
        send_data.append(self.__reg_read(0x50))
        send_data.append(self.__reg_write(0x40, 0x000F))
        send_data.append(self.__reg_read(0x40))
        send_data.append(self.__reg_read(0x20))
        self.tcp_client.send(json.dumps(send_data))

    def send(self, data):
        """
        値を送信します。
        """

        level = tpUtils.to_num(data)
        level = level % 257

        send_data = []
        send_data.append(self.__reg_write(0x0, level))
        self.tcp_client.send(json.dumps(send_data))

    def __reg_write(self, addr, data):
        """
        reg_write
        """

        if data & 0x0100:
            cmd = addr + 1
        else:
            cmd = addr

        return {
            "act": "w",
            "add": self.i2c_addr,
            "cmd": cmd,
            "v": [(data & 0x00FF)]
        }

    def __reg_read(self, addr):
        """
        reg_read
        """

        cmd = addr + 0xC
        return {"act": "r", "add": self.i2c_addr, "cmd": cmd, "len": 2}
Exemplo n.º 20
0
class Tp02:
    """
    # 02 RS232/422/485 port
    """
    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)

    def __setModeVal(self, ch_a, ch_b):
        """
        モードをセット
        """

        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)
        self.gpio_tcp_client.send(json.dumps(send_data))

    def start(self):
        """
        開始処理
        """

        # 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)
            # LINE C
            self.io_tcp_client = TcpClient()
            self.io_tcp_client.connect_by_conf(self.host, self.slot, GPIO)
        else:
            raise ValueError('Tibbit #02 Line error!')

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

    def send(self, msg):
        """
        データを送信します。
        """
        recv_data = self.tcp_client.send(msg)
        return recv_data

    def setDtr(self, val):
        """
        DTRにHIGH/LOWを設定
        """

        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'C'
        tmp_data["v"] = val
        send_data.append(tmp_data)
        self.gpio_tcp_client.send(json.dumps(send_data))

    def getDsr(self):
        """
        DSRのHIGH/LOWを取得
        """

        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'D'
        send_data.append(tmp_data)
        recv_data = self.gpio_tcp_client.send(json.dumps(send_data))
        result_data = json.loads(recv_data.decode())
        return result_data[0]

    def set_io(self, high_low):
        """
        送受信を切り替えます
        """

        if self.io_tcp_client is not None:

            # the line shall be LOW for data input and HIGH for output.
            send_data = []
            tmp_data = {}
            tmp_data["line"] = 'C'
            tmp_data["v"] = high_low
            send_data.append(tmp_data)
            self.io_tcp_client.send(json.dumps(send_data))
Exemplo n.º 21
0
class Tp31:
    """
    #31 PIC coprocessor
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = I2C
        self.host = host

        self.tcp_client = TcpClient()
        self.tcp_client.connect_by_conf(self.host, self.slot, self.comm)

        # RST / INT
        self.rst_tcp_client = TcpClient()
        self.rst_tcp_client.connect_by_conf(self.host, self.slot, GPIO)

    def pic_reg_read(self, address, num):
        """
        PICのレジスタRead
        """
        addr1 = address >> 8
        addr2 = address & 0x00FF

        send_data = []
        send_data.append({
            "act": "w",
            "add": 0x03,
            "cmd": 0xFE,
            "v": [addr1, addr2]
        })
        self.tcp_client.send(json.dumps(send_data))

        time.sleep(0.01)

        send_data = []
        send_data.append({"act": "r", "add": 0x03, "cmd": 0, "len": num})
        _result = self.tcp_client.send(json.dumps(send_data))
        result_data = json.loads(_result.decode())

        return result_data[0]

    def pic_reg_write(self, address, vals):
        """
        PICのレジスタWrite
        """
        addr1 = address >> 8
        addr2 = address & 0x00FF
        dat = [addr1, addr2]
        dat.extend(vals)

        send_data = []
        send_data.append({"act": "w", "add": 0x03, "cmd": 0xFE, "v": dat})
        self.tcp_client.send(json.dumps(send_data))

    def pic_reg_reset(self):
        """
        PICのレジスタReset
        """

        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'C'
        tmp_data["v"] = 0
        send_data.append(tmp_data)
        self.rst_tcp_client.send(json.dumps(send_data))

        time.sleep(0.01)

        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'C'
        tmp_data["v"] = 1
        send_data.append(tmp_data)
        self.rst_tcp_client.send(json.dumps(send_data))

    def pic_reg_int(self):
        """
        PICのINT取得
        """
        send_data = []
        tmp_data = {}
        tmp_data["line"] = 'D'
        send_data.append(tmp_data)
        recv_data = self.rst_tcp_client.send(json.dumps(send_data))
        result_data = json.loads(recv_data.decode())
        return result_data[0]

    def send(self, msg):
        """
        データを送信します。
        """

        # 戻り値配列
        rtn_r = []
        rtn_int = []

        datas = json.loads(msg)

        for data in datas:

            if data['act'] == 'r':
                # 読み込み

                address = data['add']
                len = int(data['len'])
                read_data = self.pic_reg_read(address, len)
                rtn_r.append(read_data)

            elif data['act'] == 'w':
                # 書き込み

                address = data['add']
                vals = data['v']
                self.pic_reg_write(address, vals)

            elif data['act'] == 'rst':
                # リセット

                self.pic_reg_reset()

            elif data['act'] == 'int':
                # INT

                read_data = self.pic_reg_int()
                rtn_int.append(read_data)

        rtn = {}
        rtn['r'] = rtn_r
        rtn['int'] = rtn_int
        return rtn