跳到主要内容

JSON 配置

JSON 配置适合现场交付:端口号、从站地址、点表和采集间隔放在文件里,现场人员改配置,不需要重新编译程序。

最小配置文件​

zeus.json:

{
"$schema": "https://docs.greekmythology.cn/schemas/zeus.json",
"acquisition": {
"intervalMilliseconds": 500,
"pollImmediately": true
},
"channels": [
{
"name": "bus",
"type": "serial",
"options": {
"portName": "COM3",
"baudRate": 9600
}
}
],
"devices": [
{
"name": "oven",
"channel": "bus",
"type": "modbus-rtu",
"options": {
"unitId": 1
},
"points": [
{
"name": "temperature",
"options": {
"table": "holding",
"address": 0,
"scale": 0.1,
"lowAlarmLimit": 10,
"highAlarmLimit": 80
}
},
{
"name": "setpoint",
"options": {
"table": "holding",
"address": 1,
"scale": 0.1,
"writable": true
}
}
]
}
]
}

程序里读取:

await using var app = ZeusHost.Create(builder => builder.AddJsonFile("zeus.json"));
await app.StartAsync();

var temperature = app.Points.Get<double>("temperature");

配置文件怎么读​

文件头建议保留 $schema,VS / VS Code 会据此补全通道类型、设备类型、点字段以及常见枚举值。schema 地址是:

"$schema": "https://docs.greekmythology.cn/schemas/zeus.json"
区域含义
acquisition采集间隔和是否启动后立刻采集
reconnect通道故障后的自动重连、退避、抖动、最大尝试次数和熔断等待
channels通信线路,例如串口、TCP、UDP、虚拟通道
devices设备,例如 Modbus RTU / TCP / ASCII、Mitsubishi MC、Siemens S7、Omron FINS、Omron Host Link、Panasonic MEWTOCOL、EtherNet/IP、DL/T 645、IEC104、MQTT 或 SNMP 设备
points设备上的业务点,例如温度、设定值、加热输出

设备里的 channel 必须引用已经在 channels 中声明过的通道名。

从当前配置格式开始,通道、设备和点位根层只放结构字段;串口参数、协议参数、地址、缩放、写回、报警限等都放进各自的 options。旧写法例如在点根层直接写 address / writable,或在通道根层直接写 host / portName,会在装载时失败。

没硬件时用虚拟配置​

把串口通道换成虚拟 Modbus 从站:

{
"name": "bus",
"type": "virtual",
"options": {
"responder": "modbus",
"unitId": 1,
"transport": "rtu"
}
}

options.transport 可设为 rtu、tcp 或 ascii,用于匹配主站封装。这样可以先验证点表、采集和界面绑定。接真实设备时再改回:

{
"name": "bus",
"type": "serial",
"options": {
"portName": "COM3",
"baudRate": 9600
}
}

通道字段​

根字段含义
nameZeus 通道名,例如 bus
typevirtual / serial / tcp / tcp-server / udp / udp-server
startup启动失败策略:required 为默认值,通道打开失败时宿主启动失败;optional / degraded 允许宿主先启动,故障通道交给自动重连恢复
options通道参数和虚拟从站参数。核心配置保留该对象,并把它纳入热更新指纹

常用 channels[].options:

options 字段适用类型含义
portName / baudRateserialWindows COM 口与波特率。校验位、数据位、停止位请用代码 AddSerialPort(name, options => …) 设置
host / porttcp / udp对端 IP 或主机名与端口
localAddress / localPorttcp-server / udp-server本地监听地址与端口;udp 可用 localPort 指定本地绑定端口,0 表示自动分配
respondervirtualmodbus / mc / s7 / fins / host-link / mewtocol / ethernet-ip / dlt645 / iec104 / mqtt / opcua / snmp
transportvirtual虚拟 Modbus 从站可选 rtu / tcp / ascii;虚拟 FINS 从站可选 udp / tcp
meterAddressvirtual + dlt645DL/T 645 虚拟表计地址,12 位十进制字符串
commonAddressvirtual + iec104IEC104 虚拟站公共地址,默认 1
snmpCommunity / snmpWriteCommunityvirtual + snmpSNMP 虚拟 Agent 的读写 community,省略写 community 时沿用读 community
opcUaUsername / opcUaPasswordvirtual + opcuaOPC UA 虚拟 Server 的可选用户名密码;省略时接受匿名登录

设备字段​

根字段含义
nameZeus 设备名,例如 oven
channel要使用的通道名,例如 bus
typemodbus-rtu / modbus-tcp / modbus-ascii / mitsubishi-mc / siemens-s7 / omron-fins / omron-host-link / panasonic-mewtocol / ethernet-ip / dlt645 / iec104 / mqtt / opcua / snmp
options协议参数。核心配置保留并纳入设备热更新指纹
points要周期采集的点

常用 devices[].options:

options 字段含义
transportFINS 线上封装,udp / tcp,默认 udp
unitIdModbus 从站地址或 TCP 单元标识;Host Link 使用 0-31 单元号;MEWTOCOL 使用 1-99 站号
frameType / encodingMC 帧类型与编码
MC 路由字段networkNumber / pcNumber / ioNumber / stationNumber / monitoringTimer / serialNumber
rack / slot / localTsap / remoteTsap / requestedPduLengthS7 连接参数
FINS 路由字段destinationNetwork / destinationNode / destinationUnit / sourceNetwork / sourceNode / sourceUnit / gatewayCount / informationControlField / tcpRequestedClientNode / useTcpNodeAddressHandshake
wordOrderFINS / Host Link / MEWTOCOL 32 位值字序,high-word-first / low-word-first
meterAddress / wakeUpPreambleCount / password / operatorCodeDL/T 645 表地址、唤醒前导和写数据参数
commonAddress / originatorAddress / interrogationQualifierIEC104 公共地址和总召唤参数
MQTT 连接字段mqttClientId、认证、保活、Clean Session、遗嘱、最大报文、自动保活和自动重连参数
SNMP 字段snmpCommunity / snmpWriteCommunity / snmpInitialRequestId
OPC UA 字段opcUaEndpointUrl / opcUaApplicationUri / opcUaApplicationName / opcUaSessionName / opcUaRequestedSessionTimeout / opcUaUsername / opcUaPassword / opcUaAutomaticReconnect

points 会接入周期采集;标为 options.writable: true 的可写点可以通过 app.Points.WriteAsync(...) 按点名下发。

Mitsubishi MC 配置示例​

真实 PLC:

{
"channels": [
{
"name": "plc-link",
"type": "tcp",
"options": {
"host": "192.168.1.10",
"port": 5000
}
}
],
"devices": [
{
"name": "plc",
"channel": "plc-link",
"type": "mitsubishi-mc",
"options": {
"frameType": "4e",
"encoding": "ascii",
"serialNumber": 1,
"networkNumber": 0,
"pcNumber": 255,
"ioNumber": 1023,
"stationNumber": 0,
"monitoringTimer": 16
},
"points": [
{
"name": "temperature",
"options": {
"deviceCode": "D",
"address": 100,
"scale": 0.1,
"writable": true
}
},
{
"name": "run",
"options": {
"deviceCode": "M",
"address": 10,
"writable": true
}
},
{
"name": "ready",
"options": {
"deviceCode": "X",
"address": "0x10"
}
},
{
"name": "recipe",
"options": {
"deviceCode": "ZR",
"address": 0
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "plc-link",
"type": "virtual",
"options": {
"responder": "mc"
}
}
],
"devices": [
{
"name": "plc",
"channel": "plc-link",
"type": "mitsubishi-mc",
"options": {
"frameType": "3e",
"encoding": "binary"
},
"points": [
{
"name": "temperature",
"options": {
"deviceCode": "D",
"address": 100,
"scale": 0.1
}
},
{
"name": "run",
"options": {
"deviceCode": "M",
"address": 10
}
}
]
}
]
}

Siemens S7 配置示例​

真实 PLC:

{
"channels": [
{
"name": "plc-link",
"type": "tcp",
"options": {
"host": "192.168.1.10",
"port": 102
}
}
],
"devices": [
{
"name": "plc",
"channel": "plc-link",
"type": "siemens-s7",
"options": {
"rack": 0,
"slot": 1
},
"points": [
{
"name": "temperature",
"options": {
"area": "db",
"db": 1,
"address": 0,
"dataType": "real"
}
},
{
"name": "setpoint",
"options": {
"area": "db",
"db": 1,
"address": 4,
"dataType": "int",
"scale": 0.1,
"writable": true
}
},
{
"name": "running",
"options": {
"area": "m",
"address": 10,
"bit": 0,
"dataType": "bool",
"writable": true
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "plc-link",
"type": "virtual",
"options": {
"responder": "s7"
}
}
],
"devices": [
{
"name": "plc",
"channel": "plc-link",
"type": "siemens-s7",
"points": [
{
"name": "temperature",
"options": {
"area": "db",
"db": 1,
"address": 0,
"dataType": "real"
}
}
]
}
]
}

Omron FINS 配置示例​

真实 PLC:

{
"channels": [
{
"name": "fins-link",
"type": "udp",
"options": {
"host": "192.168.250.1",
"port": 9600
}
}
],
"devices": [
{
"name": "plc",
"channel": "fins-link",
"type": "omron-fins",
"options": {
"transport": "udp",
"sourceNode": 10,
"destinationNode": 1
},
"points": [
{
"name": "temperature",
"options": {
"area": "dm",
"address": 100,
"dataType": "word",
"scale": 0.1,
"writable": true
}
},
{
"name": "running",
"options": {
"area": "cio",
"address": 10,
"bit": 0,
"dataType": "bit",
"writable": true
}
},
{
"name": "flow",
"options": {
"area": "dm",
"address": 120,
"dataType": "real"
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "fins-link",
"type": "virtual",
"options": {
"responder": "fins",
"transport": "udp"
}
}
],
"devices": [
{
"name": "plc",
"channel": "fins-link",
"type": "omron-fins",
"options": {
"transport": "udp",
"sourceNode": 10,
"destinationNode": 1
},
"points": [
{
"name": "temperature",
"options": {
"area": "dm",
"address": 100,
"dataType": "word",
"scale": 0.1
}
}
]
}
]
}

可直接复制的 FINS UDP / TCP 现场配置样例位于 samples/Zeus.Samples.Console.Config/zeus-fins-udp.json 和 samples/Zeus.Samples.Console.Config/zeus-fins-tcp.json。

真实 PLC 串口:

{
"channels": [
{
"name": "host-link",
"type": "serial",
"options": {
"portName": "COM3",
"baudRate": 9600
}
}
],
"devices": [
{
"name": "plc",
"channel": "host-link",
"type": "omron-host-link",
"options": {
"unitId": 0
},
"points": [
{
"name": "temperature",
"options": {
"area": "dm",
"address": 100,
"dataType": "word",
"scale": 0.1,
"writable": true
}
},
{
"name": "running",
"options": {
"area": "cio",
"address": 10,
"bit": 0,
"dataType": "bit",
"writable": true
}
},
{
"name": "flow",
"options": {
"area": "dm",
"address": 120,
"dataType": "real"
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "host-link",
"type": "virtual",
"options": {
"responder": "host-link",
"unitId": 0
}
}
],
"devices": [
{
"name": "plc",
"channel": "host-link",
"type": "omron-host-link",
"options": {
"unitId": 0
},
"points": [
{
"name": "temperature",
"options": {
"area": "dm",
"address": 100,
"dataType": "word",
"scale": 0.1
}
}
]
}
]
}

可直接复制的 Host Link 串口配置样例位于 samples/Zeus.Samples.Console.Config/zeus-host-link.json。

Panasonic MEWTOCOL 配置示例​

真实 PLC 串口:

{
"channels": [
{
"name": "mewtocol",
"type": "serial",
"options": {
"portName": "COM3",
"baudRate": 9600
}
}
],
"devices": [
{
"name": "plc",
"channel": "mewtocol",
"type": "panasonic-mewtocol",
"options": {
"unitId": 1
},
"points": [
{
"name": "temperature",
"options": {
"area": "dt",
"address": 100,
"dataType": "word",
"scale": 0.1,
"writable": true
}
},
{
"name": "running",
"options": {
"area": "r",
"address": 10,
"bit": 0,
"dataType": "bit",
"writable": true
}
},
{
"name": "flow",
"options": {
"area": "dt",
"address": 120,
"dataType": "real"
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "mewtocol",
"type": "virtual",
"options": {
"responder": "mewtocol",
"unitId": 1
}
}
],
"devices": [
{
"name": "plc",
"channel": "mewtocol",
"type": "panasonic-mewtocol",
"options": {
"unitId": 1
},
"points": [
{
"name": "temperature",
"options": {
"area": "dt",
"address": 100,
"dataType": "word",
"scale": 0.1
}
}
]
}
]
}

可直接复制的 MEWTOCOL 串口配置样例位于 samples/Zeus.Samples.Console.Config/zeus-mewtocol.json。

Allen-Bradley EtherNet/IP 配置示例​

真实 PLC:

{
"channels": [
{
"name": "enip-link",
"type": "tcp",
"options": {
"host": "192.168.1.10",
"port": 44818
}
}
],
"devices": [
{
"name": "plc",
"channel": "enip-link",
"type": "ethernet-ip",
"points": [
{
"name": "temperature",
"options": {
"tag": "Temperature",
"dataType": "int",
"scale": 0.1,
"writable": true
}
},
{
"name": "running",
"options": {
"tag": "Running",
"dataType": "bool",
"writable": true
}
},
{
"name": "speed",
"options": {
"tag": "Program:Main.Speed",
"dataType": "dint"
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "enip-link",
"type": "virtual",
"options": {
"responder": "ethernet-ip"
}
}
],
"devices": [
{
"name": "plc",
"channel": "enip-link",
"type": "ethernet-ip",
"points": [
{
"name": "temperature",
"options": {
"tag": "Temperature",
"dataType": "int",
"scale": 0.1
}
}
]
}
]
}

默认虚拟 EtherNet/IP PLC 会预置 Temperature、Running 和 Program:Main.Speed 三个演示标签,方便先验证配置、采集和写回链路。

可直接复制的 EtherNet/IP 配置样例位于 samples/Zeus.Samples.Console.Config/zeus-ethernet-ip.json。

DL/T 645 配置示例​

真实电能表串口:

{
"channels": [
{
"name": "meter-link",
"type": "serial",
"options": {
"portName": "COM3",
"baudRate": 2400
}
}
],
"devices": [
{
"name": "meter",
"channel": "meter-link",
"type": "dlt645",
"options": {
"meterAddress": "000000000001",
"wakeUpPreambleCount": 4
},
"points": [
{
"name": "energy",
"options": {
"address": "0x00000000",
"dataType": "bcd",
"dataLength": 4,
"scale": 0.01
}
},
{
"name": "voltageA",
"options": {
"address": "0x02010100",
"dataType": "bcd",
"dataLength": 2,
"scale": 0.1
}
},
{
"name": "status",
"options": {
"address": "0x04000401",
"dataType": "raw",
"dataLength": 1
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "meter-link",
"type": "virtual",
"options": {
"responder": "dlt645",
"meterAddress": "000000000001"
}
}
],
"devices": [
{
"name": "meter",
"channel": "meter-link",
"type": "dlt645",
"options": {
"meterAddress": "000000000001",
"wakeUpPreambleCount": 0
},
"points": [
{
"name": "energy",
"options": {
"address": "0x00000000",
"dataType": "bcd",
"dataLength": 4,
"scale": 0.01
}
}
]
}
]
}

可直接复制的 DL/T 645 配置样例位于 samples/Zeus.Samples.Console.Config/zeus-dlt645.json。

IEC104 配置示例​

真实站端 TCP:

{
"channels": [
{
"name": "iec-link",
"type": "tcp",
"options": {
"host": "192.168.1.20",
"port": 2404
}
}
],
"devices": [
{
"name": "station",
"channel": "iec-link",
"type": "iec104",
"options": {
"commonAddress": 7
},
"points": [
{
"name": "running",
"options": {
"address": 1,
"dataType": "single-point",
"writable": true
}
},
{
"name": "temperature",
"options": {
"address": 100,
"dataType": "scaled",
"scale": 0.1,
"writable": true
}
},
{
"name": "pressure",
"options": {
"address": 200,
"dataType": "short-float"
}
}
]
}
]
}

无硬件联调:

{
"channels": [
{
"name": "iec-link",
"type": "virtual",
"options": {
"responder": "iec104",
"commonAddress": 7
}
}
],
"devices": [
{
"name": "station",
"channel": "iec-link",
"type": "iec104",
"options": {
"commonAddress": 7
},
"points": [
{
"name": "running",
"options": {
"address": 1,
"dataType": "single-point",
"writable": true
}
},
{
"name": "temperature",
"options": {
"address": 100,
"dataType": "scaled",
"scale": 0.1,
"writable": true
}
},
{
"name": "pressure",
"options": {
"address": 200,
"dataType": "short-float"
}
}
]
}
]
}

IEC104 点的 address 表示三字节 IOA;single-point 使用单点命令写回,normalized / scaled / short-float 使用对应设点命令写回。

可直接复制的 IEC104 配置样例位于 samples/Zeus.Samples.Console.Config/zeus-iec104.json。

MQTT 配置示例​

{
"acquisition": {
"intervalMilliseconds": 500,
"pollImmediately": true
},
"channels": [
{
"name": "mqtt-link",
"type": "virtual",
"options": {
"responder": "mqtt"
}
}
],
"devices": [
{
"name": "gateway",
"channel": "mqtt-link",
"type": "mqtt",
"options": {
"mqttClientId": "zeus-gateway",
"mqttKeepAliveSeconds": 60
},
"points": [
{
"name": "temperature",
"options": {
"topic": "factory/temperature",
"dataType": "double",
"mqttQos": "1",
"mqttRetain": true
}
},
{
"name": "running",
"options": {
"topic": "factory/running",
"dataType": "boolean"
}
},
{
"name": "setpoint",
"options": {
"topic": "factory/setpoint",
"dataType": "double",
"writable": true
}
}
]
}
]
}

接真实 Broker 时把虚拟通道改为 TCP 通道,例如 { "name": "mqtt-link", "type": "tcp", "options": { "host": "192.168.1.20", "port": 1883 } }。完整说明见 MQTT。

SNMP 配置示例​

{
"acquisition": {
"intervalMilliseconds": 500,
"pollImmediately": true
},
"channels": [
{
"name": "snmp-link",
"type": "virtual",
"options": {
"responder": "snmp"
}
}
],
"devices": [
{
"name": "agent",
"channel": "snmp-link",
"type": "snmp",
"options": {
"snmpCommunity": "public"
},
"points": [
{
"name": "sysName",
"options": {
"oid": "1.3.6.1.2.1.1.5.0",
"dataType": "text",
"writable": true
}
},
{
"name": "sysUpTime",
"options": {
"oid": "1.3.6.1.2.1.1.3.0",
"dataType": "timeticks",
"scale": 0.01
}
}
]
}
]
}

接真实 Agent 时把虚拟通道改为 UDP 通道,例如 { "name": "snmp-link", "type": "udp", "options": { "host": "192.168.1.20", "port": 161 } }。完整说明见 SNMP。示例文件位于 samples/Zeus.Samples.Console.Config/zeus-snmp.json。

OPC UA 配置示例​

{
"channels": [
{
"name": "opcua-link",
"type": "virtual",
"options": {
"responder": "opcua"
}
}
],
"devices": [
{
"name": "plc",
"channel": "opcua-link",
"type": "opcua",
"options": {
"opcUaSessionName": "zeus-hmi"
},
"points": [
{
"name": "serverName",
"options": {
"nodeId": "ns=2;s=ServerName",
"dataType": "string",
"writable": true
}
}
]
}
]
}

接真实 Server 时把虚拟通道改为 TCP 通道,例如 { "name": "opcua-link", "type": "tcp", "options": { "host": "192.168.1.20", "port": 4840 } }。完整说明见 OPC UA。示例文件位于 samples/Zeus.Samples.Console.Config/zeus-opcua.json。

点字段​

根字段含义
name点名,例如 temperature
options点位地址、类型、缩放、报警和写回参数。核心配置保留该对象,并把它纳入点表指纹

常用 points[].options:

options 字段含义
topicMQTT 主题;省略时使用点名,不能包含 + 或 #
oidSNMP OID,例如 1.3.6.1.2.1.1.5.0;实例变量通常需要 .0 后缀
nodeIdOPC UA NodeId,例如 ns=2;s=Temperature 或 i=2258
mqttQos / mqttRetainMQTT 点的订阅/写回 QoS,以及写回是否作为保留消息
tagEtherNet/IP 标签名;省略时使用 name 作为标签名
tableModbus 数据区:holding / input / coil / discrete
deviceCodeMitsubishi MC 软元件:D / M / X / Y / W / R / ZR
areaSiemens S7 存储区:db / m / i / q;FINS 存储区:cio / wr / hr / ar / dm / tc / em / em0-em18;Host Link 存储区:cio / lr / hr / ar / dm;MEWTOCOL 存储区:dt / ld / fl / x / y / r / l
dbSiemens S7 DB 块号,仅 area: "db" 使用
dataTypeS7 数据类型:bool / byte / word / dword / int / dint / real;FINS / Host Link / MEWTOCOL 数据类型:bit / word / int16 / uint32 / int32 / real;EtherNet/IP 数据类型:bool / sint / int / dint / lint / usint / uint / udint / ulint / real / lreal;DL/T 645 数据类型:bcd / raw;IEC104 数据类型:single-point / normalized / scaled / short-float;MQTT 数据类型:text / boolean / int32 / int64 / double / bytes;SNMP 数据类型:integer / gauge32 / counter32 / timeticks / text / octet-string / oid / ip-address;OPC UA 数据类型:boolean / int32 / uint32 / int64 / float / double / string / datetime / bytestring
dataLengthDL/T 645 数据项有效载荷长度,不含 4 字节 DI,默认 4
bitS7 Bool 位偏移 0-7,FINS / Host Link / MEWTOCOL bit 位偏移 0-15,仅位点使用
address0 基地址;DL/T 645 中表示四字节数据项 DI;IEC104 中表示三字节 IOA;可写数字,也可写十六进制字符串,例如 "0x10" 或 "0x00000000"
count可选,默认 1。Modbus holding / input 点大于 1 时展开为连续数组点,例如 cellVoltage01、cellVoltage02
scale可选,寄存器、MC 字软元件、S7 / FINS / Host Link / MEWTOCOL 数值、EtherNet/IP 数值标签、DL/T 645 BCD 原始整数、IEC104 数值线值、SNMP 数值或 OPC UA 数值乘以该系数,结果为 double
lowAlarmLimit可选,低报阈值,仅数值点支持,按换算后的值判断
highAlarmLimit可选,高报阈值,仅数值点支持,按换算后的值判断
group可选,业务分组,例如 cellVoltage。会进入 PointDefinition.Group 和 PointAlarmRecord.Group
index可选,业务分组内序号,例如第 3 串电芯填 3。会进入 PointDefinition.Index 和 PointAlarmRecord.Index
tags可选,业务标签对象,例如 { "rack": "A" }。会进入 PointDefinition.Tags 和 PointAlarmRecord.Tags
writable可选,默认 false。Modbus 仅 holding / coil 可写;MC 的 D/W/R/ZR/M/Y 可写,X 只读;S7 的 I 区只读;MEWTOCOL 的 X 输入区只读;FINS / Host Link 按 PLC 对具体内存区的权限执行;EtherNet/IP 按 PLC 标签权限执行;DL/T 645 按表计写数据权限执行;IEC104 使用命令/设点写回;SNMP 按 Agent 的 write community 和 MIB 权限执行;OPC UA 按 Server 节点写权限执行

哪些修改会热更新​

默认 AddJsonFile(path, watch: true) 会监视文件变化。保存后走 ReloadAsync:采集间隔、重连选项立即写入运行中的选项单例;通道与设备按差异增删或重建。

修改内容是否立即生效说明
acquisition.intervalMilliseconds是下一轮采集使用新间隔
acquisition.pollImmediately是写入选项;只影响下一次从停止恢复后的首轮
reconnect.*是下一轮退避使用新参数
channels[].startup / channels[].options是通道启动策略或扩展选项变化会重建同名通道
COM 口、波特率、TCP/UDP 地址是关闭旧通道并登记新实例
增删通道 / 设备 / 点是按名称差异同步
devices[].options / points[].options是扩展选项变化会重建设备,确保协议插件重新读取参数
从站地址 unitId、DL/T 645 meterAddress 或 IEC104 commonAddress是重建该设备

通道参数变更会得到新的通道实例。原先挂在旧实例上的 DataReceived / StateChanged / PacketTraced 订阅会迁到同名新通道。业务代码如果保存了旧的 IChannel 引用,请在热更新后重新 Channels.Get。

如果 JSON 语法错误,Zeus 会继续使用上一份有效配置,并在日志里记录错误。不想依赖文件监视时,可手动调用 await app.ReloadAsync(path)。只改采集间隔、拓扑不变时,同样走 ReloadAsync,设备实例会保留。

手动调用 ReloadAsync(path, cancellationToken) 时,如果传入的令牌已经取消,Zeus 会直接按取消返回,不会先写入新的采集间隔、重连选项或拓扑变更。热更新中途失败时会尽量恢复到上一份有效拓扑;如果只是 JSON 语法错误,文件监视器会记录警告并沿用当前配置。

可选的重连段:

"reconnect": {
"enabled": true,
"initialDelayMilliseconds": 1000,
"maxDelayMilliseconds": 30000,
"backoffMultiplier": 2,
"maxAttempts": 0,
"jitterRatio": 0.2,
"circuitBreakMilliseconds": 0
}

maxAttempts: 0 表示不限次数;大于 0 时达到上限后停止重连,或在 circuitBreakMilliseconds 大于 0 时先进入熔断等待再重新开始。jitterRatio 用于错开多通道同时故障后的重连峰值,现场多设备同网段建议设置为 0.1 到 0.3。

复制到输出目录​

如果你把 zeus.json 放在项目里,建议在 .csproj 中设置复制:

<ItemGroup>
<None Include="zeus.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

否则运行目录可能找不到配置文件。

常见问题​

现象原因处理
找不到配置文件工作目录不是配置所在目录看异常里的绝对路径,或设置复制到输出目录
channel 未在 channels 中声明设备引用了不存在的通道名先写 channels,再写 devices
改了 COM 口后手里的通道引用失效通道被重建,旧实例已关闭事件订阅会自动迁移;保存的 IChannel 请重新 Channels.Get
改了采集间隔没生效JSON 语法错误或文件没被监视看日志,确认 watch: true
地址读不对address 没按 0 基写对照 Modbus 地址换算

可运行示例:samples/Zeus.Samples.Console.Config。Modbus ASCII 可直接复制 zeus-modbus-ascii.json,DL/T 645 可复制 zeus-dlt645.json,IEC104 可复制 zeus-iec104.json,OPC UA 可复制 zeus-opcua.json。