整理了错误的捕捉

关闭窗口验证
This commit is contained in:
2025-07-10 18:00:31 +08:00
parent fdd321e635
commit 4e8c66aa38
17 changed files with 368 additions and 95 deletions

View File

@@ -96,7 +96,7 @@ namespace CapMachine.Wpf
var IsOK = SoftAuthorizeHelper.CheckLience(MachineCode, PublicKey, Lience); var IsOK = SoftAuthorizeHelper.CheckLience(MachineCode, PublicKey, Lience);
if (!IsOK) if (!IsOK)
{ {
LogService.Error("授权失败"); LogService.Info("授权失败");
//this.Shutdown(); //this.Shutdown();
} }
} }
@@ -130,7 +130,7 @@ namespace CapMachine.Wpf
//containerRegistry.RegisterSingleton<MachineDataService>(); //containerRegistry.RegisterSingleton<MachineDataService>();
containerRegistry.RegisterSingleton<CanDriveService>(); containerRegistry.RegisterSingleton<CanDriveService>();
containerRegistry.RegisterSingleton<CanFdDriveService>(); containerRegistry.RegisterSingleton<CanFdDriveService>();
containerRegistry.RegisterSingleton<LinDriveService>(); containerRegistry.RegisterSingleton<LinDriveService>();
containerRegistry.RegisterSingleton<MachineRtDataService>(); containerRegistry.RegisterSingleton<MachineRtDataService>();
containerRegistry.RegisterSingleton<DataRecordService>(); containerRegistry.RegisterSingleton<DataRecordService>();
@@ -289,7 +289,7 @@ namespace CapMachine.Wpf
//给当前的全局异常捕捉服务使用 //给当前的全局异常捕捉服务使用
LogService = ContainerLocator.Container.Resolve<ILogService>(); LogService = ContainerLocator.Container.Resolve<ILogService>();
LogService.Error("Start-->OnInitialized"); LogService.Info("程序启动");
base.OnInitialized(); base.OnInitialized();
//#endregion //#endregion
@@ -317,7 +317,7 @@ namespace CapMachine.Wpf
void App_Exit(object sender, ExitEventArgs e) void App_Exit(object sender, ExitEventArgs e)
{ {
//程序退出时需要处理的业务 //程序退出时需要处理的业务
LogService.Error("程序退出"); LogService.Info("App-程序退出");
} }
@@ -332,12 +332,14 @@ namespace CapMachine.Wpf
try try
{ {
HandleException(e.Exception); HandleException(e.Exception);
MessageBox.Show("UI线程异常:" + e.Exception.Message); //MessageBox.Show("UI线程异常:" + e.Exception.Message);
LogService.Error("UI线程异常:" + e.Exception.Message);
} }
catch (Exception ex) catch (Exception ex)
{ {
HandleException(ex); HandleException(ex);
MessageBox.Show("UI线程发生致命错误"); //MessageBox.Show("UI线程发生致命错误");
LogService.Error("UI线程发生致命错误");
} }
finally finally
{ {
@@ -374,8 +376,8 @@ namespace CapMachine.Wpf
{ {
sbEx.Append(e.ExceptionObject); sbEx.Append(e.ExceptionObject);
} }
MessageBox.Show(sbEx.ToString()); //MessageBox.Show(sbEx.ToString());
LogService.Error(sbEx.ToString());
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -402,7 +404,8 @@ namespace CapMachine.Wpf
{ {
HandleException(exception); HandleException(exception);
//task线程内未处理捕获 //task线程内未处理捕获
MessageBox.Show("Task线程异常" + e.Exception.Message); //MessageBox.Show("Task线程异常" + e.Exception.Message);
LogService.Error($"Task线程异常");
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -423,7 +426,7 @@ namespace CapMachine.Wpf
private void HandleException(Exception ex) private void HandleException(Exception ex)
{ {
//记录日志 //记录日志
LogService.Error(ex.ToString()); LogService.Error($"App捕捉HandleException-{ex.ToString()}");
} }

View File

@@ -32,7 +32,7 @@ namespace CapMachine.Wpf.CanDrive
{ {
ContainerProvider = containerProvider; ContainerProvider = containerProvider;
HighSpeedDataService = ContainerProvider.Resolve<HighSpeedDataService>(); HighSpeedDataService = ContainerProvider.Resolve<HighSpeedDataService>();
LogService = ContainerProvider.Resolve<ILogService>();
//Stopwatch.Frequency表示高精度计时器每秒的计数次数ticks/秒每毫秒的ticks数 = 每秒的ticks数 ÷ 1000 //Stopwatch.Frequency表示高精度计时器每秒的计数次数ticks/秒每毫秒的ticks数 = 每秒的ticks数 ÷ 1000
TicksPerMs = Stopwatch.Frequency / 1000.0; TicksPerMs = Stopwatch.Frequency / 1000.0;
} }
@@ -42,18 +42,27 @@ namespace CapMachine.Wpf.CanDrive
/// </summary> /// </summary>
public HighSpeedDataService HighSpeedDataService { get; set; } public HighSpeedDataService HighSpeedDataService { get; set; }
public ILogService LogService { get; set; }
/// <summary> /// <summary>
/// 开始CAN的驱动 /// 开始CAN的驱动
/// </summary> /// </summary>
public void StartCanDrive() public void StartCanDrive()
{ {
IsExistsDllFile(); try
ScanDevice(); {
OpenDevice(); IsExistsDllFile();
GetDeviceInfo(); ScanDevice();
GetCANConfig(); OpenDevice();
InitCAN(); GetDeviceInfo();
GetCANConfig();
InitCAN();
}
catch (Exception ex)
{
LogService.Error(ex.Message);
System.Windows.MessageBox.Show($"{ex.Message}", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
}
} }
/// <summary> /// <summary>
@@ -473,8 +482,6 @@ namespace CapMachine.Wpf.CanDrive
private static readonly Random _random = new Random(); private static readonly Random _random = new Random();
/// <summary> /// <summary>
/// 精确周期发送CAN数据 /// 精确周期发送CAN数据
/// </summary> /// </summary>
@@ -608,6 +615,7 @@ namespace CapMachine.Wpf.CanDrive
} }
catch (Exception ex) catch (Exception ex)
{ {
LogService.Error(ex.Message);
Console.WriteLine($"CAN周期发送异常: {ex.Message}"); Console.WriteLine($"CAN周期发送异常: {ex.Message}");
// 短暂暂停避免异常情况下CPU占用过高 // 短暂暂停避免异常情况下CPU占用过高
await Task.Delay(10, token); await Task.Delay(10, token);
@@ -618,7 +626,7 @@ namespace CapMachine.Wpf.CanDrive
{ {
// 确保在任何情况下(正常退出、异常、取消)都会停止计时器 // 确保在任何情况下(正常退出、异常、取消)都会停止计时器
Stopwatcher.Stop(); Stopwatcher.Stop();
LogService.Error(ex.Message);
// 清理其他可能的资源 // 清理其他可能的资源
Console.WriteLine("CAN周期发送任务已结束资源已清理"); Console.WriteLine("CAN周期发送任务已结束资源已清理");
} }
@@ -818,6 +826,7 @@ namespace CapMachine.Wpf.CanDrive
} }
catch (Exception ex) catch (Exception ex)
{ {
LogService.Error(ex.Message);
//LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}"); //LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}");
} }
} }

View File

@@ -33,6 +33,10 @@ namespace CapMachine.Wpf.Models
SelectedCanLinMsg = "CAN"; SelectedCanLinMsg = "CAN";
CanLinRunState=true; CanLinRunState=true;
break; break;
case CanLinEnum.CANFD:
SelectedCanLinMsg = "CANFD";
CanLinRunState = true;
break;
case CanLinEnum.Lin: case CanLinEnum.Lin:
SelectedCanLinMsg = "LIN"; SelectedCanLinMsg = "LIN";
CanLinRunState = true; CanLinRunState = true;

View File

@@ -0,0 +1,69 @@
using Microsoft.VisualBasic;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Models
{
/// <summary>
/// 系统错误状态
/// </summary>
public class SysErrState : BindableBase
{
private string? _ErrTime= "无错误";
/// <summary>
/// 错误时间
/// </summary>
public string? ErrTime
{
get { return _ErrTime; }
set { _ErrTime = value; RaisePropertyChanged(); }
}
private string? _ErrMsg;
/// <summary>
/// 错误消息
/// </summary>
public string? ErrMsg
{
get { return _ErrMsg; }
set { _ErrMsg = value; RaisePropertyChanged(); }
}
private bool _ErrState=false;
/// <summary>
/// 错误状态
/// </summary>
public bool ErrState
{
get { return _ErrState; }
set { _ErrState = value; RaisePropertyChanged(); }
}
/// <summary>
/// 激活错误状态
/// </summary>
public void ActiveErr(string Msg)
{
ErrState=true;
ErrTime =DateTime.Now.ToString("MM-dd HH:mm:ss");
ErrMsg = "见日志";
}
/// <summary>
/// 清空错误状态
/// </summary>
public void ClearErr()
{
ErrState = false;
ErrTime = "无错误";
ErrMsg = "";
}
}
}

View File

@@ -0,0 +1,17 @@
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.PrismEvent
{
/// <summary>
/// 错误状态事件
/// </summary>
public class ErrStateEvent : PubSubEvent<ErrStateMsg>
{
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.PrismEvent
{
/// <summary>
/// 错误状态消息
/// </summary>
public class ErrStateMsg
{
/// <summary>
/// 错误消息内容
/// </summary>
public string? ErrMsg { get; set; }
}
}

View File

@@ -311,69 +311,77 @@ namespace CapMachine.Wpf.Services
{ {
if (RecoredChannelInfo.Reader.TryRead(out var recordChannelData)) if (RecoredChannelInfo.Reader.TryRead(out var recordChannelData))
{ {
////第一次计时 try
//stopwatch.Start(); //启动Stopwatch
//新增数据
CacheRecordData.Add(recordChannelData);
MaxCacheCellCount++;
//先判断缓存的单元大小,防止每次都检查删除,数据达到时间范围外的话,则删除,即是600次后进行一次判断删除
if (MaxCacheCellCount >= 600)
{ {
//不在缓存的时间范围内的话,则删除数据 ////第一次计时
if (CacheRecordData.Where(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec)).Any()) //stopwatch.Start(); //启动Stopwatch
//新增数据
CacheRecordData.Add(recordChannelData);
MaxCacheCellCount++;
//先判断缓存的单元大小,防止每次都检查删除,数据达到时间范围外的话,则删除,即是600次后进行一次判断删除
if (MaxCacheCellCount >= 600)
{ {
CacheRecordData.RemoveAll(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec)); //不在缓存的时间范围内的话,则删除数据
if (CacheRecordData.Where(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec)).Any())
{
CacheRecordData.RemoveAll(a => a.CreateTime <= DateTime.Now.AddSeconds(-ConfigService.ChartRtDataCacheTimeSec));
}
MaxCacheCellCount = 0;
} }
MaxCacheCellCount = 0;
//ConcurrentQueueData.
//Prism发布数据
_EventAggregator.GetEvent<RecordDataEvent>().Publish(recordChannelData.DeepClone());
//判断集合的数据是否达到要求
//if (CacheRecordData.Count >= MaxCacheCount)
//{
//CacheRecordData可能存在多个表格数据依据表名进行分类
//考虑多个表结构
//var GroupTableData = CacheRecordData.GroupBy(a => a.TableName).ToList();
//foreach (var ItemData in GroupTableData)
//{
//表名称
//var TableName = ItemData.Key;
//当前表格的数据
//var Datas = ItemData.Select(item => item.Data).ToList();
//var Datas = recordChannelData.Select(item => item.Data).ToList();
//List<CsvRecordModel> models = Datas.Select(dict => ConvertToCsvRecordModel(dict)).ToList();
//转换到CSV的数据
var models = ConvertToCsvRecordModel(recordChannelData.Data);
//填充工况名称
models.WorkCond = ConfigService.CurExpInfo.Name;
//数据库保存
//zeroDbContext.Insert(Datas);
//CSV文件保存
SaveToCsv(new List<CsvRecordModel>() { models });
//}
//CacheRecordData.Clear();
//Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}-{LineName}-保存成功!");
//}
//stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("保存数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset();
}
catch (Exception ex)
{
LogService.Error(ex.Message);
} }
//ConcurrentQueueData.
//Prism发布数据
_EventAggregator.GetEvent<RecordDataEvent>().Publish(recordChannelData.DeepClone());
//判断集合的数据是否达到要求
//if (CacheRecordData.Count >= MaxCacheCount)
//{
//CacheRecordData可能存在多个表格数据依据表名进行分类
//考虑多个表结构
//var GroupTableData = CacheRecordData.GroupBy(a => a.TableName).ToList();
//foreach (var ItemData in GroupTableData)
//{
//表名称
//var TableName = ItemData.Key;
//当前表格的数据
//var Datas = ItemData.Select(item => item.Data).ToList();
//var Datas = recordChannelData.Select(item => item.Data).ToList();
//List<CsvRecordModel> models = Datas.Select(dict => ConvertToCsvRecordModel(dict)).ToList();
//转换到CSV的数据
var models = ConvertToCsvRecordModel(recordChannelData.Data);
//填充工况名称
models.WorkCond = ConfigService.CurExpInfo.Name;
//数据库保存
//zeroDbContext.Insert(Datas);
//CSV文件保存
SaveToCsv(new List<CsvRecordModel>() { models });
//}
//CacheRecordData.Clear();
//Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}-{LineName}-保存成功!");
//}
//stopwatch.Stop(); //停止Stopwatch
//Console.WriteLine("保存数据耗时::{0}", stopwatch.Elapsed.TotalSeconds.ToString());
//stopwatch.Reset();
} }
} }
} }
@@ -400,9 +408,9 @@ namespace CapMachine.Wpf.Services
//增加日期和时间两个列 //增加日期和时间两个列
model.WorkDay = model.CreateTime.ToString("yyyy-MM-dd"); model.WorkDay = model.CreateTime.ToString("yyyy-MM-dd");
model.Time = model.CreateTime.ToString("HH:mm:ss"); model.Time = model.CreateTime.ToString("HH:mm:ss");
return model; return model;
} }
@@ -452,7 +460,7 @@ namespace CapMachine.Wpf.Services
var DataInfo = MachineRtDataService.TagManger.DicTags var DataInfo = MachineRtDataService.TagManger.DicTags
.ToDictionary(kvp => kvp.Key, kvp => (object)MachineRtDataService.TagManger.TryGetRecordPVValue(kvp.Value.Name)); .ToDictionary(kvp => kvp.Key, kvp => (object)MachineRtDataService.TagManger.TryGetRecordPVValue(kvp.Value.Name));
DataInfo.Add("创建时间", DateTime.Now); DataInfo.Add("创建时间", DateTime.Now);
var RecordData = new RecordChannelData() var RecordData = new RecordChannelData()
{ {
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
@@ -474,7 +482,7 @@ namespace CapMachine.Wpf.Services
catch (Exception ex) catch (Exception ex)
{ {
//CycleTimer.Start(); //执行完毕后再开启器 //CycleTimer.Start(); //执行完毕后再开启器
LogService.Info($"时间:{DateTime.Now.ToString()}-【PwAnalyze-CycleAction】-{ex.Message}"); LogService.Error($"时间:{DateTime.Now.ToString()}-【RecoredCycleAction】-{ex.Message}");
} }
} }

View File

@@ -1,4 +1,6 @@
using NLog; using CapMachine.Wpf.PrismEvent;
using NLog;
using Prism.Events;
using Prism.Services.Dialogs; using Prism.Services.Dialogs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -15,6 +17,16 @@ namespace CapMachine.Wpf.Services
{ {
private static Logger Logger = LogManager.GetCurrentClassLogger(); //初始化日志类 private static Logger Logger = LogManager.GetCurrentClassLogger(); //初始化日志类
public IEventAggregator EventAggregator { get; }
/// <summary>
/// NLog服务构造函数
/// </summary>
public LogService(IEventAggregator eventAggregator)
{
EventAggregator = eventAggregator;
}
/// <summary> /// <summary>
/// 调试日志 /// 调试日志
/// </summary> /// </summary>
@@ -48,6 +60,8 @@ namespace CapMachine.Wpf.Services
public void Error(string msg) public void Error(string msg)
{ {
Logger.Error(msg); Logger.Error(msg);
//发布错误状态消息,给页脚显示用
EventAggregator.GetEvent<ErrStateEvent>().Publish(new ErrStateMsg() { ErrMsg=msg});
} }
/// <summary> /// <summary>

View File

@@ -37,6 +37,7 @@ namespace CapMachine.Wpf.Services
private IEventAggregator _EventAggregator { get; set; } private IEventAggregator _EventAggregator { get; set; }
public AlarmService AlarmService { get; } public AlarmService AlarmService { get; }
public ConfigService ConfigService { get; } public ConfigService ConfigService { get; }
public ILogService LogService { get; }
public CanDriveService CanDriveService { get; } public CanDriveService CanDriveService { get; }
public CanFdDriveService CanFdDriveService { get; } public CanFdDriveService CanFdDriveService { get; }
public LinDriveService LinDriveService { get; } public LinDriveService LinDriveService { get; }
@@ -121,7 +122,7 @@ namespace CapMachine.Wpf.Services
/// 实例化函数 /// 实例化函数
/// </summary> /// </summary>
/// <param name="eventAggregator"></param> /// <param name="eventAggregator"></param>
public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService, ConfigService configService, public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService, ConfigService configService,ILogService logService,
CanDriveService canDriveService, CanFdDriveService canFdDriveService, LinDriveService linDriveService, SysRunService sysRunService)//, AlarmService alarmService CanDriveService canDriveService, CanFdDriveService canFdDriveService, LinDriveService linDriveService, SysRunService sysRunService)//, AlarmService alarmService
{ {
//ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>(); //ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>();
@@ -139,6 +140,7 @@ namespace CapMachine.Wpf.Services
_EventAggregator = eventAggregator; _EventAggregator = eventAggregator;
AlarmService = alarmService; AlarmService = alarmService;
ConfigService = configService; ConfigService = configService;
LogService = logService;
CanDriveService = canDriveService; CanDriveService = canDriveService;
CanFdDriveService = canFdDriveService; CanFdDriveService = canFdDriveService;
LinDriveService = linDriveService; LinDriveService = linDriveService;
@@ -1728,7 +1730,7 @@ namespace CapMachine.Wpf.Services
} }
catch (Exception ex) catch (Exception ex)
{ {
//LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}"); LogService.Error(ex.Message);
} }

View File

@@ -1,4 +1,5 @@
using CapMachine.Wpf.Models; using CapMachine.Wpf.Models;
using CapMachine.Wpf.PrismEvent;
using Prism.Events; using Prism.Events;
using Prism.Mvvm; using Prism.Mvvm;
using System; using System;
@@ -10,11 +11,11 @@ using System.Threading.Tasks;
namespace CapMachine.Wpf.Services namespace CapMachine.Wpf.Services
{ {
/// <summary> /// <summary>
/// 系统 /// 系统运行服务
/// </summary> /// </summary>
public class SysRunService : BindableBase public class SysRunService : BindableBase
{ {
public SysRunService(IEventAggregator eventAggregator,ConfigService configService,CanDriveService canDriveService,LinDriveService linDriveService) public SysRunService(IEventAggregator eventAggregator, ConfigService configService, CanDriveService canDriveService, LinDriveService linDriveService)
{ {
// 创建一个定时器设置间隔时间为2000毫秒即2秒 // 创建一个定时器设置间隔时间为2000毫秒即2秒
CurTimer = new System.Timers.Timer(5000); CurTimer = new System.Timers.Timer(5000);
@@ -28,10 +29,27 @@ namespace CapMachine.Wpf.Services
ConfigService = configService; ConfigService = configService;
CanDriveService = canDriveService; CanDriveService = canDriveService;
LinDriveService = linDriveService; LinDriveService = linDriveService;
MachineRunState1 = new MachineRunState("M1", EventAggregator, ConfigService,canDriveService,linDriveService); MachineRunState1 = new MachineRunState("M1", EventAggregator, ConfigService, canDriveService, linDriveService);
EventAggregator.GetEvent<ErrStateEvent>().Subscribe(ErrStateAction);
} }
/// <summary>
/// 错误状态处理方法
/// </summary>
/// <param name="msg"></param>
/// <exception cref="NotImplementedException"></exception>
private void ErrStateAction(ErrStateMsg errStateMsg)
{
SysErrStateInfo.ActiveErr(errStateMsg.ErrMsg!);
}
/// <summary>
/// 系统错误状态
/// </summary>
public SysErrState SysErrStateInfo { get; set; } = new SysErrState();
/// <summary> /// <summary>
/// 设备运行状态 /// 设备运行状态
/// </summary> /// </summary>

View File

@@ -14,7 +14,7 @@
"DataType": "Short", "DataType": "Short",
"RWInfo": "PLCRead", "RWInfo": "PLCRead",
"PVModel": { "PVModel": {
"Address": "VW15000", "Address": "VW14100",
"ReWritePLCAddress": "V14100", "ReWritePLCAddress": "V14100",
"EngValue": 0, "EngValue": 0,
"EngValueStr": "", "EngValueStr": "",

View File

@@ -34,7 +34,7 @@ namespace CapMachine.Wpf.ViewModels
{ {
public CANFDConfigViewModel(IDialogService dialogService, IFreeSql freeSql, public CANFDConfigViewModel(IDialogService dialogService, IFreeSql freeSql,
IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService, IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService,
ComActionService actionService, ComActionService actionService,ILogService logService,
ConfigService configService, CanFdDriveService canFdDriveService, ConfigService configService, CanFdDriveService canFdDriveService,
IMapper mapper, MachineRtDataService machineRtDataService) IMapper mapper, MachineRtDataService machineRtDataService)
{ {
@@ -44,6 +44,7 @@ namespace CapMachine.Wpf.ViewModels
RegionManager = regionManager; RegionManager = regionManager;
SysRunService = sysRunService; SysRunService = sysRunService;
ComActionService = actionService; ComActionService = actionService;
LogService = logService;
ConfigService = configService; ConfigService = configService;
CanFdDriveService = canFdDriveService; CanFdDriveService = canFdDriveService;
Mapper = mapper; Mapper = mapper;
@@ -139,6 +140,7 @@ namespace CapMachine.Wpf.ViewModels
public IRegionManager RegionManager { get; } public IRegionManager RegionManager { get; }
public SysRunService SysRunService { get; } public SysRunService SysRunService { get; }
public ComActionService ComActionService { get; } public ComActionService ComActionService { get; }
public ILogService LogService { get; }
public ConfigService ConfigService { get; } public ConfigService ConfigService { get; }
public CanFdDriveService CanFdDriveService { get; } public CanFdDriveService CanFdDriveService { get; }
public IMapper Mapper { get; } public IMapper Mapper { get; }
@@ -905,6 +907,7 @@ namespace CapMachine.Wpf.ViewModels
switch (Par) switch (Par)
{ {
case "Open": case "Open":
if (ComActionService.IsCanToDoWork() == false) if (ComActionService.IsCanToDoWork() == false)
{ {
System.Windows.MessageBox.Show("请关闭LIN连接后才能开启CAN同一个时刻只能有一个通信驱动压缩机", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); System.Windows.MessageBox.Show("请关闭LIN连接后才能开启CAN同一个时刻只能有一个通信驱动压缩机", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);

View File

@@ -64,6 +64,31 @@ namespace CapMachine.Wpf.ViewModels
IsTopDrawerOpen = false; IsTopDrawerOpen = false;
} }
//private DelegateCommand _WindowClosingCmd;
///// <summary>
///// 顶部弹窗按钮命令
///// </summary>
//public DelegateCommand WindowClosingCmd
//{
// set
// {
// _WindowClosingCmd = value;
// }
// get
// {
// if (_WindowClosingCmd == null)
// {
// _WindowClosingCmd = new DelegateCommand(() => WindowClosingCmdCall());
// }
// return _WindowClosingCmd;
// }
//}
//private void WindowClosingCmdCall()
//{
// var dd = 1;
//}
private DelegateCommand<string> _TopDrawerCmd; private DelegateCommand<string> _TopDrawerCmd;
/// <summary> /// <summary>
/// 顶部弹窗按钮命令 /// 顶部弹窗按钮命令

View File

@@ -27,7 +27,8 @@ namespace CapMachine.Wpf.ViewModels
/// <param name="machineRtDataService"></param> /// <param name="machineRtDataService"></param>
/// <param name="dialogService"></param> /// <param name="dialogService"></param>
public MonitorViewModel(ConfigService configService, IEventAggregator eventAggregator, public MonitorViewModel(ConfigService configService, IEventAggregator eventAggregator,
DataRecordService dataRecordService, SysRunService sysRunService, AlarmService alarmService, PPCService pPCService,CanDriveService canDriveService,LinDriveService linDriveService, DataRecordService dataRecordService, SysRunService sysRunService, AlarmService alarmService, PPCService pPCService,
CanDriveService canDriveService, CanFdDriveService canFdDriveService, LinDriveService linDriveService,
MachineRtDataService machineRtDataService, IDialogService dialogService) MachineRtDataService machineRtDataService, IDialogService dialogService)
{ {
ConfigService = configService; ConfigService = configService;
@@ -38,6 +39,7 @@ namespace CapMachine.Wpf.ViewModels
AlarmService = alarmService; AlarmService = alarmService;
PPCService = pPCService; PPCService = pPCService;
CanDriveService = canDriveService; CanDriveService = canDriveService;
CanFdDriveService = canFdDriveService;
LinDriveService = linDriveService; LinDriveService = linDriveService;
MachineRtDataService = machineRtDataService; MachineRtDataService = machineRtDataService;
DialogService = dialogService; DialogService = dialogService;
@@ -75,6 +77,7 @@ namespace CapMachine.Wpf.ViewModels
public AlarmService AlarmService { get; } public AlarmService AlarmService { get; }
public PPCService PPCService { get; } public PPCService PPCService { get; }
public CanDriveService CanDriveService { get; } public CanDriveService CanDriveService { get; }
public CanFdDriveService CanFdDriveService { get; }
public LinDriveService LinDriveService { get; } public LinDriveService LinDriveService { get; }
public MachineRtDataService MachineRtDataService { get; } public MachineRtDataService MachineRtDataService { get; }
public IDialogService DialogService { get; } public IDialogService DialogService { get; }
@@ -229,6 +232,10 @@ namespace CapMachine.Wpf.ViewModels
this.SysRunServer.MachineRunState1.FireStart(); this.SysRunServer.MachineRunState1.FireStart();
DataRecordService.StartRecord(); DataRecordService.StartRecord();
//清空错误状态
SysRunServer.SysErrStateInfo.ClearErr();
break; break;
case "结束": case "结束":
MachineRtDataService.SysEnd(); MachineRtDataService.SysEnd();
@@ -244,6 +251,11 @@ namespace CapMachine.Wpf.ViewModels
CanDriveService.UpdateSpeedCmdData(0); CanDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0; //itemTag.Value.EngPvValue = 0;
break; break;
case CanLinEnum.CANFD:
//获取PLC的SV数据 更新SV的速度值到压缩机
CanFdDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.Lin: case CanLinEnum.Lin:
//获取PLC的SV数据 更新SV的速度值到压缩机 //获取PLC的SV数据 更新SV的速度值到压缩机
LinDriveService.UpdateSpeedCmdData(0); LinDriveService.UpdateSpeedCmdData(0);
@@ -261,6 +273,9 @@ namespace CapMachine.Wpf.ViewModels
this.SysRunServer.MachineRunState1.FireReset(); this.SysRunServer.MachineRunState1.FireReset();
DataRecordService.EndRecord(); DataRecordService.EndRecord();
//清空错误状态
SysRunServer.SysErrStateInfo.ClearErr();
//结束运行的时候需要将压缩机的速度值设置为0 //结束运行的时候需要将压缩机的速度值设置为0
switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin)
{ {
@@ -269,6 +284,11 @@ namespace CapMachine.Wpf.ViewModels
CanDriveService.UpdateSpeedCmdData(0); CanDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0; //itemTag.Value.EngPvValue = 0;
break; break;
case CanLinEnum.CANFD:
//获取PLC的SV数据 更新SV的速度值到压缩机
CanFdDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.Lin: case CanLinEnum.Lin:
//获取PLC的SV数据 更新SV的速度值到压缩机 //获取PLC的SV数据 更新SV的速度值到压缩机
LinDriveService.UpdateSpeedCmdData(0); LinDriveService.UpdateSpeedCmdData(0);

View File

@@ -64,7 +64,7 @@
<TextBlock <TextBlock
FontSize="16" FontSize="16"
Foreground="White" Foreground="White"
Text="系统状态:" /> Text="运行状态:" />
<TextBlock <TextBlock
Margin="5,0" Margin="5,0"
FontSize="16" FontSize="16"
@@ -247,6 +247,38 @@
Text="{Binding DataRecordService.IsRecord, Converter={StaticResource BoolStateStrConvert}}" /> Text="{Binding DataRecordService.IsRecord, Converter={StaticResource BoolStateStrConvert}}" />
</StackPanel> </StackPanel>
</Border> </Border>
<Border>
<Border.Style>
<Style BasedOn="{StaticResource BoardStyle}" TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding SysRunService.SysErrStateInfo.ErrState}" Value="false">
<Setter Property="Background" Value="LimeGreen" />
</DataTrigger>
<DataTrigger Binding="{Binding SysRunService.SysErrStateInfo.ErrState}" Value="true">
<Setter Property="Background" Value="OrangeRed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel Style="{StaticResource StackPanelStyle}">
<TextBlock
Margin="5,0,5,0"
VerticalAlignment="Center"
FontFamily="/Assets/Fonts/#iconfont"
FontSize="16"
Foreground="White"
Text="&#xe686;" />
<TextBlock
FontSize="16"
Foreground="White"
Text="软件信息:" />
<TextBlock
Margin="5,0"
FontSize="16"
Foreground="White"
Text="{Binding SysRunService.SysErrStateInfo.ErrTime}" />
</StackPanel>
</Border>
<Border> <Border>
<Border.Style> <Border.Style>
<Style BasedOn="{StaticResource BoardStyle}" TargetType="Border"> <Style BasedOn="{StaticResource BoardStyle}" TargetType="Border">

View File

@@ -14,6 +14,8 @@
Width="1920" Width="1920"
Height="1080" Height="1080"
prism:ViewModelLocator.AutoWireViewModel="True" prism:ViewModelLocator.AutoWireViewModel="True"
Closed="Window_Closed"
Closing="Window_Closing"
Icon="/Assets/Images/favicon.ico" Icon="/Assets/Images/favicon.ico"
StateChanged="Window_StateChanged" StateChanged="Window_StateChanged"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
@@ -24,8 +26,8 @@
<localEx:BindingProxy x:Key="Proxy" Data="{Binding}" /> <localEx:BindingProxy x:Key="Proxy" Data="{Binding}" />
</Window.Resources> </Window.Resources>
<!--<i:Interaction.Triggers> <!--<i:Interaction.Triggers>
<i:EventTrigger EventName="StateChanged"> <i:EventTrigger EventName="Closing">
<prism:InvokeCommandAction Command="{Binding WindowStateChangedCmd}" CommandParameter="{Binding ElementName=MainDatagrid, Path=SelectedItem}" /> <prism:InvokeCommandAction Command="{Binding WindowClosingCmd}" />
</i:EventTrigger> </i:EventTrigger>
</i:Interaction.Triggers>--> </i:Interaction.Triggers>-->
<Grid> <Grid>

View File

@@ -26,6 +26,34 @@ namespace CapMachine.Wpf.Views
LogService.Info($"Windows状态{this.WindowState}-Visibility: {this.Visibility}"); LogService.Info($"Windows状态{this.WindowState}-Visibility: {this.Visibility}");
} }
/// <summary>
/// 主界面正要关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// 弹窗提示是否确定要退出
MessageBoxResult result = MessageBox.Show("您确定要退出程序吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel);
//System.Console.WriteLine(result);
if (result == MessageBoxResult.Cancel)
{
e.Cancel = true; // 中断点击事件
}
else
{
LogService.Info("Windows关闭");
}
}
/// <summary>
/// 主界面完成关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Closed(object sender, EventArgs e)
{
Environment.Exit(0); // 强制结束
}
} }
} }