【工业自动化平台】 工程设计-项目分层目录设计(1)

【工业自动化平台】 工程设计-项目分层目录设计(1)

总想做点什么

方向:

  • UI(WPF/WinForms)
  • MVVM
  • Application只负责插件生命周期和应用协调
  • 设备Domain按插件拆分
  • Infrastructure基础服务
  • Driver底层通信驱动
  • EventBus / CommandBus / DataBus
  • Core定义契约
  • Common工具程序集

设计工程目录如下:

text 复制代码
Industrial.Platform.sln

│
├── 01.Core                         核心契约层
│   │
│   └── Platform.Core
│       │
│       ├── Interfaces              接口定义
│       │   ├── IPlugin.cs
│       │   ├── IPluginManager.cs
│       │   ├── IEventBus.cs
│       │   ├── ICommandBus.cs
│       │   ├── IDataBus.cs
│       │   ├── IRepository.cs
│       │   └── IDriver.cs
│       │
│       ├── Messages                消息契约
│       │   ├── EventMessage.cs
│       │   ├── CommandMessage.cs
│       │   └── DataMessage.cs
│       │
│       ├── Events                  系统事件
│       │   ├── DeviceStateEvent.cs
│       │   ├── AlarmEvent.cs
│       │   └── PluginStateEvent.cs
│       │
│       ├── Models                  基础模型
│       │   ├── DeviceInfo.cs
│       │   ├── PluginInfo.cs
│       │   └── StateInfo.cs
│       │
│       └── Exceptions
│
│
├── 02.Common                       通用工具层
│   │
│   └── Platform.Common
│       │
│       ├── Extensions
│       │   ├── StringExtensions.cs
│       │   └── ObjectExtensions.cs
│       │
│       ├── Helpers
│       │   ├── JsonHelper.cs
│       │   ├── ReflectionHelper.cs
│       │   └── DateTimeHelper.cs
│       │
│       ├── Serialization
│       │
│       ├── Threading
│       │
│       └── Result
│
│
├── 03.Application                  应用协调层
│   │
│   └── Platform.Application
│       │
│       ├── Services
│       │   ├── PluginApplicationService.cs
│       │   └── DeviceApplicationService.cs
│       │
│       ├── Commands
│       │
│       └── DTO
│
│
├── 04.Runtime                      平台运行时
│   │
│   └── Platform.Runtime
│       │
│       ├── PluginManager
│       │   ├── PluginLoader.cs
│       │   └── PluginContainer.cs
│       │
│       ├── ServiceManager
│       │
│       ├── AssemblyLoader
│       │
│       └── Lifecycle
│
│
├── 05.Infrastructure                基础设施层
│   │
│   └── Platform.Infrastructure
│       │
│       ├── EventBus
│       │   ├── LocalEventBus.cs
│       │   └── RabbitMQEventBus.cs
│       │
│       ├── CommandBus
│       │
│       ├── DataBus
│       │
│       ├── Persistence
│       │   ├── SQLite
│       │   ├── EFCore
│       │   └── Repository
│       │
│       ├── Logging
│       │
│       ├── Configuration
│       │
│       ├── Cache
│       │
│       └── FileStorage
│
│
├── 06.Driver                       底层驱动层
│   │
│   └── Platform.Driver
│       │
│       ├── Abstractions
│       │   ├── IPlcDriver.cs
│       │   ├── ICameraDriver.cs
│       │   └── IMotionDriver.cs
│       │
│       ├── PLC
│       │   ├── Siemens
│       │   ├── Mitsubishi
│       │   ├── Omron
│       │   └── Modbus
│       │
│       ├── Motion
│       │   ├── Servo
│       │   └── Robot
│       │
│       ├── Camera
│       │   ├── Basler
│       │   └── Hikvision
│       │
│       ├── SECS
│       │   ├── HSMS
│       │   ├── SECS-II
│       │   └── GEM
│       │
│       └── Network
│           ├── TCP
│           ├── UDP
│           └── SerialPort
│
│
├── 07.Domain.Plugin                 设备领域插件层
│   │
│   ├── Tester.Plugin
│   │   │
│   │   ├── Domain
│   │   ├── StateMachine
│   │   ├── Process
│   │   ├── Recipe
│   │   ├── Alarm
│   │   └── PluginEntry.cs
│   │
│   │
│   ├── Robot.Plugin
│   │
│   ├── SMT.Plugin
│   │
│   ├── Vision.Plugin
│   │
│   └── SECS.Plugin
│
│
├── 08.UI                            表现层
│   │
│   ├── Platform.UI.WPF
│   │   │
│   │   ├── Views
│   │   ├── Controls
│   │   ├── Themes
│   │   └── Resources
│   │
│   │
│   └── Platform.UI.WinForms
│
│
├── 09.ViewModels                    MVVM层
│   │
│   └── Platform.ViewModels
│       │
│       ├── MainViewModel.cs
│       ├── DeviceViewModel.cs
│       ├── AlarmViewModel.cs
│       └── PluginViewModel.cs
│
│
└── 10.Host                          主程序

    Platform.Client.exe

    │
    ├── Startup
    ├── DI注册
    ├── Configuration
    └── App.xaml

依赖方向

严格控制:

text 复制代码
                 Host
                  |
                  ↓

                 UI

                  |
                  ↓

             ViewModel

                  |
                  ↓

            Application

                  |
                  ↓

        Domain.Plugin

                  |
                  ↓

                 Core


Infrastructure ─────→ Core

Driver ─────────────→ Core

Runtime ────────────→ Core

Common ← 所有层引用

各层最终职责

职责 示例
Core 定义规则 IPlugin、IEventBus
Common 通用工具 Json、反射
Application 应用协调 启动插件
Runtime 运行管理 加载DLL
Infrastructure 公共能力 SQLite、日志
Driver 硬件通信 PLC、SECS
Domain.Plugin 设备大脑 状态机、工艺
ViewModel 界面逻辑 Command、Binding
UI 显示 WPF/WinForms
Host 组装启动 DI、配置

这个结构更适合你的目标:

"工业设备上位机平台化开发"

后续增加:

  • 新设备 → 新 Domain.Plugin
  • 新PLC → 新 Driver
  • 新通信 → 新 Infrastructure
  • 新界面 → 新 UI

主程序无需修改。

下面对每一层进行详细说明。

整体定位:

Host负责组装系统,Runtime负责运行插件,Application负责协调,Domain Plugin负责设备逻辑,Driver负责硬件通信,Infrastructure提供平台能力,Core定义契约。


1. Core 核心契约层

定位

Core是整个系统的公共协议层

它不包含任何业务实现,只定义:

  • 谁和谁通信
  • 模块之间遵循什么规则
  • 数据如何传递

类似操作系统的 API 定义。


主要内容

项目:

复制代码
Platform.Core

结构:

复制代码
Core

├── Interfaces
├── Messages
├── Events
├── Commands
├── Models
└── Exceptions

1.1 Interfaces(接口)

定义系统能力。

例如插件:

csharp 复制代码
public interface IPlugin
{
    string Id { get; }

    string Name { get; }


    Task InitializeAsync();

    Task StartAsync();

    Task StopAsync();

}

所有设备插件实现:

复制代码
PLC.Plugin
Robot.Plugin
Vision.Plugin

1.2 EventBus接口

csharp 复制代码
public interface IEventBus
{

    void Publish<T>(T message);


    void Subscribe<T>(
        Action<T> handler);

}

Core只定义:

"有消息机制"

不关心:

  • 内存事件
  • RabbitMQ
  • MQTT

1.3 Driver接口

例如:

csharp 复制代码
public interface IPlcDriver
{

    Task Connect();

    Task Disconnect();


    Task Write(
        string address,
        object value);

}

实现:

复制代码
SiemensDriver

MitsubishiDriver

1.4 消息模型

例如:

设备状态:

csharp 复制代码
public class DeviceStateChangedEvent
{
    public string DeviceId {get;set;}

    public string State {get;set;}
}

用于:

复制代码
PLC Plugin

发布

↓

UI显示

2. Common 通用工具层

定位

开发辅助库。

原则:

谁都可以使用,但不能包含业务。


项目:

复制代码
Platform.Common

内容:

2.1 扩展方法

例如:

csharp 复制代码
public static class StringExtensions
{

    public static bool IsNull(
        this string value)
    {
        return string.IsNullOrEmpty(value);
    }

}

2.2 序列化

例如:

复制代码
JsonHelper
XmlHelper
BinarySerializer

用途:

  • 配置文件
  • 通信数据
  • 缓存

2.3 反射工具

插件加载:

csharp 复制代码
AssemblyHelper.Load()

用于:

复制代码
扫描Plugins目录

加载DLL

2.4 Result统一返回

csharp 复制代码
Result<T>

统一:

复制代码
成功
失败
错误信息
数据

3. Application 应用协调层

定位

Application不是设备业务。

你的设计:

只负责插件开启、关闭、协调。


项目:

复制代码
Platform.Application

职责:

3.1 插件管理调用

例如:

用户:

复制代码
点击启动设备

流程:

复制代码
ViewModel

↓

ApplicationService

↓

PluginManager

↓

Plugin.Start()

代码:

csharp 复制代码
public class PluginApplicationService
{

    private readonly IPluginManager manager;


    public Task Start(
        string plugin)
    {
        return manager.Start(plugin);
    }

}

3.2 应用状态管理

例如:

复制代码
系统启动

插件加载

插件运行

插件停止

3.3 不包含:

❌ PLC逻辑

❌ Recipe流程

❌ 设备状态机

这些属于 Domain Plugin。


4. Runtime 运行时层

定位

整个软件的"操作系统"。

负责:

  • DLL加载
  • 插件生命周期
  • DI容器
  • 服务管理

项目:

复制代码
Platform.Runtime

4.1 PluginManager

核心:

csharp 复制代码
public class PluginManager
{

    Load();

    Start();

    Stop();

}

流程:

复制代码
启动程序

↓

扫描 Plugins

↓

找到 xxx.Plugin.dll

↓

反射创建对象

↓

注册DI

↓

启动插件

4.2 AssemblyLoader

负责:

复制代码
Assembly.Load()

支持:

  • 动态加载
  • 插件隔离
  • 升级

5. Infrastructure 基础设施层

定位

提供技术能力。

不包含设备业务。


项目:

复制代码
Platform.Infrastructure

5.1 EventBus实现

Core:

复制代码
IEventBus

Infrastructure:

复制代码
LocalEventBus
RabbitMQEventBus

例如:

单机:

复制代码
内存事件

分布式:

复制代码
RabbitMQ

5.2 SQLite

负责:

  • 数据保存
  • 查询
  • ORM

例如:

保存:

复制代码
报警记录

运行日志

Recipe参数

结构:

复制代码
Persistence

├── DbContext

├── Repository

└── Migration

5.3 Logger

例如:

复制代码
Serilog
NLog

统一:

复制代码
Debug
Info
Error

5.4 Configuration

负责:

复制代码
设备配置

系统配置

插件配置

例如:

json 复制代码
{
 "PLC":
 {
   "IP":"192.168.1.10"
 }
}

6. Driver 驱动层

定位

连接真实硬件。

属于:

软件到设备的最后一公里。


项目:

复制代码
Platform.Driver

PLC

结构:

复制代码
Driver.PLC

├── Siemens

├── Mitsubishi

├── Omron

└── Modbus

负责:

复制代码
TCP

协议

数据转换

读写

Camera

例如:

复制代码
Basler SDK

Hikvision SDK

Cognex SDK

Motion

例如:

复制代码
Servo

Robot

Axis

SECS

拆分:

复制代码
HSMS

SECS-II

GEM

7. Domain.Plugin 设备领域插件层

定位

这是设备的"大脑"。

每一种设备一个插件。


例如:

复制代码
Tester.Plugin.dll
Robot.Plugin.dll

内部:

复制代码
Tester.Plugin

├── Domain

├── StateMachine

├── Process

├── Recipe

├── Alarm

└── PluginEntry

Domain

定义:

设备对象:

复制代码
Tester

Wafer

Carrier

StateMachine

例如:

复制代码
Idle

 ↓

Ready

 ↓

Run

 ↓

Complete

 ↓

Error

Process

工艺流程:

例如:

复制代码
Load

Align

Test

Unload

Recipe

参数:

复制代码
温度

速度

时间

8. ViewModel层

定位

MVVM中的VM。

连接:

复制代码
UI

↓

ViewModel

↓

Application

负责:

  • 数据绑定
  • Command
  • UI状态

例如:

csharp 复制代码
StartCommand
StopCommand
ResetCommand

不负责:

❌ PLC通信

❌ 数据库

❌ 设备控制


9. UI层

定位

显示。

支持:

复制代码
WPF

WinForms

负责:

  • 页面
  • 控件
  • 样式
  • 用户操作

不包含:

复制代码
业务代码
PLC代码
数据库代码

10. Host主程序

定位

系统入口。

负责:

启动所有模块。


流程:

复制代码
Main()

↓

创建DI

↓

加载配置

↓

初始化Runtime

↓

加载插件

↓

显示UI

最终数据流

控制流

复制代码
用户

↓

UI

↓

ViewModel

↓

Application

↓

Runtime

↓

Domain Plugin

↓

Driver

↓

设备

状态流

复制代码
设备

↓

Driver

↓

Domain Plugin

↓

EventBus

↓

ViewModel

↓

UI

数据保存

复制代码
设备

↓

Plugin

↓

Repository

↓

SQLite

最终架构定位总结

一句话
Core 定义规则
Common 提供工具
UI 显示界面
ViewModel 连接界面和系统
Application 协调应用
Runtime 管理插件运行
Domain Plugin 设备大脑
Infrastructure 提供平台能力
Driver 连接硬件
Host 启动系统

这个分层适合构建 EAP、SCADA、半导体设备控制软件、智能制造上位机平台

相关推荐
DeepVisionary6 小时前
从 Qwen3.8-27B 把原生多模态、原生 FP8、桌面级 Agent 三件事一次集齐,看开源大模型的“工业化拐点“
python·自动化
接口不宕机7 小时前
外贸公司实战:利用 1688API 自动化监控竞品价格,解决采购定价痛点
运维·自动化
其实防守也摸鱼10 小时前
接口审计:从原理到实践的万字深度指南
数据库·安全·自动化·github·copilot
环境栈笔记11 小时前
指纹浏览器怎么选?从 Profile、代理、权限和自动化能力判断是否适合
前端·人工智能·后端·自动化
画中有画16 小时前
自动化脚本中如何启动/打开app的某个页面
运维·自动化
酷可达拉斯19 小时前
自动化运维-Ansible Role综合应用案例-基于LNMP部署wordpress
linux·运维·服务器·自动化·ansible
宝桥南山1 天前
Blazor Web Assembly - 体验一下Authentication State从Server共享给Client
microsoft·微软·c#·asp.net·.net·.netcore
疯狂的维修1 天前
PDPS关于cable的设定
自动化
云飞云共享云桌面2 天前
苏州昆山精密机械加工厂研发部门10个SolidWorks可以部署云飞云共享云桌面吗?
大数据·运维·服务器·自动化·汽车·制造
云飞云共享云桌面2 天前
自动化设备厂 10 人研发团队,如何共用一台服务器做 SolidWorks 建模?
运维·服务器·网络·3d·自动化·制造