Exemplo n.º 1
0
class Tp54_in:
    """
    #54 Four dry contact inputs
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = GPIO
        self.host = host

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

    def wait_for_recv(self):
        """
        データ受信待ち
        """
        self.tcp_client.recv()
class TpcButton:
    """
    TP Button
    """
    def __init__(self, host=None):
        """
        コンストラクタ
        """

        self.slot = "S00"
        self.comm = TP_BUTTON
        self.host = host

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

    def wait_for_recv(self):
        """
        データ受信待ち
        """
        self.tcp_client.recv()
class Tp00_in:
    """
    #00 direct I/O lines
    """
    def __init__(self, slot, comm, host=None):
        """
        コンストラクタ
        """

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

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

    def wait_for_recv(self):
        """
        データ受信待ち
        """
        self.tcp_client.recv()
class Tp01_in:
    """
    #01 Four-line RS232 port
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = Serial
        self.host = host

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

    def wait_for_recv(self):
        """
        データ受信待ち
        """
        self.tcp_client.recv()
class Tp31_in:
    """
    #31 PIC coprocessor
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = GPIO
        self.host = host

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

    def wait_for_recv(self):
        """
        データ受信待ち
        """
        self.tcp_client.recv()
Exemplo n.º 6
0
class Tp00_in:
    """
    #00 direct I/O lines
    """
    def __init__(self,
                 slot,
                 comm,
                 host=None,
                 target_line=['A', 'B', 'C', 'D']):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = comm
        self.host = host
        # GPIOのみ有効(対象となるライン)
        self.target_line = target_line

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

        self.callback_recv = callback_recv

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

    def wait_for_recv(self):
        """
        データ受信待ち
        """
        self.tcp_client.recv()

    def __callback_recv(self, recv_data):
        """
        データ受信イベント
        """

        if self.comm == GPIO:
            # GPIOの場合、監視対象のラインかチェック
            result_data = json.loads(recv_data.decode())
            if result_data['line'] in self.target_line:
                # 含むときだけコールバックを呼ぶ
                self.handler(self.callback_recv, recv_data)
        else:
            self.handler(self.callback_recv, recv_data)

    def handler(self, func, *args):
        """
        ハンドラー
        """
        return func(*args)
Exemplo n.º 7
0
class Tp02_in:
    """
    #02 RS232/422/485 port
    """
    def __init__(self, slot, host=None):
        """
        コンストラクタ
        """

        self.slot = slot
        self.comm = Serial
        self.host = host

    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))

    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)

    def wait_for_recv(self):
        """
        データ受信待ち
        """

        thread.start_new_thread(self.tcp_client.recv, ())
        thread.start_new_thread(self.gpio_tcp_client.recv, ())

        # 待ち処理
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            pass