Exemplo n.º 1
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": "init"}))

    def get_data(self):
        """
        データを取得します。
        """
        # Lock
        self.tcp_client.lock(self.slot)
        try:
            _result = self.tcp_client.send(json.dumps({"act": "t"}))
            result_data = tpUtils.to_float(_result.decode())
            return result_data
        finally:
            # unLock
            self.tcp_client.unlock(self.slot)
Exemplo n.º 2
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

    def lock(self, slot, name=""):
        """
        排他ロック
        """
        self.tcp_client.lock(slot, name)

    def unlock(self, slot, name=""):
        """
        排他ロック解除
        """
        self.tcp_client.unlock(slot, name)