from module.wtMBtcp import wtMBtcp

class tcp_handler:
    def __init__(self, config):
        self._mbtcp = []
        try:
            for cfg in config:
                mbtc = wtMBtcp(cfg['ip'], cfg['port'], cfg['slave_id'])
                self._mbtcp.append(mbtc) 
                del mbtc
        except Exception as exp:
            print(exp)

    def data_write_handler(self, id, cmd, address, new_value, data_type):
        wtmbtcp : wtMBtcp
        try:
            for wtmbtcp in self._mbtcp:
                wtmbtcp.modify_register(id, cmd, address, new_value, data_type)    
        except Exception as exp:
            print(exp)
            
