diff --git a/CapMachine.Wpf/App.xaml.cs b/CapMachine.Wpf/App.xaml.cs index fdfa8b4..6150690 100644 --- a/CapMachine.Wpf/App.xaml.cs +++ b/CapMachine.Wpf/App.xaml.cs @@ -95,9 +95,9 @@ namespace CapMachine.Wpf containerRegistry.RegisterSingleton(); ////注册设备服务 //containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); - containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); containerRegistry.RegisterSingleton(); diff --git a/CapMachine.Wpf/CanDrive/ToomossCan.cs b/CapMachine.Wpf/CanDrive/ToomossCan.cs index b90cbf3..930cdde 100644 --- a/CapMachine.Wpf/CanDrive/ToomossCan.cs +++ b/CapMachine.Wpf/CanDrive/ToomossCan.cs @@ -372,6 +372,7 @@ namespace CapMachine.Wpf.CanDrive /// /// 发送CAN数据 + /// 发送一次 /// public void SendCanMsg(List CmdData) { diff --git a/CapMachine.Wpf/Services/CanDriveService.cs b/CapMachine.Wpf/Services/CanDriveService.cs index 5ecfe3b..49535db 100644 --- a/CapMachine.Wpf/Services/CanDriveService.cs +++ b/CapMachine.Wpf/Services/CanDriveService.cs @@ -78,28 +78,96 @@ namespace CapMachine.Wpf.Services #region 程序驱动CAN + /// + /// 转速 指令数据 实例 + /// + private CanCmdData SpeedCanCmdData { get; set; } + + /// + /// 功率限制 指令数据 实例 + /// + private CanCmdData PwLimitCanCmdData { get; set; } + + /// + /// 使能 指令数据 实例 + /// + private CanCmdData EnableCanCmdData { get; set; } + /// /// 要发送的CAN指令数据 /// 在程序配置好后就确定要发送哪些数据 /// public List CmdData { get; set; } = new List(); + /// + /// 增加发送的指令数据 + /// + /// + public void AddCmdData(CanCmdData SendCanCmdData) + { + //提取常用的实例数据 + switch (SendCanCmdData.ConfigName) + { + case "转速": + SpeedCanCmdData = SendCanCmdData; + break; + case "功率限制": + PwLimitCanCmdData = SendCanCmdData; + break; + case "使能": + EnableCanCmdData = SendCanCmdData; + break; + case "Anti_Sleep": + //SpeedCanCmdData = SendCanCmdData; + break; + default: + break; + } + //添加到发送数据集合 + CmdData.Add(SendCanCmdData); + } + + + /// + /// 更新速度信息 + /// 默认是启动 + /// + /// + public void UpdateSpeedCmdData(double SpeedData) + { + if (SpeedCanCmdData != null) + { + SpeedCanCmdData.SignalCmdValue = SpeedData; + } + if (EnableCanCmdData!=null) + { + EnableCanCmdData.SignalCmdValue = 1; + } + } + + /// /// 发送消息给CAN 驱动 /// - public void SendMsgToCanDrive() + public void SendMsgToCanDrive(double SpeedData) { if (ToomossCanDrive.OpenState) { if (CmdData.Count > 0) { + //更新速度信息 + UpdateSpeedCmdData(SpeedData); + ToomossCanDrive.SendCanMsg(CmdData); } else { System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); } - + } + else + { + System.Windows.MessageBox.Show("未打开CAN通信,无法发送数据", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand); } } diff --git a/CapMachine.Wpf/Services/MachineRtDataService.cs b/CapMachine.Wpf/Services/MachineRtDataService.cs index edaa3f7..b49d336 100644 --- a/CapMachine.Wpf/Services/MachineRtDataService.cs +++ b/CapMachine.Wpf/Services/MachineRtDataService.cs @@ -35,6 +35,8 @@ namespace CapMachine.Wpf.Services /// private IEventAggregator _EventAggregator { get; set; } public AlarmService AlarmService { get; } + public CanDriveService CanDriveService { get; } + public SysRunService SysRunService { get; } /// /// PLCScanTask扫描Task @@ -105,7 +107,7 @@ namespace CapMachine.Wpf.Services /// 实例化函数 /// /// - public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService)//, AlarmService alarmService + public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService, CanDriveService canDriveService, SysRunService sysRunService)//, AlarmService alarmService { //ConcurrentDictionary keyValuePairs = new ConcurrentDictionary(); @@ -119,6 +121,8 @@ namespace CapMachine.Wpf.Services //事件服务 _EventAggregator = eventAggregator; AlarmService = alarmService; + CanDriveService = canDriveService; + SysRunService = sysRunService; //秒触发一次 CycleTimer = new System.Timers.Timer(500); @@ -1115,8 +1119,9 @@ namespace CapMachine.Wpf.Services if (OperateResultShort.IsSuccess) { TagManger.GetTagInfoValueByName(itemTag.Value.Name)!.Value = SiemensDrive.ReadInt16(itemTag.Value.PVAddress).Content; - TagManger.GetTagByName(itemTag.Value.Name).EngPvValue = TagManger.GetTagInfoValueByName(itemTag.Value.Name)!.Value * 1.0 / TagManger.GetTagByName(itemTag.Value.Name)!.Precision; + TagManger.GetTagByName(itemTag.Value.Name)!.EngPvValue = TagManger.GetTagInfoValueByName(itemTag.Value.Name)!.Value * 1.0 / TagManger.GetTagByName(itemTag.Value.Name)!.Precision; LinkState = true; + } else { @@ -1130,8 +1135,15 @@ namespace CapMachine.Wpf.Services if (OperateResultSVShort.IsSuccess) { //TagManger.GetTagInfoValueByName(itemTag.Value.Name)!.Value = OperateResultSVShort.Content; - TagManger.GetTagByName(itemTag.Value.Name).EngSvValue = OperateResultSVShort.Content * 1.0 / TagManger.GetTagByName(itemTag.Value.Name)!.Precision; + TagManger.GetTagByName(itemTag.Value.Name)!.EngSvValue = OperateResultSVShort.Content * 1.0 / TagManger.GetTagByName(itemTag.Value.Name)!.Precision; LinkState = true; + + //在运行时,更新速度的SV的值 + if (itemTag.Value.Name == "转速[rpm]" && SysRunService.MachineRunState1.RunStateMsg == "运行") + { + //更新SV的速度值 + CanDriveService.UpdateSpeedCmdData(TagManger.GetTagByName(itemTag.Value.Name)!.EngSvValue); + } } else { @@ -1145,7 +1157,7 @@ namespace CapMachine.Wpf.Services if (OperateResultMVShort.IsSuccess) { //TagManger.GetTagInfoValueByName(itemTag.Value.Name)!.Value = OperateResultMVShort.Content; - TagManger.GetTagByName(itemTag.Value.Name).EngMvValue = OperateResultMVShort.Content*1.0/10; + TagManger.GetTagByName(itemTag.Value.Name)!.EngMvValue = OperateResultMVShort.Content * 1.0 / 10; LinkState = true; } else @@ -1155,8 +1167,8 @@ namespace CapMachine.Wpf.Services } //手自动切换按钮条件 - AutoHandSwtichConditionState.AlarmStateResult= SiemensDrive.ReadBool(AutoHandSwtichConditionState.AlarmAddress); - AutoHandSwtichConditionState.HandStateResult= SiemensDrive.ReadBool(AutoHandSwtichConditionState.HandStateAddress); + AutoHandSwtichConditionState.AlarmStateResult = SiemensDrive.ReadBool(AutoHandSwtichConditionState.AlarmAddress); + AutoHandSwtichConditionState.HandStateResult = SiemensDrive.ReadBool(AutoHandSwtichConditionState.HandStateAddress); AutoHandSwtichConditionState.SumResult(); break; diff --git a/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs b/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs index 60335c6..3c5feee 100644 --- a/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs +++ b/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs @@ -120,13 +120,20 @@ namespace CapMachine.Wpf.ViewModels CanDriveService.CmdData.Clear(); foreach (var item in WirteData) { - CanDriveService.CmdData.Add(new CanCmdData() + CanDriveService.AddCmdData(new CanCmdData() { ConfigName = item.Name, MsgName = item.MsgFrameName, SignalName = item.SignalName, SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0, }); + //CanDriveService.CmdData.Add(new CanCmdData() + //{ + // ConfigName = item.Name, + // MsgName = item.MsgFrameName, + // SignalName = item.SignalName, + // SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0, + //}); } } @@ -411,13 +418,21 @@ namespace CapMachine.Wpf.ViewModels CanDriveService.CmdData.Clear(); foreach (var item in WirteData) { - CanDriveService.CmdData.Add(new CanCmdData() + CanDriveService.AddCmdData(new CanCmdData() { ConfigName = item.Name, MsgName = item.MsgFrameName, SignalName = item.SignalName, SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0, }); + + //CanDriveService.CmdData.Add(new CanCmdData() + //{ + // ConfigName = item.Name, + // MsgName = item.MsgFrameName, + // SignalName = item.SignalName, + // SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0, + //}); } } @@ -829,7 +844,7 @@ namespace CapMachine.Wpf.ViewModels case "HandSend"://手动发送 //手动发送数据 - CanDriveService.SendMsgToCanDrive(); + CanDriveService.SendMsgToCanDrive(HandSpeed); //CanDriveService.ToomossCanDrive.SendCanMsg(new List() //{ @@ -854,6 +869,18 @@ namespace CapMachine.Wpf.ViewModels } } + + private double _HandSpeed; + /// + /// 手动转速数据 + /// + public double HandSpeed + { + get { return _HandSpeed; } + set { _HandSpeed = value; RaisePropertyChanged(); } + } + + #endregion diff --git a/CapMachine.Wpf/Views/CANConfigView.xaml b/CapMachine.Wpf/Views/CANConfigView.xaml index a2a5314..93c4e44 100644 --- a/CapMachine.Wpf/Views/CANConfigView.xaml +++ b/CapMachine.Wpf/Views/CANConfigView.xaml @@ -420,6 +420,33 @@ + + + + + + -