ThingsGatewayRuntime.Foundation
2.2.13
dotnet add package ThingsGatewayRuntime.Foundation --version 2.2.13
NuGet\Install-Package ThingsGatewayRuntime.Foundation -Version 2.2.13
<PackageReference Include="ThingsGatewayRuntime.Foundation" Version="2.2.13" />
<PackageVersion Include="ThingsGatewayRuntime.Foundation" Version="2.2.13" />
<PackageReference Include="ThingsGatewayRuntime.Foundation" />
paket add ThingsGatewayRuntime.Foundation --version 2.2.13
#r "nuget: ThingsGatewayRuntime.Foundation, 2.2.13"
#:package ThingsGatewayRuntime.Foundation@2.2.13
#addin nuget:?package=ThingsGatewayRuntime.Foundation&version=2.2.13
#tool nuget:?package=ThingsGatewayRuntime.Foundation&version=2.2.13
ThingsGatewayRuntime
ThingsGatewayRuntime 是 ThingsGateway 的工业物联网边缘网关运行时,负责设备采集、变量计算、数据转发、历史数据、实时报警、规则引擎和 Web 管理。
项目组成
| 模块 | 路径 | 说明 |
|---|---|---|
| 运行时宿主 | src/ThingsGatewayRuntime |
配置加载、应用启动和进程入口 |
| 应用核心 | src/ThingsGatewayRuntime.Application |
通道、设备、变量、报警、历史数据、规则引擎和管理 API |
| 驱动基础 | src/ThingsGatewayRuntime.Foundation |
通信通道、设备抽象、数据转换和驱动基础设施 |
| 内置插件 | src/ThingsGatewayRuntime.Plugin |
可用于常规运行环境的采集与业务插件 |
| 非 AOT 插件 | src/ThingsGatewayRuntime.NOAOTPlugin |
OPC 等依赖动态能力的插件 |
| 前端资源 | src/ThingsGatewayRuntime.Frontend |
嵌入运行时的 Web 静态资源 |
| 脚本编译器 | src/ThingsGatewayScriptCompiler |
脚本和表达式编译支持 |
| 源生成器 | analyzer |
表达式和插件注册代码生成 |
| Bootstrapper | src/Bootstrapper |
.NET 10 离线环境检测、安装和应用启动 |
| Web 前端 | web |
Vue 3 网关管理界面 |
| 自动化测试 | test/ThingsGatewayRuntime.Test |
核心运行时、驱动、规则和安全测试 |
功能特性
- 通道、设备、变量的统一建模、批量配置、状态监控和在线调试。
- Modbus、Siemens S7、DL/T 645、MQTT、OPC UA/DA 等内置协议,扩展协议由插件项目提供。
- 实时数据缓存、变量读写、WebSocket 推送和网关间同步。
- 历史数据与历史报警查询、实时报警、确认和配置管理。
- 采集驱动与业务插件生命周期、动态属性和权限元数据。
- 数据转发到 MQTT、RabbitMQ、Kafka、数据库、HTTP 等目标。
- 可视化规则流、自定义节点、运行时脚本和表达式。
- 工程备份恢复、冗余管理、健康检查、日志、审计和 TAdmin 权限体系。
历史数据数据库矩阵
历史数据转发与查询覆盖 SQLite、SQL Server、MySQL、PostgreSQL、QuestDB、TDengine 和 IoTDB。当前浏览器验收矩阵包含 22 个相互隔离的目标:8 个普通目标、7 个显式自定义 SQL 目标,以及 7 个开启自定义 SQL但建表、插入、删除模板全部留空的自动生成目标。
| 数据库 | 普通模式 | 显式自定义 SQL | 空 SQL 自动生成 | 隔离方式 |
|---|---|---|---|---|
| SQLite | 1 | 1 | 1 | 独立数据库文件 |
| SQL Server | 1 | 1 | 1 | 独立数据库 |
| MySQL | 1 | 1 | 1 | 独立数据库 |
| PostgreSQL | 1 | 1 | 1 | 独立数据库 |
| QuestDB | 1 | 1 | 1 | 独立表名;QuestDB 没有多数据库命名空间 |
| TDengine | 1 | 1 | 1 | 独立数据库 |
| IoTDB Table | 1 | 1 | 1 | Table 模型支持自定义 SQL |
| IoTDB Tree | 1 | 0 | 0 | Tree 模型只使用普通历史查询 |
数据查询页遵循以下契约:
- 普通模式返回设备名称、变量名称、变量 ID、值、采集时间、在线状态、记录时间、源 Epoch、源序列、源节点和记录键。没有冗余来源元数据时,源节点与记录键为空;其余字段必须有值。
- 通用自定义宽表返回
event_time、main_value、copy_value和device_name;IoTDB 自动表额外返回group_key,IoTDB 显式自定义表返回time、device_id、variable_id、variable_name、value和is_online。 - 普通模式按变量写入记录,两个变量通常每周期产生两行;合并宽表通常每周期产生一行,因此两种模式的累计总数不要求相同。分页栏中的
50条/页是当前分页大小,总数以“共 N 条”为准。 - 切换查询目标时必须清空上一目标的分页排序字段并重建表格排序状态,不能把普通表的
createTime排序带入使用event_time或time的自定义表。 - 普通模式的 IoTDB 与 QuestDB 原生 UTC 时间在服务端按目标配置时区投影为墙钟时间;例如目标配置
+08:00时,UTC09:42Z在普通表显示为17:42。IoTDB 与 QuestDB 自定义宽表保留原始Z后缀,明确表示 UTC。 - QuestDB 普通查询必须应用页面传入的条件和排序;按记录时间降序时使用
CreateTime DESC,不能退回到可能长期不变的CollectTime。
2026-08-30 使用 Asia/Shanghai 浏览器时区完成 22 个目标的实际 UI 验收:所有目标均返回 50 行;宽表最新行的两个数值均为 42.5、设备名称为 Memory 且没有空字段;普通表除源节点和记录键外字段完整。修复后 IoTDB Table、IoTDB Tree 和 QuestDB Normal 的最新记录时间分别与本地当前时间一致,IoTDB/QuestDB 宽表仍返回带 Z 的 UTC 时间。
技术栈
| 技术 | 当前配置 | 用途 |
|---|---|---|
| .NET | net10.0 |
后端运行时和测试 |
| TouchSocket | 4.3.0 |
TCP、UDP、串口、MQTT、WebApi 和 WebSocket |
| TAdmin | 2.1.12 |
用户、角色、权限、认证和审计 |
| TUtility | 2.0.55 |
应用启动与通用基础能力 |
| TORM | 2.0.54 |
运行时数据库访问 |
| Vue | 3.5.x |
Web 管理界面 |
| TypeScript | 6.0.x |
前端类型系统 |
| Element Plus | 2.14.x |
前端组件库 |
| Vite | 8.0.x |
前端开发和构建 |
目录结构
ThingsGatewayRuntime/
|-- analyzer/
| |-- ThingsGatewayRuntime.ExpressionsGenerator/
| `-- ThingsGatewayRuntime.PluginsGenerator/
|-- src/
| |-- Bootstrapper/
| |-- ThingsGatewayRuntime/
| |-- ThingsGatewayRuntime.Application/
| |-- ThingsGatewayRuntime.Foundation/
| |-- ThingsGatewayRuntime.Frontend/
| |-- ThingsGatewayRuntime.Plugin/
| |-- ThingsGatewayRuntime.NOAOTFoundation/
| |-- ThingsGatewayRuntime.NOAOTPlugin/
| `-- ThingsGatewayScriptCompiler/
|-- test/ThingsGatewayRuntime.Test/
|-- web/
|-- Directory.Build.props
`-- README.md
开发环境
- .NET SDK 10
- Node.js 22 和 npm
- 仓库工作区构建时使用同级
TAdmin、TUtility和TORM源码;单独使用项目时改用对应 NuGet 包。
构建
从 ThingsGateway 目录构建包含 Runtime、PRO 和 Studio 的解决方案:
dotnet restore ThingsGatewayRuntime.slnx
dotnet build ThingsGatewayRuntime.slnx -c Release
只构建运行时:
dotnet build ThingsGatewayRuntime/src/ThingsGatewayRuntime/ThingsGatewayRuntime.csproj -c Release
运行测试:
dotnet test ThingsGatewayRuntime/test/ThingsGatewayRuntime.Test/ThingsGatewayRuntime.Test.csproj -c Release
前端开发
cd web
npm install
npm run dev
开发服务器默认使用 http://localhost:3100。构建生产资源:
npm run check
npm run build
npm run build 会执行类型检查、生成静态资源,并把资源复制到 ThingsGatewayRuntime.Frontend 的嵌入目录。
运行
先构建前端资源,再启动后端:
dotnet run --project src/ThingsGatewayRuntime/ThingsGatewayRuntime.csproj
默认 WebApi 端口为 6100。运行目录下的 Configuration 用于数据库、JWT、OAuth2、日志、历史查询和 WebApi 配置;默认 SQLite 连接启用 WAL 日志模式。
扩展开发
- 采集插件、业务插件和属性元数据开发参见 插件二次开发。
- 运行时脚本、表达式和自定义节点文档位于 官方文档站点源码。
- Studio 与 Watchdog 的工程开发和部署说明参见 ThingsGatewayStudio。
相关资源
- 官方文档:https://runtime.thingsgateway.cn/
- Gitee:https://gitee.com/diego2098/ThingsGateway
- GitHub:https://github.com/kimdiego2098/ThingsGateway
- QQ 群:605534569
许可证
本项目使用 Apache-2.0 协议。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- OPCFoundation.NetStandard.Opc.Ua.Client.ComplexTypes (>= 2.0.0-preview.3)
- TouchSocket (>= 4.3.4)
- TouchSocket.SerialPorts (>= 4.3.4)
- TUtility.App (>= 2.0.68)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ThingsGatewayRuntime.Foundation:
| Package | Downloads |
|---|---|
|
ThingsGatewayRuntime.Application
Package Description |
|
|
ThingsGatewayRuntime.NOAOTFoundation
Package Description |
|
|
ThingsGatewayRuntime.NOAOTPROFoundation
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.2.13 | 0 | 8/30/2026 |
| 2.2.10 | 45 | 8/29/2026 |
| 2.2.8 | 44 | 8/29/2026 |
| 2.2.7 | 79 | 8/25/2026 |
| 2.2.6 | 137 | 8/21/2026 |
| 2.2.5 | 132 | 8/21/2026 |
| 2.2.4 | 139 | 8/20/2026 |
| 2.2.3 | 130 | 8/20/2026 |
| 2.2.2 | 138 | 8/19/2026 |
| 2.1.44 | 139 | 8/17/2026 |
| 2.1.43 | 125 | 8/15/2026 |
| 2.1.42 | 117 | 8/11/2026 |
| 2.1.40 | 115 | 8/11/2026 |
| 2.1.39 | 141 | 8/9/2026 |
| 2.1.38 | 143 | 8/4/2026 |
| 2.1.37 | 140 | 8/3/2026 |
| 2.1.36 | 164 | 7/31/2026 |
| 2.1.34 | 143 | 7/27/2026 |
| 2.1.33 | 148 | 7/25/2026 |
| 2.1.32 | 166 | 7/23/2026 |