跳到主要内容

NuGet 预览包

当前版本是 0.1.0-preview。安装任何 Zeus 包时都要加 --prerelease

先按场景复制命令

控制台、Windows 服务、后台采集程序

dotnet add package Zeus.Communications --prerelease

Zeus.Communications 会带上宿主和核心抽象。你可以使用 ZeusHost.Create、虚拟通道、串口和 TCP。

WinForms 上位机

dotnet add package Zeus.Communications --prerelease
dotnet add package Zeus.Presentation.WinForms --prerelease

项目目标框架必须是:

<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>

WPF 上位机

dotnet add package Zeus.Communications --prerelease
dotnet add package Zeus.Presentation.Wpf --prerelease

项目目标框架必须是:

<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>

Modbus 设备

dotnet add package Zeus.Communications --prerelease
dotnet add package Zeus.Protocols.Modbus --prerelease

自定义帧协议

dotnet add package Zeus.Communications --prerelease
dotnet add package Zeus.Protocols.Framing --prerelease

JSON 配置

dotnet add package Zeus.Configuration --prerelease

通常还会同时安装 Zeus.Communications 和协议包,因为配置文件里会声明通道和设备。

包之间怎么理解

你装它是为了什么
Zeus.Hosting宿主、生命周期、采集循环。通常由其它包自动带上
Zeus.Communications串口、TCP、虚拟通道。大多数项目都需要
Zeus.Protocols.Framing处理“帧头 + 长度 + 载荷 + 校验”这类厂家私有协议
Zeus.Protocols.Modbus读写 Modbus RTU / TCP 设备
Zeus.Configurationzeus.json 读取通道、设备和采集配置
Zeus.Presentation.WinFormsWinForms 的 AttachZeusBindToBindState
Zeus.Presentation.WpfWPF 的 AttachZeusBindToAsBindingSource

Zeus.AbstractionsZeus.Presentation.Abstractions 是底层依赖,一般不用手动安装。

装好后写一段最小代码

using System.Text;
using Zeus;

await using var app = ZeusHost.Create(builder =>
{
builder.AddVirtualChannel("meter");
});

var meter = app.Channels.Get("meter");
meter.DataReceived += (_, e) => Console.WriteLine(Encoding.UTF8.GetString(e.Data.Span));

await app.StartAsync();
await meter.WriteAsync(Encoding.UTF8.GetBytes("PING"));

能输出 PING,说明包引用和基础运行环境没问题。

常见问题

现象原因处理
Unable to find package Zeus.*预览包默认不会被选择命令末尾加 --prerelease
编译时找不到 AddVirtualChannel没装 Zeus.Communications安装通信包
编译时找不到 AttachZeus没装对应 UI 包WinForms 装 Zeus.Presentation.WinForms,WPF 装 Zeus.Presentation.Wpf
桌面项目还原失败目标框架不对改成 net8.0-windows

源码见 github.com/Mokode-dev/Zeus。许可证为 MIT。