diff --git a/CapMachine.Model/CANLIN/CanLinEmun.cs b/CapMachine.Model/CANLIN/CanLinEmun.cs
index 42802ed..69e479f 100644
--- a/CapMachine.Model/CANLIN/CanLinEmun.cs
+++ b/CapMachine.Model/CANLIN/CanLinEmun.cs
@@ -15,10 +15,16 @@ namespace CapMachine.Model.CANLIN
/// CAN
///
CAN = 1,
+
///
/// LIN
///
LIN = 2,
+
+ ///
+ /// CANFD
+ ///
+ CANFD = 3,
}
///
diff --git a/CapMachine.Wpf/App.xaml.cs b/CapMachine.Wpf/App.xaml.cs
index 851d5d8..97142b0 100644
--- a/CapMachine.Wpf/App.xaml.cs
+++ b/CapMachine.Wpf/App.xaml.cs
@@ -129,6 +129,8 @@ namespace CapMachine.Wpf
////注册设备服务
//containerRegistry.RegisterSingleton();
containerRegistry.RegisterSingleton();
+ containerRegistry.RegisterSingleton();
+
containerRegistry.RegisterSingleton();
containerRegistry.RegisterSingleton();
containerRegistry.RegisterSingleton();
@@ -178,6 +180,7 @@ namespace CapMachine.Wpf
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
+ containerRegistry.RegisterForNavigation();
containerRegistry.RegisterForNavigation();
@@ -275,6 +278,7 @@ namespace CapMachine.Wpf
var appVersionService6 = ContainerLocator.Container.Resolve();
var appVersionService7 = ContainerLocator.Container.Resolve();
var appVersionService8 = ContainerLocator.Container.Resolve();
+ var appVersionService81 = ContainerLocator.Container.Resolve();
var appVersionService9 = ContainerLocator.Container.Resolve();
var appVersionService10 = ContainerLocator.Container.Resolve();
//var appVersionService11 = ContainerLocator.Container.Resolve();
diff --git a/CapMachine.Wpf/CanDrive/CanFD/ToomossCanFD.cs b/CapMachine.Wpf/CanDrive/CanFD/ToomossCanFD.cs
index 8abde2d..fce2a20 100644
--- a/CapMachine.Wpf/CanDrive/CanFD/ToomossCanFD.cs
+++ b/CapMachine.Wpf/CanDrive/CanFD/ToomossCanFD.cs
@@ -118,6 +118,15 @@ namespace CapMachine.Wpf.CanDrive
set { _OpenState = value; RaisePropertyChanged(); }
}
+ private bool _DbcParserState;
+ ///
+ /// DBC解析的状态
+ ///
+ public bool DbcParserState
+ {
+ get { return _DbcParserState; }
+ set { _DbcParserState = value; RaisePropertyChanged(); }
+ }
///
/// 扫描到设备个数
@@ -766,6 +775,9 @@ namespace CapMachine.Wpf.CanDrive
//关闭设备
USB_DEVICEByFD.USB_CloseDevice(DevHandle);
OpenState = false;
+ DbcParserState = false;
+ IsCycleRevice = false;
+ IsCycleSend = false;
}
}
diff --git a/CapMachine.Wpf/Services/NavigationMenuService.cs b/CapMachine.Wpf/Services/NavigationMenuService.cs
index db0c4eb..d96ed1e 100644
--- a/CapMachine.Wpf/Services/NavigationMenuService.cs
+++ b/CapMachine.Wpf/Services/NavigationMenuService.cs
@@ -73,6 +73,7 @@ namespace CapMachine.Wpf.Services
//}));
MenuItems.Add(new NavigationItem("", "工艺过程", "MonitorView"));
MenuItems.Add(new NavigationItem("", "CAN配置", "CANConfigView"));
+ MenuItems.Add(new NavigationItem("", "CANFD配置", "CANFDConfigView"));
MenuItems.Add(new NavigationItem("", "LIN配置", "LINConfigView"));
MenuItems.Add(new NavigationItem("", "工艺参数", "ProConfigView"));
MenuItems.Add(new NavigationItem("", "工艺曲线", "RealTimeChartView"));
diff --git a/CapMachine.Wpf/ViewModels/CANFDConfigViewModel.cs b/CapMachine.Wpf/ViewModels/CANFDConfigViewModel.cs
new file mode 100644
index 0000000..7294059
--- /dev/null
+++ b/CapMachine.Wpf/ViewModels/CANFDConfigViewModel.cs
@@ -0,0 +1,1290 @@
+using AutoMapper;
+using CapMachine.Core;
+using CapMachine.Model;
+using CapMachine.Model.CANLIN;
+using CapMachine.Wpf.CanDrive;
+using CapMachine.Wpf.Dtos;
+using CapMachine.Wpf.PrismEvent;
+using CapMachine.Wpf.Services;
+using Ganss.Excel;
+using ImTools;
+using Microsoft.VisualBasic;
+using Microsoft.Win32;
+using NPOI.SS.UserModel.Charts;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Regions;
+using Prism.Services.Dialogs;
+using Syncfusion.Windows.Tools.Controls;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using static CapMachine.Wpf.Models.ComEnum;
+
+namespace CapMachine.Wpf.ViewModels
+{
+ public class CANFDConfigViewModel : NavigationViewModel
+ {
+ public CANFDConfigViewModel(IDialogService dialogService, IFreeSql freeSql,
+ IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService,
+ ComActionService actionService,
+ ConfigService configService, CanFdDriveService canFdDriveService,
+ IMapper mapper, MachineRtDataService machineRtDataService)
+ {
+ //LogService = logService;
+ FreeSql = freeSql;
+ EventAggregator = eventAggregator;
+ RegionManager = regionManager;
+ SysRunService = sysRunService;
+ ComActionService = actionService;
+ ConfigService = configService;
+ CanFdDriveService = canFdDriveService;
+ Mapper = mapper;
+ this.MachineRtDataService = machineRtDataService;
+
+ //MachineDataService = machineDataService;
+ DialogService = dialogService;
+
+ WriteNameCbxItems = new ObservableCollection()
+ {
+ new CbxItems(){ Key="转速",Text="转速"},
+ new CbxItems(){ Key="功率限制",Text="功率限制"},
+ new CbxItems(){ Key="使能",Text="使能"},
+ new CbxItems(){ Key="Anti_Sleep",Text="Anti_Sleep"},
+
+ new CbxItems(){ Key="PTC使能",Text="PTC使能"},
+ new CbxItems(){ Key="PTC功率",Text="PTC功率"},
+ new CbxItems(){ Key="PTC水流量",Text="PTC水流量"},
+ new CbxItems(){ Key="PTC水温",Text="PTC水温"},
+ };
+
+ ReadNameCbxItems = new ObservableCollection()
+ {
+ new CbxItems(){ Key="通讯Cmp转速",Text="通讯Cmp转速"},
+ new CbxItems(){ Key="通讯Cmp母线电压",Text="通讯Cmp母线电压"},
+ new CbxItems(){ Key="通讯Cmp母线电流",Text="通讯Cmp母线电流"},
+ new CbxItems(){ Key="通讯Cmp相电流",Text="通讯Cmp相电流"},
+ new CbxItems(){ Key="通讯Cmp功率",Text="通讯Cmp功率"},
+ new CbxItems(){ Key="通讯Cmp芯片温度",Text="通讯Cmp芯片温度"},
+
+ new CbxItems(){ Key="通讯PTC入水温度",Text="通讯PTC入水温度"},
+ new CbxItems(){ Key="通讯PTC出水温度",Text="通讯PTC出水温度"},
+ new CbxItems(){ Key="通讯PTC峰值电流",Text="通讯PTC峰值电流"},
+ new CbxItems(){ Key="通讯PTC母线电流",Text="通讯PTC母线电流"},
+ new CbxItems(){ Key="通讯PTC膜温",Text="通讯PTC膜温"},
+ new CbxItems(){ Key="通讯PTC模块温度",Text="通讯PTC模块温度"},
+ };
+ InitLoadCanConfigPro();
+
+ }
+
+
+ ///
+ /// FreeSQL 实例函数
+ ///
+ public IFreeSql FreeSql { get; }
+ public IEventAggregator EventAggregator { get; }
+ public IRegionManager RegionManager { get; }
+ public SysRunService SysRunService { get; }
+ public ComActionService ComActionService { get; }
+ public ConfigService ConfigService { get; }
+ public CanFdDriveService CanFdDriveService { get; }
+ public IMapper Mapper { get; }
+ private MachineRtDataService MachineRtDataService { get; }
+
+ ///
+ /// 弹窗服务
+ ///
+ public IDialogService DialogService { get; }
+
+
+
+ #region CanConfigPro
+
+ ///
+ /// 初始化j加载执行方法
+ ///
+ private void InitLoadCanConfigPro()
+ {
+ //CAN配置集合数据
+ canLinConfigPros = FreeSql.Select().Where(a => a.CANLINInfo == CANLIN.CANFD)
+ .Include(a => a.CANConfigExd)
+ .IncludeMany(a => a.CanLinConfigContents)
+ .ToList();
+
+ ListCanLinConfigPro = new ObservableCollection(canLinConfigPros);
+ if (SelectCanLinConfigPro != null)
+ {
+ SelectCanLinConfigPro = canLinConfigPros.Where(a => a.Id == SelectCanLinConfigPro.Id).FirstOrDefault()!;
+ //无数据就返回
+ if (SelectCanLinConfigPro == null) return;
+
+ SelectedCANConfigExdDto = Mapper.Map(SelectCanLinConfigPro!.CANConfigExd);
+
+ //配置信息
+ var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
+ if (WirteData != null && WirteData.Count > 0)
+ {
+ ListWriteCanLinRWConfigDto = new ObservableCollection(Mapper.Map>(WirteData));
+
+ //加载把当前的配置信息给指令
+ CanFdDriveService.CmdData.Clear();
+ foreach (var item in WirteData)
+ {
+ CanFdDriveService.AddCmdData(new CanCmdData()
+ {
+ ConfigName = item.Name,
+ MsgName = item.MsgFrameName,
+ SignalName = item.SignalName,
+ SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
+ });
+ //CanFdDriveService.CmdData.Add(new CanCmdData()
+ //{
+ // ConfigName = item.Name,
+ // MsgName = item.MsgFrameName,
+ // SignalName = item.SignalName,
+ // SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
+ //});
+ }
+ }
+ var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
+ if (ReadData != null && ReadData.Count > 0)
+ {
+ ListReadCanLinRWConfigDto = new ObservableCollection(Mapper.Map>(ReadData));
+ }
+
+ //匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListCanDbcModel
+ MatchSeletedAndCanDbcModel();
+ }
+ }
+
+ ///
+ /// 匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListCanDbcModel
+ /// 为了标注和着色使用
+ ///
+ private void MatchSeletedAndCanDbcModel()
+ {
+ //通过CanLinConfigContents标注ListCanDbcModel的选中状态属性,方便着色
+ if (ListCanDbcModel != null && ListCanDbcModel!.Count() > 0 && SelectCanLinConfigPro.CanLinConfigContents != null && SelectCanLinConfigPro.CanLinConfigContents.Count() > 0)
+ {
+ foreach (var itemCanDbcModel in ListCanDbcModel)
+ {
+ var FindData = SelectCanLinConfigPro.CanLinConfigContents.FindFirst(a => a.SignalName == itemCanDbcModel.SignalName);
+ if (FindData != null)//找到了就标注
+ {
+ switch (FindData.RWInfo)
+ {
+ case RW.Write:
+ itemCanDbcModel.IsSeletedInfo = 1;
+ break;
+ case RW.Read:
+ itemCanDbcModel.IsSeletedInfo = 2;
+ break;
+ default:
+ break;
+ }
+ }
+ else
+ {
+ //没有找到了就标注为0
+ itemCanDbcModel.IsSeletedInfo = 0;
+ }
+ }
+ }
+ }
+
+
+
+ private bool _IsCanConfigProActive = false;
+ ///
+ /// CAN 配置是否被激活
+ ///
+ public bool IsCanConfigProActive
+ {
+ get { return _IsCanConfigProActive; }
+ set { _IsCanConfigProActive = value; RaisePropertyChanged(); }
+ }
+
+ private bool _IsCANConfigDatagridActive = true;
+ ///
+ /// CANConfigDatagrid是否被触控
+ /// 关联IsCanConfigProActive 取反
+ ///
+ public bool IsCANConfigDatagridActive
+ {
+ get { return _IsCANConfigDatagridActive; }
+ set { _IsCANConfigDatagridActive = value; RaisePropertyChanged(); }
+ }
+
+ private string _SelectCanLinConfigProConfigName;
+ ///
+ /// 选中的 CanLinConfigPro 名称
+ ///
+ public string SelectCanLinConfigProConfigName
+ {
+ get { return _SelectCanLinConfigProConfigName; }
+ set { _SelectCanLinConfigProConfigName = value; RaisePropertyChanged(); }
+ }
+
+
+ private DelegateCommand _CanLinConfigPromdCmd;
+ ///
+ /// CanConfigPro操作的指令
+ ///
+ public DelegateCommand CanLinConfigPromdCmd
+ {
+ set
+ {
+ _CanLinConfigPromdCmd = value;
+ }
+ get
+ {
+ if (_CanLinConfigPromdCmd == null)
+ {
+ _CanLinConfigPromdCmd = new DelegateCommand((Par) => CanLinConfigPromdCmdMethod(Par));
+ }
+ return _CanLinConfigPromdCmd;
+ }
+ }
+ ///
+ /// CanConfigPro操作的指令方法
+ ///
+ ///
+ private void CanLinConfigPromdCmdMethod(string Par)
+ {
+ switch (Par)
+ {
+ case "Add":
+ //弹窗
+ DialogService.ShowDialog("DialogCanLinConfigCreateView", new DialogParameters() { { "Name", "" } }, (par) =>
+ {
+ if (par.Result == ButtonResult.OK)
+ {
+ //程序名称
+ var ReturnValue = par.Parameters.GetValue("Name");
+
+ //加载默认的数据 CANConfigExd
+ var InsertCANConfigExd = FreeSql.Insert(new CANConfigExd()
+ {
+ BaudRate = 250,
+ DbcPath = "请配置DBC路径",
+ Cycle = 100,
+ }).ExecuteInserted();
+
+ //返回数据,刷新Chart
+ var InsertData = FreeSql.Insert(new CanLinConfigPro()
+ {
+ ConfigName = ReturnValue,
+ CANLINInfo = CANLIN.CANFD,
+ CANConfigExdId = InsertCANConfigExd.FirstOrDefault()!.Id
+ }).ExecuteInserted();
+ if (InsertData != null)
+ {
+ //加载默认的数据 CanLinRWConfig
+ FreeSql.Insert(new CanLinRWConfig()
+ {
+ SignalName = "Speed",
+ DefautValue = "0",
+ Name = "转速",
+ RWInfo = RW.Write,
+ CanLinConfigProId = InsertData.FirstOrDefault().Id
+ }).ExecuteInserted();
+
+ FreeSql.Insert(new CanLinRWConfig()
+ {
+ SignalName = "Vol",
+ DefautValue = "0",
+ Name = "电压",
+ RWInfo = RW.Read,
+ CanLinConfigProId = InsertData.FirstOrDefault().Id
+
+ }).ExecuteInserted();
+ }
+
+ InitLoadCanConfigPro();
+
+ SelectCanLinConfigPro = canLinConfigPros!.Find(a => a.Id == InsertData.FirstOrDefault()!.Id);
+ }
+ else if (par.Result == ButtonResult.Cancel)
+ {
+ //取消
+
+ }
+
+ });
+
+ break;
+ case "Edit":
+ if (SelectCanLinConfigPro != null)
+ {
+ //弹窗
+ DialogService.ShowDialog("DialogCanLinConfigCreateView", new DialogParameters() { { "Name", SelectCanLinConfigPro.ConfigName } }, (par) =>
+ {
+ if (par.Result == ButtonResult.OK)
+ {
+ //程序名称
+ var ReturnValue = par.Parameters.GetValue("Name");
+
+ FreeSql.Update()
+ .Set(a => a.ConfigName, ReturnValue)
+ .Where(a => a.Id == SelectCanLinConfigPro.Id)
+ .ExecuteAffrows();
+
+ InitLoadCanConfigPro();
+
+ SelectCanLinConfigPro = null;
+ }
+ else if (par.Result == ButtonResult.Cancel)
+ {
+ //取消
+
+ }
+
+ });
+ }
+ else
+ {
+ System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ }
+ break;
+
+ case "Save":
+
+ case "Delete":
+ if (SelectCanLinConfigPro != null)
+ {
+ var repo = FreeSql.GetRepository();
+ repo.DbContextOptions.EnableCascadeSave = true; //关键设置
+
+ var DeleteData = repo.Select
+ .Include(a => a.CANConfigExd)
+ .IncludeMany(a => a.CanLinConfigContents)
+ .Where(a => a.Id == SelectCanLinConfigPro.Id)
+ .ToList();
+
+ repo.Delete(DeleteData);
+ foreach (var item in DeleteData)
+ {
+ FreeSql.Delete(item.CANConfigExdId).ExecuteAffrows();
+ }
+ InitLoadCanConfigPro();
+ }
+ else
+ {
+ System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ }
+ break;
+ case "Active":
+
+ //激活到取消的状态的判断
+ if (IsCanConfigProActive == true)
+ {
+ //控件的激活
+ IsCanConfigProActive = !IsCanConfigProActive;
+ //控件的激活配置信息
+ IsCANConfigDatagridActive = !IsCanConfigProActive;
+
+ return;
+ }
+
+ if ((CanFdDriveService.ToomossCanFDDrive.OpenState == true && CanFdDriveService.ToomossCanFDDrive.DbcParserState == true))
+ {
+ if (SelectCanLinConfigPro != null)
+ {
+ //控件的激活
+ IsCanConfigProActive = !IsCanConfigProActive;
+ //控件的激活配置信息
+ IsCANConfigDatagridActive = !IsCanConfigProActive;
+
+ //当前使用的CAN 配置信息
+ CanFdDriveService.InitCanConfig(SelectCanLinConfigPro);
+
+ InitLoadCanConfigPro();
+ }
+ else
+ {
+ System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ }
+
+ }
+ else
+ {
+ System.Windows.MessageBox.Show("请确保CAN连接打开和Dbc解析成功后再激活", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ ///
+ /// CAN List集合信息
+ ///
+ private List canLinConfigPros = new List();
+
+
+ private ObservableCollection _ListCanLinConfigPro;
+ ///
+ /// CAN 配置程序集合 ObservableCollection
+ ///
+ public ObservableCollection ListCanLinConfigPro
+ {
+ get { return _ListCanLinConfigPro; }
+ set { _ListCanLinConfigPro = value; RaisePropertyChanged(); }
+ }
+
+ ///
+ /// 选中的CanLinConfigPro
+ ///
+ public CanLinConfigPro SelectCanLinConfigPro { get; set; }
+
+ private DelegateCommand