This commit is contained in:
xyy
2026-04-10 18:54:06 +08:00
parent 61c5e9f006
commit db683ead3b
4 changed files with 54 additions and 9 deletions

View File

@@ -11,7 +11,7 @@ namespace MembranePoreTester
public static IPlcService PlcService { get; private set; }
public static PlcConfiguration PlcConfig { get; private set; }
protected override void OnStartup(StartupEventArgs e)
protected async override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
@@ -29,6 +29,16 @@ namespace MembranePoreTester
throw new InvalidOperationException("PLC settings missing in appsettings.json");
PlcService = new ModbusTcpPlcService(PlcConfig);
var plcService = App.PlcService as ModbusTcpPlcService;
try
{
await plcService.EnsureConnectedAsync();
}
catch (Exception ex)
{
MessageBox.Show($"PLC 连接失败:{ex.Message}");
}
}
protected override void OnExit(ExitEventArgs e)