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 _CanConfigProGridSelectionChangedCmd; + /// + /// CAN 配置程序 选中行数据命令 + /// + public DelegateCommand CanConfigProGridSelectionChangedCmd + { + set + { + _CanConfigProGridSelectionChangedCmd = value; + } + get + { + if (_CanConfigProGridSelectionChangedCmd == null) + { + _CanConfigProGridSelectionChangedCmd = new DelegateCommand((par) => CanConfigProGridSelectionChangedCmdMethod(par)); + } + return _CanConfigProGridSelectionChangedCmd; + } + } + private void CanConfigProGridSelectionChangedCmdMethod(object par) + { + if (par == null) + { + return; + } + if (par is SelectionChangedEventArgs) + { + return; + } + + if (par is CanLinConfigPro) + { + SelectCanLinConfigPro = par as CanLinConfigPro; + + //CANConfigExdDto 数据 + 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)); + } + + SelectCanLinConfigProConfigName = SelectCanLinConfigPro.ConfigName; + + return; + } + //先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件 + var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as CanLinConfigPro; + + if (Selecteddata != null) + { + SelectCanLinConfigPro = Selecteddata; + + SelectCanLinConfigProConfigName = SelectCanLinConfigPro.ConfigName; + + } + + + } + + + private DelegateCommand _CanConfigProGridPreviewMouseLeftButtonDownCmd; + /// + /// CAN 配置程序 选中行之前的数据命令 Preview + /// 防止CAN 打开后没有关闭就开始切换CAN 配置程序信息 + /// 要关闭后再切换 + /// + public DelegateCommand CanConfigProGridPreviewMouseLeftButtonDownCmd + { + set + { + _CanConfigProGridPreviewMouseLeftButtonDownCmd = value; + } + get + { + if (_CanConfigProGridPreviewMouseLeftButtonDownCmd == null) + { + _CanConfigProGridPreviewMouseLeftButtonDownCmd = new DelegateCommand((par) => CanConfigProGridPreviewMouseLeftButtonDownCmdMethod(par)); + } + return _CanConfigProGridPreviewMouseLeftButtonDownCmd; + } + } + /// + /// 防止CAN 打开后没有关闭就开始切换CAN 配置程序信息 + /// 要关闭后再切换 + /// + /// + private void CanConfigProGridPreviewMouseLeftButtonDownCmdMethod(object par) + { + if (par == null) + { + return; + } + if (par is System.Windows.Input.MouseButtonEventArgs) + { + var handler = par as System.Windows.Input.MouseButtonEventArgs; + + if (!CanFdDriveService.ToomossCanFDDrive.OpenState) + { + // 防止默认的行选择行为发生 + handler.Handled = false; + } + else + { + System.Windows.MessageBox.Show("关闭CAN连接后再点击切换CAN配置", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + handler.Handled = true; + } + } + } + + + #endregion + + #region Dbc操作 + + private ObservableCollection _ListCanDbcModel; + /// + /// Dbc消息集合 + /// + public ObservableCollection ListCanDbcModel + { + get { return _ListCanDbcModel; } + set { _ListCanDbcModel = value; RaisePropertyChanged(); } + } + + //private string _DbcFilePath; + ///// + ///// Dbc文件路径 + ///// + //public string DbcFilePath + //{ + // get { return _DbcFilePath; } + // set { _DbcFilePath = value; RaisePropertyChanged(); } + //} + + + private DelegateCommand _LoadDbcCmd; + /// + /// 下载Dbc文件指令 + /// + public DelegateCommand LoadDbcCmd + { + set + { + _LoadDbcCmd = value; + } + get + { + if (_LoadDbcCmd == null) + { + _LoadDbcCmd = new DelegateCommand(() => LoadDbcCmdMethod()); + } + return _LoadDbcCmd; + } + } + /// + /// 加载Dbc文件信息 + /// + private void LoadDbcCmdMethod() + { + //DbcFilePath + try + { + //var dd = ListQuickMeterStepDto; + + if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null) + { + OpenFileDialog OpenFileDialogInfo = new OpenFileDialog(); //new一个方法 + OpenFileDialogInfo.Filter = "(*.dbc;*.dbc)|*.dbc;*.dbc|all|*.*"; //删选、设定文件显示类型 + OpenFileDialogInfo.CheckFileExists = true; + OpenFileDialogInfo.CheckPathExists = true; + + OpenFileDialogInfo.ShowDialog(); //显示打开文件的窗口 + string fileName = OpenFileDialogInfo.FileName; //获得选择的文件路径 + + SelectedCANConfigExdDto.DbcPath = fileName; + } + else + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + + + + //System.Diagnostics.Process.Start(fileName);//打开指定路径下的文件 + } + catch (Exception ex) + { + System.Windows.MessageBox.Show("可能未选择信息", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand); + } + } + + + /// + /// 选中的CanDbcModel + /// + public CanDbcModel SelectedCanDbcModel { get; set; } + + private DelegateCommand _DbcGridSelectionChangedCmd; + /// + /// Dbc选中行数据命令 + /// + public DelegateCommand DbcGridSelectionChangedCmd + { + set + { + _DbcGridSelectionChangedCmd = value; + } + get + { + if (_DbcGridSelectionChangedCmd == null) + { + _DbcGridSelectionChangedCmd = new DelegateCommand((par) => DbcGridSelectionChangedCmdMethod(par)); + } + return _DbcGridSelectionChangedCmd; + } + } + private void DbcGridSelectionChangedCmdMethod(object par) + { + if (par == null) + { + return; + } + if (par is CanDbcModel) + { + SelectedCanDbcModel = par as CanDbcModel; + return; + } + + //(par as SelectionChangedEventArgs)!.AddedItems[0] == null + if ((par as SelectionChangedEventArgs)!.AddedItems.Count == 0) + { + return; + } + //先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件 + var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as CanDbcModel; + + if (Selecteddata != null) + { + SelectedCanDbcModel = Selecteddata; + + } + } + + + private DelegateCommand _DataGridMenuCmd; + /// + /// DataGridMenu 操作的指令 + /// + public DelegateCommand DataGridMenuCmd + { + set + { + _DataGridMenuCmd = value; + } + get + { + if (_DataGridMenuCmd == null) + { + _DataGridMenuCmd = new DelegateCommand((Par) => DataGridMenuCmdMethod(Par)); + } + return _DataGridMenuCmd; + } + } + /// + /// DataGridMenu 操作的指令 + /// + /// + private void DataGridMenuCmdMethod(string Par) + { + switch (Par) + { + case "Write": + if (SelectedCanDbcModel != null && SelectCanLinConfigPro != null) + { + FreeSql.Insert(new CanLinRWConfig() + { + Name = "", + SignalName = SelectedCanDbcModel.SignalName, + MsgFrameName = SelectedCanDbcModel.MsgName, + CanLinConfigProId = SelectCanLinConfigPro.Id, + DefautValue = "", + RWInfo = RW.Write, + }).ExecuteInserted(); + + InitLoadCanConfigPro(); + } + break; + case "Read": + if (SelectedCanDbcModel != null && SelectCanLinConfigPro != null) + { + FreeSql.Insert(new CanLinRWConfig() + { + Name = "", + SignalName = SelectedCanDbcModel.SignalName, + MsgFrameName = SelectedCanDbcModel.MsgName, + CanLinConfigProId = SelectCanLinConfigPro.Id, + DefautValue = "", + RWInfo = RW.Read, + }).ExecuteInserted(); + + InitLoadCanConfigPro(); + } + break; + default: + break; + } + } + + + + #endregion + + #region CAN操作 + + private CANConfigExdDto _SelectedCANConfigExdDto; + /// + /// 选中的CAN操作 + /// + public CANConfigExdDto SelectedCANConfigExdDto + { + get { return _SelectedCANConfigExdDto; } + set { _SelectedCANConfigExdDto = value; RaisePropertyChanged(); } + } + + private DelegateCommand _CanOpCmd; + /// + /// CAN操作的指令 + /// + public DelegateCommand CanOpCmd + { + set + { + _CanOpCmd = value; + } + get + { + if (_CanOpCmd == null) + { + _CanOpCmd = new DelegateCommand((Par) => CanOpCmdMethod(Par)); + } + return _CanOpCmd; + } + } + /// + /// CAN操作的指令方法 + /// + /// + private void CanOpCmdMethod(string Par) + { + switch (Par) + { + case "Open": + if (ComActionService.IsCanToDoWork() == false) + { + System.Windows.MessageBox.Show("请关闭LIN连接后才能开启CAN,同一个时刻只能有一个通信驱动压缩机", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + return; + } + if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null) + { + //打开连接 + CanFdDriveService.ToomossCanFDDrive.StartCanDrive(); + //成功后状态显示 + if (CanFdDriveService.ToomossCanFDDrive.OpenState) + { + //系统使用了CAN + ConfigService.CanLinRunStateModel.CurSysSelectedCanLin = CanLinEnum.Can; + } + + //CAN DBC配置 有DBC配置的话,则直接加载DBC信息 + if (!string.IsNullOrEmpty(SelectCanLinConfigPro.CANConfigExd.DbcPath)) + { + var DbcData = CanFdDriveService.StartDbc(SelectedCANConfigExdDto.DbcPath); + ListCanDbcModel = DbcData; + + //ListCanDbcModel有数据后就要看看是否有配置信息,有的话就要标注 + //匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListCanDbcModel + MatchSeletedAndCanDbcModel(); + + } + + } + else + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + break; + case "Close": + if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null) + { + + CanFdDriveService.ToomossCanFDDrive.CloseDevice(); + //系统取消使用了CAN + ConfigService.CanLinRunStateModel.CurSysSelectedCanLin = CanLinEnum.No; + } + else + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + break; + case "Save": + if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null) + { + //保存Can 配置 + if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath)) + { + var Update = FreeSql.Update() + .Set(a => a.DbcPath, SelectedCANConfigExdDto.DbcPath) + .Set(a => a.Cycle, SelectedCANConfigExdDto.Cycle) + .Set(a => a.BaudRate, SelectedCANConfigExdDto.BaudRate) + .Where(a => a.Id == SelectedCANConfigExdDto.Id) + .ExecuteUpdated(); + } + + InitLoadCanConfigPro(); + } + else + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + break; + case "Parse": + if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null) + { + //打开之后连接 + if (CanFdDriveService.ToomossCanFDDrive.OpenState) + { + //CAN DBC配置 有DBC配置的话,则加载DBC信息 + if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath)) + { + var DbcData = CanFdDriveService.StartDbc(SelectedCANConfigExdDto.DbcPath); + + ListCanDbcModel = DbcData; + } + else + { + System.Windows.MessageBox.Show("请选择DBC文件后再操作", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand); + } + } + // ListCanDbcModel = new ObservableCollection() + //{ + // new CanDbcModel(){ MsgName="DSDF1",SignalName="FASDFA11",Publisher="DFAD1",SignalDesc="ASDFASD1"}, + // new CanDbcModel(){ MsgName="DSDF2",SignalName="FASDFA22",Publisher="DFAD2",SignalDesc="ASDFASD2"}, + // new CanDbcModel(){ MsgName="DSDF3",SignalName="FASDFA33",Publisher="DFAD3",SignalDesc="ASDFASD3"}, + // new CanDbcModel(){ MsgName="DSDF4",SignalName="FASDFA44",Publisher="DFAD4",SignalDesc="ASDFASD4"}, + // new CanDbcModel(){ MsgName="DSDF5",SignalName="FASDFA55",Publisher="DFAD5",SignalDesc="ASDFASD5"}, + //}; + // return; + + } + else + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + break; + + case "HandSend"://手动发送 + + //手动发送数据 + CanFdDriveService.SendMsgToCanDrive(HandSpeed); + + //CanFdDriveService.ToomossCanFDDrive.SendCanMsg(new List() + //{ + // new CanCmdData(){ MsgName="TX1",SignalName="COM_current_Power",SignalCmdValue=12}, + // new CanCmdData(){ MsgName="TX1",SignalName="COM_Curr_dc",SignalCmdValue=12}, + //}); + + break; + case "CycleSend"://循环发送你 + //循环发送数据 + CanFdDriveService.CycleSendMsg(); + + //Listen + break; + case "CycleRecive": + CanFdDriveService.CycleReciveMsg(); + + //Listen + break; + default: + break; + } + } + + + private double _HandSpeed; + /// + /// 手动转速数据 + /// + public double HandSpeed + { + get { return _HandSpeed; } + set { _HandSpeed = value; RaisePropertyChanged(); } + } + + + #endregion + + + #region 写入和读取操作 + + private ObservableCollection _WriteNameCbxItems; + /// + /// 写入的Name + /// + public ObservableCollection WriteNameCbxItems + { + get { return _WriteNameCbxItems; } + set { _WriteNameCbxItems = value; RaisePropertyChanged(); } + } + + + private ObservableCollection _ReadNameCbxItems; + /// + /// 写入的Name + /// + public ObservableCollection ReadNameCbxItems + { + get { return _ReadNameCbxItems; } + set { _ReadNameCbxItems = value; RaisePropertyChanged(); } + } + + + //private string _SelectedWriteName; + ///// + ///// 选中的写入的Name + ///// + //public string SelectedWriteName + //{ + // get { return _SelectedWriteName; } + // set { _SelectedWriteName = value; RaisePropertyChanged(); } + //} + + //private string _SelectedReadName; + ///// + ///// 选中的读取的Name + ///// + //public string SelectedReadName + //{ + // get { return _SelectedReadName; } + // set { _SelectedReadName = value; RaisePropertyChanged(); } + //} + + + private ObservableCollection _ListWriteCanLinRWConfigDto; + /// + /// CAN写入集合数据 + /// + public ObservableCollection ListWriteCanLinRWConfigDto + { + get { return _ListWriteCanLinRWConfigDto; } + set { _ListWriteCanLinRWConfigDto = value; RaisePropertyChanged(); } + } + + /// + /// 选中的CanLinRWConfigDto行 Write + /// + private CanLinRWConfigDto SelectedWriteCanLinRWConfigDto { get; set; } + + private DelegateCommand _WriteGridSelectionChangedCmd; + /// + /// 写入CAN的选中行的命令 + /// + public DelegateCommand WriteGridSelectionChangedCmd + { + set + { + _WriteGridSelectionChangedCmd = value; + } + get + { + if (_WriteGridSelectionChangedCmd == null) + { + _WriteGridSelectionChangedCmd = new DelegateCommand((Par) => WriteGridSelectionChangedCmdMethod(Par)); + } + return _WriteGridSelectionChangedCmd; + } + } + /// + /// 写入CAN的选中行执行方法 + /// + /// + /// + private void WriteGridSelectionChangedCmdMethod(object par) + { + if (par is CanLinRWConfigDto) + { + SelectedWriteCanLinRWConfigDto = par as CanLinRWConfigDto; + } + } + + private DelegateCommand _WriteCmd; + /// + /// 写入操作的指令 + /// + public DelegateCommand WriteCmd + { + set + { + _WriteCmd = value; + } + get + { + if (_WriteCmd == null) + { + _WriteCmd = new DelegateCommand((Par) => WriteCmdMethod(Par)); + } + return _WriteCmd; + } + } + /// + /// 写入操作的指令方法 + /// + /// + private void WriteCmdMethod(string Par) + { + if (SelectCanLinConfigPro == null) + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + return; + } + + + switch (Par) + { + case "Add": + //由右侧的右键DBC目录增加 + + break; + case "Edit": + if (ListWriteCanLinRWConfigDto != null && ListWriteCanLinRWConfigDto.Count() > 0) + { + foreach (var item in ListWriteCanLinRWConfigDto) + { + //直接修改 + FreeSql.Update(item.Id) + .Set(a => a.Name, item.Name) + .Set(a => a.DefautValue, item.DefautValue) + .ExecuteAffrows(); + //ListWriteCanLinRWConfigDto.Remove(SelectedWriteCanLinRWConfigDto); + + //SelectedWriteCanLinRWConfigDto = null; + + } + + InitLoadCanConfigPro(); + } + + + + break; + case "Delete": + if (SelectedWriteCanLinRWConfigDto != null) + { + //直接删除掉 + FreeSql.Delete(SelectedWriteCanLinRWConfigDto.Id).ExecuteAffrows(); + ListWriteCanLinRWConfigDto.Remove(SelectedWriteCanLinRWConfigDto); + + SelectedWriteCanLinRWConfigDto = null; + + InitLoadCanConfigPro(); + } + else + { + System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + break; + default: + break; + } + } + + + + + + private ObservableCollection _ListReadCanLinRWConfigDto; + /// + /// CAN读取集合数据 + /// + public ObservableCollection ListReadCanLinRWConfigDto + { + get { return _ListReadCanLinRWConfigDto; } + set { _ListReadCanLinRWConfigDto = value; RaisePropertyChanged(); } + } + + /// + /// 选中的CanLinRWConfigDto行 Read + /// + private CanLinRWConfigDto SelectedReadCanLinRWConfigDto { get; set; } + + private DelegateCommand _ReadGridSelectionChangedCmd; + /// + /// 写入CAN的选中行的命令 + /// + public DelegateCommand ReadGridSelectionChangedCmd + { + set + { + _ReadGridSelectionChangedCmd = value; + } + get + { + if (_ReadGridSelectionChangedCmd == null) + { + _ReadGridSelectionChangedCmd = new DelegateCommand((Par) => ReadGridSelectionChangedCmdMethod(Par)); + } + return _ReadGridSelectionChangedCmd; + } + } + /// + /// 读取CAN的选中行执行方法 + /// + /// + /// + private void ReadGridSelectionChangedCmdMethod(object par) + { + if (par is CanLinRWConfigDto) + { + SelectedReadCanLinRWConfigDto = par as CanLinRWConfigDto; + } + } + + + + private DelegateCommand _ReadCmd; + /// + /// 读取操作的指令 + /// + public DelegateCommand ReadCmd + { + set + { + _ReadCmd = value; + } + get + { + if (_ReadCmd == null) + { + _ReadCmd = new DelegateCommand((Par) => ReadCmdMethod(Par)); + } + return _ReadCmd; + } + } + /// + /// 读取操作的指令方法 + /// + /// + private void ReadCmdMethod(string Par) + { + if (SelectCanLinConfigPro == null) + { + System.Windows.MessageBox.Show("选中CAN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + return; + } + + switch (Par) + { + case "Add": + //由右侧的右键DBC目录增加 + + break; + case "Edit": + if (ListReadCanLinRWConfigDto != null && ListReadCanLinRWConfigDto.Count() > 0) + { + foreach (var item in ListReadCanLinRWConfigDto) + { + //直接修改 + FreeSql.Update(item.Id) + .Set(a => a.Name, item.Name) + .Set(a => a.DefautValue, item.DefautValue) + .ExecuteAffrows(); + //ListReadCanLinRWConfigDto.Remove(SelectedReadCanLinRWConfigDto); + + //SelectedReadCanLinRWConfigDto = null; + + } + + InitLoadCanConfigPro(); + } + + + + break; + case "Delete": + if (SelectedReadCanLinRWConfigDto != null) + { + //直接删除掉 + FreeSql.Delete(SelectedReadCanLinRWConfigDto.Id).ExecuteAffrows(); + ListReadCanLinRWConfigDto.Remove(SelectedReadCanLinRWConfigDto); + + SelectedReadCanLinRWConfigDto = null; + + InitLoadCanConfigPro(); + } + else + { + System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); + } + + break; + default: + break; + } + } + + #endregion + } +} diff --git a/CapMachine.Wpf/Views/CANFDConfigView.xaml b/CapMachine.Wpf/Views/CANFDConfigView.xaml new file mode 100644 index 0000000..f9f7e02 --- /dev/null +++ b/CapMachine.Wpf/Views/CANFDConfigView.xaml @@ -0,0 +1,999 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CapMachine.Wpf/Views/CANFDConfigView.xaml.cs b/CapMachine.Wpf/Views/CANFDConfigView.xaml.cs new file mode 100644 index 0000000..84a4c0d --- /dev/null +++ b/CapMachine.Wpf/Views/CANFDConfigView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace CapMachine.Wpf.Views +{ + /// + /// CANFDConfigView.xaml 的交互逻辑 + /// + public partial class CANFDConfigView : UserControl + { + public CANFDConfigView() + { + InitializeComponent(); + } + } +}