现场的需求的更改
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CapMachine.Wpf.Services;
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.Views
|
||||
@@ -8,10 +9,19 @@ namespace CapMachine.Wpf.Views
|
||||
/// </summary>
|
||||
public partial class MainView : Window
|
||||
{
|
||||
public MainView(ILogService logService)
|
||||
private readonly ZlgCanDriveService _zlgCanDriveService;
|
||||
private readonly ZlgLinDriveService _zlgLinDriveService;
|
||||
private readonly CanDriveService _canDriveService;
|
||||
private readonly LinDriveService _linDriveService;
|
||||
|
||||
public MainView(ILogService logService, ZlgCanDriveService zlgCanDriveService, ZlgLinDriveService zlgLinDriveService, CanDriveService canDriveService, LinDriveService linDriveService)
|
||||
{
|
||||
InitializeComponent();
|
||||
LogService = logService;
|
||||
_zlgCanDriveService = zlgCanDriveService;
|
||||
_zlgLinDriveService = zlgLinDriveService;
|
||||
_canDriveService = canDriveService;
|
||||
_linDriveService = linDriveService;
|
||||
}
|
||||
|
||||
public ILogService LogService { get; }
|
||||
@@ -42,10 +52,110 @@ namespace CapMachine.Wpf.Views
|
||||
}
|
||||
else
|
||||
{
|
||||
StopBusCommunicationOnExit();
|
||||
LogService.Info("Windows关闭");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 软件退出时停止总线通信,防止适配器在进程退出后继续自动发送。
|
||||
/// </summary>
|
||||
private void StopBusCommunicationOnExit()
|
||||
{
|
||||
StopZlgBusCommunicationOnExit();
|
||||
StopToomossBusCommunicationOnExit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止 ZLG CAN/CANFD 与 LIN 通信。
|
||||
/// </summary>
|
||||
private void StopZlgBusCommunicationOnExit()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_zlgLinDriveService.OpenState)
|
||||
{
|
||||
if (_zlgLinDriveService.IsCycleSend || _zlgLinDriveService.SchEnable)
|
||||
{
|
||||
_zlgLinDriveService.StopSchedule();
|
||||
_zlgLinDriveService.IsCycleSend = false;
|
||||
}
|
||||
|
||||
_zlgLinDriveService.CloseDevice();
|
||||
LogService.Info("程序退出时已停止 ZLG LIN 调度/发送并关闭设备");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_zlgCanDriveService.OpenState)
|
||||
{
|
||||
if (_zlgCanDriveService.IsCycleSend || _zlgCanDriveService.SchEnable)
|
||||
{
|
||||
_zlgCanDriveService.StopSchedule();
|
||||
_zlgCanDriveService.IsCycleSend = false;
|
||||
}
|
||||
|
||||
_zlgCanDriveService.CloseDevice();
|
||||
LogService.Info("程序退出时已停止 ZLG CAN/CANFD 调度/发送并关闭设备");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"程序退出停止 ZLG 总线失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止 Toomoss CAN 与 LIN 通信。
|
||||
/// </summary>
|
||||
private void StopToomossBusCommunicationOnExit()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_linDriveService.ToomossLinDrive.OpenState)
|
||||
{
|
||||
if (_linDriveService.ToomossLinDrive.IsCycleSend)
|
||||
{
|
||||
_linDriveService.ToomossLinDrive.StopCycleSendMsg();
|
||||
}
|
||||
|
||||
if (_linDriveService.ToomossLinDrive.SchEnable)
|
||||
{
|
||||
_linDriveService.ToomossLinDrive.StopSchedule();
|
||||
}
|
||||
|
||||
_linDriveService.ToomossLinDrive.CloseDevice();
|
||||
LogService.Info("程序退出时已停止 Toomoss LIN 调度/发送并关闭设备");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"程序退出停止 Toomoss LIN 失败:{ex.Message}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (_canDriveService.ToomossCanDrive.OpenState)
|
||||
{
|
||||
if (_canDriveService.ToomossCanDrive.IsCycleSend)
|
||||
{
|
||||
_canDriveService.ToomossCanDrive.StopCycleSendMsg();
|
||||
}
|
||||
|
||||
if (_canDriveService.ToomossCanDrive.SchEnable)
|
||||
{
|
||||
_canDriveService.ToomossCanDrive.StopSchedule();
|
||||
}
|
||||
|
||||
_canDriveService.ToomossCanDrive.CloseDevice();
|
||||
LogService.Info("程序退出时已停止 Toomoss CAN 调度/发送并关闭设备");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"程序退出停止 Toomoss CAN 失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主界面完成关闭
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user