使用python opcua 订阅节点之后,如果opcua断链之后,如何是她重新链接,或者如何知道是否断链
def run(): time.sleep(3) logging.basicConfig(level=logging.WARN) base_path = os.path.dirname(os.path.dirname(__file__)) json_file_path = os.path.join(base_path, "jsonfile") file_name = "hmi1.json" json_file = os.path.join(json_file_path, file_name) with open(json_file, 'r', encoding="utf-8") as f: json_list = json.load(f) client = Client(f"opc.tcp://{plc_ip}:{plc_port}") try: client.connect() client.load_type_definitions() # params = ua.CreateSubscriptionParameters() # params.RequestedPublishingInterval = 2000 # params.RequestedLifetimeCount = 30000 # params.RequestedMaxKeepAliveCount = 10000 # params.MaxNotificationsPerPublish = 2147483649 # params.PublishingEnabled = True # params.Priority = 0 # params._freeze = True t1 = time.time() node_list = [] area_key = "" for key, node_id in json_list.items(): if key == "REEFER": area_key = key for node in node_id: node_id = node.get('NodeId') node_list.append(node_id) handler = SubHandler(json_list, area_key) sub = client.create_subscription(50, handler) for node in node_list: handle = sub.subscribe_data_change(client.get_node(node)) t2 = time.time() - t1 print(t2, "over_time") const = 0 # while True: # const += 1 # time.sleep(1) # print(const) embed() print(client.disconnect()) except Exception as e: print(e) finally: client.disconnect()
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。