This commit is contained in:
12
App.xaml.cs
12
App.xaml.cs
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user