Hello 各位大佬,
我在使用openness的“上传 PLC 设备”功能为什么会显示:
“
未经处理的异常: Siemens.Engineering.EngineeringTargetInvocationException: Error when calling method 'StationUpload' of type 'Siemens.Engineering.Upload.StationUploadProvider'.
Online connection to PLC_1 [192.168.0.100] failed.
”
但是我在手动使用TIA Portal 的转至在线,和上载都是没有问题的?
环境:WIN11
TIA Portal V20
用的是VirtualBox虚拟机+S7-PLCSIM V19
仿真环境和TIA Portal V20手动可以正常下载上传程序,只有使用openness的上传 PLC 设备不行

以下是源程序
public static bool UploadPLC(Project myProject)
{
// 1. 获取上传服务
StationUploadProvider uploadProvider = myProject.GetService<StationUploadProvider>();
// 2. 配置上传地址
ConnectionConfiguration configuration = uploadProvider.Configuration;
// 使用 PN/IE 模式(常用的 S7 通讯)
ConfigurationMode mode = configuration.Modes.Find("PN/IE");
if (mode == null) throw new Exception("未找到通信模式 PN/IE");
// 找到本机网卡(名称请根据实际调整)
ConfigurationPcInterface pcInterface = mode.PcInterfaces.Find("Intel(R) Wi-Fi 6E AX211 160MHz",1);
if (pcInterface == null) throw new Exception("未找到匹配的本地网卡");
// 配置 PLC 的 IP 地址
ConfigurationAddress address = pcInterface.Addresses.Create("192.168.0.100"); // PLC IP
// 3. 上传配置前委托
UploadConfigurationDelegate preUploadDelegate = PreConfigureUpload;
// 4. 执行上传
UploadResult result = uploadProvider.StationUpload(address, preUploadDelegate);
// 5. 打印上传结果
Console.WriteLine($"上传结果:{result.State}, 错误数:{result.ErrorCount}, 警告数:{result.WarningCount}");
PrintAllMessages(result.Messages, 0);
// 6. 获取上传设备对象
Device uploadedStation = result.UploadedStation;
return uploadedStation != null;
}