发布时间:2026/8/24 18:02:04
OPC UA设置事件节点 参考链接Question about Python OPCUA session timeout and client.import asyncio, json from asyncua import Client, ua, Node from asyncua.common.events import Event from datetime import datetime #################################################################################### # Globals: #################################################################################### # OPC UA Client server_url opc.tcp://192.168.10.1:4840 nodes_to_subscribe [ #node-id ns4;i1000, ns0;i2267, ns0;i2259, ] events_to_subscribe [ #(eventtype-node-id, event-node-id) ] #################################################################################### # OpcUaClient: #################################################################################### class SubscriptionHandler: The SubscriptionHandler is used to handle the data that is received for the subscription. def datachange_notification(self, node: Node, val, data): Callback for asyncua Subscription. This method will be called when the Client received a data change message from the Server. print(node, val, data) def event_notification(self, event: Event): called for every event notification from server print(event) def status_change_notification(self, status): called for every status change notification from server print(status) async def opcua_client(): -handles connect/disconnect/reconnect/subscribe/unsubscribe -connection-monitoring with cyclic read of the service-level client Client(urlserver_url) handler SubscriptionHandler() subscription None case 0 subscription_handle_list [] while 1: if case 1: #connect print(connecting...) try: await client.connect() await client.load_type_definitions() print(connected!) case 2 except: print(connection error!) case 1 await asyncio.sleep(5) elif case 2: #subscribe all nodes and events print(subscribing nodes and events...) try: subscription await client.create_subscription(50, handler) subscription_handle_list [] if nodes_to_subscribe: for node in nodes_to_subscribe: handle await subscription.subscribe_data_change(client.get_node(node)) subscription_handle_list.append(handle) if events_to_subscribe: for event in events_to_subscribe: handle await subscription.subscribe_events(event[0], event[1]) subscription_handle_list.append(handle) print(subscribed!) case 3 except: print(subscription error) case 4 await asyncio.sleep(0) elif case 3: #running read cyclic the service level if it fails disconnect and unsubscribe wait 5s connect try: service_level await client.get_node(ns0;i2267).get_value() if service_level 200: case 3 else: case 4 await asyncio.sleep(5) except: case 4 elif case 4: #disconnect clean unsubscribe, delete subscription then disconnect print(unsubscribing...) try: if subscription_handle_list: for handle in subscription_handle_list: await subscription.unsubscribe(handle) await subscription.delete() print(unsubscribed!) except: print(unsubscribing error!) subscription None subscription_handle_list [] await asyncio.sleep(0) print(disconnecting...) try: await client.disconnect() except: print(disconnection error!) case 0 else: #wait case 1 await asyncio.sleep(5) #################################################################################### # Run: #################################################################################### if __name__ __main__: asyncio.ensure_future(opcua_client()) asyncio.get_event_loop().run_forever()

相关新闻

2026/8/24 18:02:04

篮球 ·篮球 篮球 篮球 篮球 篮球 篮球

//-----TYPE 41 降肘顶肘 定手式---- *手肘自然压缩,手肘降低为顶肘腾出上顶空间。 - [定型] : 左右垂直瞄准, 但是眼睛注意力始终在篮筐。降肘: 目的不是为了降肘而降肘,而是为了给顶肘向上发力的空间,手肘放低(大多时候手肘平于或低于肩)…

2026/8/24 18:02:04

Qt QStackedWidget详解:抽屉式界面管理器的原理、实战与优化

1. 项目概述:为什么你需要一个“抽屉式”的界面管理器? 在桌面应用开发中,尤其是使用Qt框架时,我们经常会遇到一个经典场景:一个主窗口里,需要根据用户的不同操作(比如点击侧边栏的不同按钮、选…

2026/8/24 18:02:04

GPGPU编程模型与架构原理:从浮点运算到矩阵乘法优化

1. 项目概述:从“一句话”到“一整套”的GPGPU认知跃迁 最近在网上看到不少朋友在讨论“一句话告诉我浮点运算的机理”,这让我想起了十多年前刚接触通用图形处理器(GPGPU)编程时的自己。那时候,面对CUDA或者OpenCL的官…

2026/8/24 20:23:14

开源桌面宠物dsh-pet v0.3:零门槛部署与Python二次开发指南

这次我们来看一个开源桌面宠物项目——鲸鱼娘校宠 dsh-pet v0.3。它不是一个复杂的AI模型,而是一个用Python写的、会动会叫的桌面小精灵,核心目标就是“陪伴”:在你工作或学习时,它会在屏幕角落游来游去,偶尔互动&…

2026/8/24 20:23:14

智能制造转型实战:从概念到落地的核心能力与实施路径

1. 先看懂“智造之城”到底在解决什么实际问题“智造之城”不是一个简单的口号,它背后要解决的是所有工业城市发展到一定阶段后都会遇到的瓶颈问题:如何在土地、劳动力等传统要素成本持续上升的背景下,继续保持甚至提升工业的竞争力、利润率和…

2026/8/24 20:23:14

【数据结构】排序算法:归并排序与基数排序

考点频率:★★★★☆(选择题常考,归并排序的复杂度与稳定性是重点,基数排序常考其适用场景) 难度:⭐⭐⭐⭐(归并排序需理解分治与合并,基数排序需理解分配与收集过程) 建…

2026/8/24 20:23:14

Aurora IDE 测试版 1.0 深度体验:从安装配置到 Web 项目实战全指南

最近在尝试新的开发工具时,发现了一款名为 Aurora IDE 的集成开发环境,它目前处于测试版 1.0 阶段。对于开发者而言,一个顺手的 IDE 能极大提升编码效率和幸福感。本文将基于 Aurora IDE 测试版 1.0,为大家带来一份从零开始的深…

2026/8/24 20:18:13

Czkawka:一款开源工具找出重复文件、相似图片与空文件夹

Czkawka:一款开源工具找出重复文件、相似图片与空文件夹 【免费下载链接】czkawka Multi functional app to find duplicates, empty folders, similar images etc. 项目地址: https://gitcode.com/GitHub_Trending/cz/czkawka Czkawka 是一款用 Rust 编写的…

2026/8/24 0:07:22

[光学原理与应用-521]:对光的错误理解与纠偏

首先光是一种能量的载体和形态,宏观上观察到的光是由无数个微观的光量子组成的,每个光子在产生的瞬间,其在真空的空间中以确定不变的速度沿着一个初始的方向一直向前,在微观层面,每个光量子的运动轨迹是以波函数所展现…

2026/8/24 1:12:32

SIP通话转接原理与REFER方法实战解析

1. 通话转接不是“挂断再拨号”,而是SIP会话的动态重定向你有没有遇到过这样的场景:客服坐席A正在和客户通电话,突然需要把这通对话无缝转给专家坐席B,客户完全感知不到中间的断连——既没听到忙音,也没被要求重新拨号…

2026/8/24 8:17:29

Kolla-ansible单节点OpenStack部署实战:从环境准备到排坑指南

1. 为什么选择Kolla-ansible来部署单节点OpenStack?如果你正在寻找一种能把OpenStack从“概念”快速变成“可用的实验环境”的方法,那么Kolla-ansible几乎是当前最主流、最省心的选择。我见过太多人卡在手动编译依赖、配置服务、处理版本冲突的泥潭里&am…

2026/8/24 1:09:25

3条命令跑通LocalAI:无GPU本地AI引擎部署

3条命令跑通LocalAI:无GPU本地AI引擎部署 【免费下载链接】LocalAI LocalAI is the open-source AI engine. Run any model - LLMs, vision, voice, image, video - on any hardware. No GPU required. 项目地址: https://gitcode.com/GitHub_Trending/lo/LocalAI…

2026/8/24 1:09:25

AI推理性能测试怎么做:MLPerf Inference完整上手指南

AI推理性能测试怎么做:MLPerf Inference完整上手指南 【免费下载链接】inference Reference implementations of MLPerf inference benchmarks 项目地址: https://gitcode.com/gh_mirrors/inf/inference 同一个模型换一张卡,速度快多少你知道吗&a…

2026/8/24 13:42:17

实测才敢推 AI论文网站 2026最新测评与推荐

2026年真正好用的AI论文网站,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。一、综…

2026/8/24 18:13:48

2026必备!AI论文网站测评:最新推荐与深度对比

2026年真正好用的AI论文网站,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。 一、…

2026/8/23 4:22:01

摆脱论文困扰!盘点2026年全网爆红的的AI论文写作工具

一天写完毕业论文在2026年已不再是天方夜谭。2026年最炸裂、实测能大幅提速的AI论文写作工具,覆盖选题构思、文献整理、内容生成、格式排版等核心场景,真正帮你高效搞定论文难题。 一、全流程王者:一站式搞定论文全链路(一天定稿首…