> For the complete documentation index, see [llms.txt](https://docs.zongsoft.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zongsoft.com/framework/externals/integration.md).

# OPC UA 设备协议

理解 OPC UA 的节点、会话、订阅与证书，并规划工业设备接入。

OPC UA 为工业设备和应用之间的数据交换提供统一协议。本页介绍节点、会话、订阅与证书等基础概念，以及接入前需要准备的运行条件。

## OPC UA 的基本概念

OPC UA 以服务端地址空间组织设备数据。**NodeId** 标识节点，节点的值还伴随类型、状态码和时间戳；仅显示数值会丢失质量及采样时间信息。

**Session** 是与服务器交互的会话；**Subscription** 及监视项用于持续接收变化。订阅不是永久有效对象，断线重连、服务器重启和证书变更后，都需要验证其恢复状态。

`Zongsoft.Externals.Opc` 提供相关客户端、服务端及读写订阅适配。插件让程序集和 SDK 可用，实际端点、证书信任、会话建立和[工作器](https://github.com/Zongsoft/framework/blob/main/Zongsoft.Core/src/Components/IWorker.cs)生命周期由应用组织。

## 从本地示例开始

先阅读[OPC 示例说明](https://github.com/Zongsoft/framework/blob/main/externals/opc/samples/README.zh-Hans.md)，使用其中配套的本地 server/client 项目。建议依次验证连接、浏览、读取一个已知节点、订阅变化，再验证断线后的恢复。

真实设备写入前还要明确数据类型、量纲、允许范围和设备状态。不能因为 SDK 写入方法返回成功，就忽略设备侧联锁和后续状态确认。

## 证书与身份

应用证书用于建立受信任通信，用户身份决定会话能执行哪些操作，两者不能相互替代。证书主题、应用 URI、有效期及信任目录都应与实际部署一致。

{% hint style="warning" %}
🚨 不要把示例自签名证书、自动信任所有证书或写在命令行中的示例密码作为正式部署方案。私钥和信任目录由运行账号保护；信任变更后应验证客户端与服务器双方的连接行为。
{% endhint %}

诊断至少保留节点标识、质量状态、源时间戳和错误阶段，并控制敏感设备信息的访问。退出时应停止订阅分派、关闭会话并释放客户端，避免重启后残留重复订阅。

源码入口：[OPC](https://github.com/Zongsoft/framework/tree/main/externals/opc)。

## 按项目继续阅读

[Opc](/framework/externals/projects/opc.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zongsoft.com/framework/externals/integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
