fix(download): 多网卡按 IP 选 PG/PC 接口 + 可显式指定/可诊断 (#14) - #16
Open
bulaofen0036-coder wants to merge 1 commit into
Open
fix(download): 多网卡按 IP 选 PG/PC 接口 + 可显式指定/可诊断 (#14)#16bulaofen0036-coder wants to merge 1 commit into
bulaofen0036-coder wants to merge 1 commit into
Conversation
DownloadToPlc 旧逻辑取第一个能 ApplyConfiguration 的 TargetInterface; ApplyConfiguration 不校验可达性,对 WLAN/VPN 网卡也返回 true,于是多网卡 机器上下载从看不见 CPU 的网卡走出去,报"连接到模块失败"。 - SelectDownloadRoute 枚举全部 Modes→PcInterfaces→TargetInterfaces 路由并 打分:PG/PC 网卡 IP 与目标 CPU IP 同一 /24 者优先;同分保持原枚举顺序 (旧 first-wins 行为不变)。 - DownloadToPlc 新增可选入参 pgPcInterface / targetIpAddress;匹配不到时 报错并列出全部可用路由,不静默回落。 - CheckDownloadReadiness 只读列出候选路由 (meta.downloadRoutes);下载成功 回报 meta.pgPcRoute,失败时错误信息附路由与覆盖参数用法。 - 新增离线测试 scripts/Test-DownloadRouteSelection.ps1(含必错哨兵),7/7 过。
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14.
根因
DownloadToPlc旧逻辑取第一个能ApplyConfiguration的ConfigurationTargetInterface。但ApplyConfiguration只返回「这条在线路由是否配置成功」,它不校验可达性 —— 对 WLAN / VPN 虚拟网卡同样返回true。于是在多网卡机器上(WLAN + VPN + PLCSIM 虚拟网卡),下载从一块根本看不见 CPU 的网卡走出去,报「连接到模块失败 / Connection to the target module cannot be established」,而CheckDownloadReadiness还返回ready: true。改动
Portal.Download.cs:TrySelectDownloadTargetInterface→SelectDownloadRoute。Modes → PcInterfaces → TargetInterfaces成候选路由并打分:PG/PC 网卡自身 IP 与目标 CPU IP 同一 IPv4 /24 者优先。DownloadToPlc新增可选入参pgPcInterface(网卡名子串,不区分大小写)与targetIpAddress(目标 CPU IP)。填了却匹配不到时报错并列出全部可用路由,不静默回落。CheckDownloadReadiness的meta.downloadRoutes只读列出每条「PG/PC 网卡 → CPU 接口」路由及两端 IP(preferred=true表示同网段);DownloadToPlc成功时meta.pgPcRoute回报实际走的网卡,失败时错误信息附「已用路由 + 全部候选 + 覆盖参数用法」。兼容性
同分时保持原枚举顺序 —— 所有候选都不占优(PROFIBUS/MPI、或确实没有网卡在 CPU 网段)时,行为与旧的 first-wins 完全一致。新入参全部可选,现有调用不受影响。
已知假设
Openness 的
ConfigurationAddress只暴露地址、不暴露掩码,所以 /24 是假设。它只用于给候选排序,绝不用于否决下载 —— 猜错最坏情况是退回旧行为,不会把本来能下的下载挡掉。验证
scripts/Test-DownloadRouteSelection.ps1:离线、不需要连 TIA,用伪造的多网卡对象图跑真实选路代码(EnumerateDownloadRoutes/ScoreDownloadRoutes/SelectDownloadRoute全是反射,POCO 即可驱动)。覆盖:自动选中 PLCSIM / 显式 IP / 显式网卡名覆盖排序 / 两种匹配失败的报错含路由清单 / 同分回落原顺序,外加一条必错哨兵(哨兵若通过说明测试本身坏了)。7/7 过。未做
meta.downloadRoutes。[未发布]:版本号待与另一条未合并的公开线分支统一后再定。