增加CAN FD和规则的功能
This commit is contained in:
415
CapMachine.Wpf/Services/CanFdDriveService.cs
Normal file
415
CapMachine.Wpf/Services/CanFdDriveService.cs
Normal file
@@ -0,0 +1,415 @@
|
||||
using CapMachine.Model.CANLIN;
|
||||
using CapMachine.Wpf.CanDrive;
|
||||
using CapMachine.Wpf.Models;
|
||||
using CapMachine.Wpf.Models.ProModelPars;
|
||||
using ImTools;
|
||||
using Prism.Ioc;
|
||||
using Prism.Mvvm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapMachine.Wpf.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Can FD驱动服务
|
||||
/// </summary>
|
||||
public class CanFdDriveService : BindableBase
|
||||
{
|
||||
public HighSpeedDataService HighSpeedDataService { get; }
|
||||
public LogicRuleService LogicRuleService { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// </summary>
|
||||
public CanFdDriveService(HighSpeedDataService highSpeedDataService, IContainerProvider containerProvider, LogicRuleService logicRuleService)
|
||||
{
|
||||
ToomossCanFDDrive = new ToomossCanFD(containerProvider);
|
||||
//高速数据服务
|
||||
HighSpeedDataService = highSpeedDataService;
|
||||
LogicRuleService = logicRuleService;
|
||||
|
||||
//ToomossCanFDDrive.StartCanDrive();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前选中的CanLinConfigPro 程序
|
||||
/// </summary>
|
||||
public CanLinConfigPro SelectedCanLinConfigPro { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图莫斯 CAN Drive
|
||||
/// ToomossCanFDDrive
|
||||
/// </summary>
|
||||
public ToomossCanFD ToomossCanFDDrive { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dbc消息集合
|
||||
/// 包括读取的实时值和数据
|
||||
/// </summary>
|
||||
public ObservableCollection<CanDbcModel> ListCanDbcModel { get; set; } = new ObservableCollection<CanDbcModel>();
|
||||
|
||||
/// <summary>
|
||||
/// 初始化CAN的配置信息
|
||||
/// </summary>
|
||||
public void InitCanConfig(CanLinConfigPro selectedCanLinConfigPro)
|
||||
{
|
||||
//赋值配置数据
|
||||
SelectedCanLinConfigPro = selectedCanLinConfigPro;
|
||||
//为DBC实时数据关联配置的名称
|
||||
foreach (var item in SelectedCanLinConfigPro.CanLinConfigContents)
|
||||
{
|
||||
var FindData = ListCanDbcModel.FindFirst(a => a.SignalName == item.SignalName);
|
||||
if (FindData != null)
|
||||
{
|
||||
FindData.Name = item.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始DBC 配置文件 加载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ObservableCollection<CanDbcModel> StartDbc(string Path)
|
||||
{
|
||||
ListCanDbcModel = ToomossCanFDDrive.StartDbc(Path);
|
||||
return ListCanDbcModel;
|
||||
}
|
||||
|
||||
|
||||
#region 程序驱动CAN
|
||||
|
||||
/// <summary>
|
||||
/// 转速 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData SpeedCanCmdData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 功率限制 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData PwLimitCanCmdData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使能 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData EnableCanCmdData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PTC使能 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData PTCEnableCanCmdData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PTC功率 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData PTCPwCanCmdData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PTC水流量 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData PTCFlowCanCmdData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// PTC水温 指令数据 实例
|
||||
/// </summary>
|
||||
private CanCmdData PTCWaterTempCanCmdData { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 要发送的CAN指令数据
|
||||
/// 在程序配置好后就确定要发送哪些数据
|
||||
/// </summary>
|
||||
public List<CanCmdData> CmdData { get; set; } = new List<CanCmdData>();
|
||||
|
||||
/// <summary>
|
||||
/// 增加发送的指令数据
|
||||
/// </summary>
|
||||
/// <param name="canCmdData"></param>
|
||||
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;
|
||||
case "PTC使能":
|
||||
PTCEnableCanCmdData = SendCanCmdData;
|
||||
break;
|
||||
case "PTC功率":
|
||||
PTCPwCanCmdData = SendCanCmdData;
|
||||
break;
|
||||
case "PTC水流量":
|
||||
PTCFlowCanCmdData = SendCanCmdData;
|
||||
break;
|
||||
case "PTC水温":
|
||||
PTCWaterTempCanCmdData = SendCanCmdData;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//添加到发送数据集合
|
||||
CmdData.Add(SendCanCmdData);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新速度信息
|
||||
/// 默认是启动
|
||||
/// </summary>
|
||||
/// <param name="canCmdData"></param>
|
||||
public void UpdateSpeedCmdData(double SpeedData)
|
||||
{
|
||||
if (SpeedCanCmdData != null)
|
||||
{
|
||||
if (SpeedCanCmdData.LogicRuleDto == null)
|
||||
{
|
||||
//没有启动逻辑规则处理
|
||||
SpeedCanCmdData.SignalCmdValue = SpeedData;
|
||||
return;
|
||||
}
|
||||
|
||||
SpeedCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(SpeedData, SpeedCanCmdData.LogicRuleDto);
|
||||
}
|
||||
//if (EnableCanCmdData != null)
|
||||
//{
|
||||
// EnableCanCmdData.SignalCmdValue = 1;
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新压缩机使能数据
|
||||
/// </summary>
|
||||
/// <param name="IsEnable"></param>
|
||||
public void UpdateCapEnableCmdData(bool IsEnable)
|
||||
{
|
||||
if (EnableCanCmdData != null)
|
||||
{
|
||||
EnableCanCmdData.SignalCmdValue = IsEnable ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新压缩机的功率限制
|
||||
/// </summary>
|
||||
/// <param name="IsEnable"></param>
|
||||
public void UpdateCapPwLimitCmdData(double PwLimit)
|
||||
{
|
||||
if (PwLimitCanCmdData != null)
|
||||
{
|
||||
if (PwLimitCanCmdData.LogicRuleDto == null)
|
||||
{
|
||||
PwLimitCanCmdData.SignalCmdValue = PwLimit;
|
||||
return;
|
||||
}
|
||||
PwLimitCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(PwLimit, PwLimitCanCmdData.LogicRuleDto!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新 PTC使能信号
|
||||
/// </summary>
|
||||
/// <param name="IsEnable"></param>
|
||||
public void UpdateCapPTCEnableCmdData(bool IsEnable)
|
||||
{
|
||||
if (PTCEnableCanCmdData != null)
|
||||
{
|
||||
PTCEnableCanCmdData.SignalCmdValue = IsEnable ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 PTC功率 信号
|
||||
/// </summary>
|
||||
/// <param name="IsEnable"></param>
|
||||
public void UpdateCapPTCPwCmdData(double PTCPw)
|
||||
{
|
||||
if (PTCPwCanCmdData != null)
|
||||
{
|
||||
if (PTCPwCanCmdData.LogicRuleDto == null)
|
||||
{
|
||||
PTCPwCanCmdData.SignalCmdValue = PTCPw;
|
||||
return;
|
||||
}
|
||||
PTCPwCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(PTCPw, PTCPwCanCmdData.LogicRuleDto!);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 PTC水流量 信号
|
||||
/// </summary>
|
||||
/// <param name="IsEnable"></param>
|
||||
public void UpdateCapPTCFlowCmdData(double Flow)
|
||||
{
|
||||
if (PTCFlowCanCmdData != null)
|
||||
{
|
||||
if (PTCFlowCanCmdData.LogicRuleDto == null)
|
||||
{
|
||||
PTCFlowCanCmdData.SignalCmdValue = Flow;
|
||||
return;
|
||||
}
|
||||
PTCFlowCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(Flow, PTCFlowCanCmdData.LogicRuleDto!);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新 PTC水温 信号
|
||||
/// </summary>
|
||||
/// <param name="IsEnable"></param>
|
||||
public void UpdateCapPTCWaterTempCmdData(double WaterTemp)
|
||||
{
|
||||
if (PTCWaterTempCanCmdData != null)
|
||||
{
|
||||
if (PTCWaterTempCanCmdData.LogicRuleDto == null)
|
||||
{
|
||||
PTCWaterTempCanCmdData.SignalCmdValue = WaterTemp;
|
||||
return;
|
||||
}
|
||||
PTCWaterTempCanCmdData.SignalCmdValue = LogicRuleService.ApplyExpressionFast(WaterTemp, PTCWaterTempCanCmdData.LogicRuleDto!);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息给CAN 驱动
|
||||
/// </summary>
|
||||
public void SendMsgToCanDrive(double SpeedData)
|
||||
{
|
||||
if (ToomossCanFDDrive.OpenState)
|
||||
{
|
||||
if (CmdData.Count > 0)
|
||||
{
|
||||
//更新速度信息
|
||||
UpdateSpeedCmdData(SpeedData);
|
||||
|
||||
ToomossCanFDDrive.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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 循环发送数据到CAN
|
||||
/// </summary>
|
||||
public void CycleSendMsg()
|
||||
{
|
||||
if (ToomossCanFDDrive.OpenState)
|
||||
{
|
||||
if (ToomossCanFDDrive.IsCycleSend == false)
|
||||
{
|
||||
if (CmdData.Count > 0)
|
||||
{
|
||||
ToomossCanFDDrive.IsCycleSend = true;
|
||||
ToomossCanFDDrive.CmdData = CmdData;
|
||||
//ToomossCanFDDrive.StartCycleSendMsg();
|
||||
ToomossCanFDDrive.StartPrecisionCycleSendMsg();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ToomossCanFDDrive.IsCycleSend = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///循环接收数据
|
||||
/// </summary>
|
||||
public void CycleReciveMsg()
|
||||
{
|
||||
if (ToomossCanFDDrive.OpenState)
|
||||
{
|
||||
if (ToomossCanFDDrive.IsCycleRevice == false)
|
||||
{
|
||||
if (ListCanDbcModel.Count > 0)
|
||||
{
|
||||
ToomossCanFDDrive.IsCycleRevice = true;
|
||||
ToomossCanFDDrive.StartCycleReviceCanMsg();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("未发现配置的数据内容", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ToomossCanFDDrive.IsCycleRevice = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取数据值
|
||||
/// 从DBC中获取数据给数据中心集合
|
||||
/// </summary>
|
||||
/// <param name="Name"></param>
|
||||
/// <returns></returns>
|
||||
public double GetDbcValueByName(string Name)
|
||||
{
|
||||
if (!ToomossCanFDDrive.IsCycleRevice) return 0;
|
||||
|
||||
if (ListCanDbcModel.Any(a => a.Name == Name))
|
||||
{
|
||||
//double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1);
|
||||
return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
//return 12.3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 速度的数据的获取
|
||||
/// 获取速度数据值
|
||||
/// 从DBC中获取Speed数据给数据中心集合
|
||||
/// </summary>
|
||||
/// <param name="Name"></param>
|
||||
/// <returns></returns>
|
||||
public double GetDbcSpeedValueBySpeedName(string Name)
|
||||
{
|
||||
if (!ToomossCanFDDrive.IsCycleRevice) return 0;
|
||||
|
||||
if (ListCanDbcModel.Any(a => a.Name == Name))
|
||||
{
|
||||
//double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue, out double Result1);
|
||||
//return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
return double.TryParse(ListCanDbcModel.FindFirst(a => a.Name == Name).SignalRtValue.Split(" ")[0], out double Result) == true ? Result : 0;
|
||||
//return 2300;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.Services
|
||||
{
|
||||
@@ -61,6 +62,14 @@ namespace CapMachine.Wpf.Services
|
||||
case "过热度/过冷度配置":
|
||||
ShowSuperHeatCool(msg.Par);
|
||||
break;
|
||||
case "规则转换":
|
||||
if (SysRunServer.MachineRunState1.IsRunState)
|
||||
{
|
||||
MessageBox.Show("请不要在运行时编辑规则转换,此时更改可能导致运行出错,请停止后再编辑");
|
||||
return;
|
||||
}
|
||||
ShowLogicRule(msg.Par);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -94,6 +103,41 @@ namespace CapMachine.Wpf.Services
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 过热度和过冷度配置弹窗
|
||||
/// </summary>
|
||||
private void ShowLogicRule(object par)
|
||||
{
|
||||
//弹窗
|
||||
DialogService.ShowDialog("DialogLogicRuleView", new DialogParameters() { { "Name", par } }, (par) =>
|
||||
{
|
||||
if (par.Result == ButtonResult.OK)
|
||||
{
|
||||
//保存配置信息
|
||||
//PPCService.SaveSuperHeatCoolConfig();
|
||||
|
||||
//是否改变规格
|
||||
var ReturnValue = par.Parameters.GetValue<bool>("IsRuleEdit");
|
||||
if (ReturnValue)
|
||||
{
|
||||
MessageBox.Show("检测到你已经改变了规则,CAN或者LIN配置中如果已经加载规则或者连接的话,则会出现错误,那么你需要重启软件");
|
||||
//逻辑可能更改了
|
||||
EventAggregator.GetEvent<LogicRuleChangeEvent>().Publish("");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (par.Result == ButtonResult.Cancel)
|
||||
{
|
||||
//取消
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
578
CapMachine.Wpf/Services/LogicRuleService.cs
Normal file
578
CapMachine.Wpf/Services/LogicRuleService.cs
Normal file
@@ -0,0 +1,578 @@
|
||||
using AutoMapper;
|
||||
using CapMachine.Core;
|
||||
using CapMachine.Model;
|
||||
using CapMachine.Wpf.Dtos;
|
||||
using DynamicExpresso;
|
||||
using FreeSql;
|
||||
using FreeSql.DataAnnotations;
|
||||
using Prism.Mvvm;
|
||||
using Syncfusion.Windows.Shared;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 逻辑服务 - 用于处理数据逻辑转换
|
||||
/// </summary>
|
||||
public class LogicRuleService : BindableBase
|
||||
{
|
||||
private readonly ILogService LogService;
|
||||
private readonly IFreeSql FreeSql;
|
||||
|
||||
/// <summary>
|
||||
/// 逻辑转换规则集合
|
||||
/// </summary>
|
||||
public ObservableCollection<LogicRuleDto> LogicRuleDtos { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// DynamicExpresso解释器
|
||||
/// </summary>
|
||||
private Interpreter CurInterpreter { get; set; }
|
||||
public IMapper Mapper { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 规则表达式缓存(高性能访问)
|
||||
/// Key: 规则名称, Value: 已编译的Lambda表达式
|
||||
///private readonly ConcurrentDictionary<string, Func<double, double>> _expressionCache;
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<string, Func<double, double>> _expressionCache;
|
||||
|
||||
///// <summary>
|
||||
///// 创建包含指定值的参数数组
|
||||
///// </summary>
|
||||
//private Parameter[] CreateParameters(double value)
|
||||
//{
|
||||
// return new Parameter[]
|
||||
// {
|
||||
// new Parameter("value", typeof(double), value)
|
||||
// };
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 创建包含指定值的参数
|
||||
/// </summary>
|
||||
private Parameter CreateParameters(double value)
|
||||
{
|
||||
return new Parameter("value", typeof(double), value);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// </summary>
|
||||
public LogicRuleService(ILogService logService, IFreeSql freeSql, IMapper mapper)
|
||||
{
|
||||
LogService = logService;
|
||||
FreeSql = freeSql;
|
||||
Mapper = mapper;
|
||||
|
||||
// 初始化集合
|
||||
LogicRuleDtos = new ObservableCollection<LogicRuleDto>();
|
||||
|
||||
_expressionCache = new ConcurrentDictionary<string, Func<double, double>>();
|
||||
|
||||
// 初始化DynamicExpresso解释器
|
||||
CurInterpreter = new Interpreter();
|
||||
|
||||
try
|
||||
{
|
||||
// 从数据库加载规则
|
||||
LoadRulesFromDatabase();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"初始化逻辑服务失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从数据库加载规则
|
||||
/// </summary>
|
||||
private void LoadRulesFromDatabase()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 从数据库加载规则
|
||||
var dbRules = FreeSql.Select<LogicRule>().OrderBy(a => a.Id).ToList();
|
||||
if (dbRules != null && dbRules.Count > 0)
|
||||
{
|
||||
LogicRuleDtos.Clear();
|
||||
_expressionCache.Clear(); // 清空表达式缓存
|
||||
|
||||
foreach (var rule in dbRules)
|
||||
{
|
||||
LogicRuleDtos.Add(Mapper.Map<LogicRuleDto>(rule));
|
||||
}
|
||||
|
||||
// 预编译所有表达式
|
||||
WarmUpExpressionCache();
|
||||
|
||||
//LogService.Info($"已从数据库加载并预编译 {dbRules.Count} 条逻辑规则");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogService.Warn("数据库中没有逻辑规则");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"从数据库加载逻辑规则失败: {ex.Message}");
|
||||
throw; // 重新抛出异常以便调用者处理
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 增删改查LogicRule
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加新规则
|
||||
/// </summary>
|
||||
/// <param name="rule">规则对象</param>
|
||||
public void AddRule(LogicRule rule)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rule.Name))
|
||||
{
|
||||
MessageBox.Show("规则名称不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rule.Expression))
|
||||
{
|
||||
MessageBox.Show("规则表达式不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (LogicRuleDtos.Where(a => a.Name == rule.Name).Any())
|
||||
{
|
||||
MessageBox.Show("已经有另一个相同名称的规则了");
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证表达式是否有效
|
||||
if (!ValidateExpression(rule.Expression))
|
||||
{
|
||||
MessageBox.Show("规则表达式验证失败");
|
||||
return;
|
||||
}
|
||||
|
||||
if (InsertRuleToDb(rule, out LogicRule resultInsert))
|
||||
{
|
||||
//此时的resultInsert有新增的ID
|
||||
// 添加规则
|
||||
LogicRuleDtos.Add(Mapper.Map<LogicRuleDto>(resultInsert));
|
||||
|
||||
// 预编译并缓存表达式
|
||||
CacheExpression(Mapper.Map<LogicRuleDto>(resultInsert));
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("增加数据失败!");
|
||||
return;
|
||||
}
|
||||
//LogService.Info($"添加新规则: {rule.Name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存规格到数据库中
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool InsertRuleToDb(LogicRule rule, out LogicRule ResultInsert)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 插入规则到数据库
|
||||
var result = FreeSql.Insert<LogicRule>(rule).ExecuteInserted();
|
||||
|
||||
// 检查影响的行数
|
||||
bool success = result.Count > 0;
|
||||
|
||||
if (success)
|
||||
{
|
||||
ResultInsert = result.FirstOrDefault()!;
|
||||
return success;
|
||||
//LogService.Info($"成功插入规则: {rule.Name}");
|
||||
|
||||
// 刷新内存中的规则集合
|
||||
//LoadRulesFromDatabase();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogService.Warn($"插入规则失败: {rule.Name},没有行受影响");
|
||||
ResultInsert = null;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"插入规则到数据库时发生异常: {ex.Message}");
|
||||
ResultInsert = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新规则
|
||||
/// </summary>
|
||||
/// <param name="rule">规则对象</param>
|
||||
public void UpdateRule(LogicRule ruleOld, LogicRule rule)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rule.Name))
|
||||
{
|
||||
MessageBox.Show("规则名称不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(rule.Expression))
|
||||
{
|
||||
MessageBox.Show("规则表达式不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 验证表达式是否有效
|
||||
if (!ValidateExpression(rule.Expression))
|
||||
{
|
||||
MessageBox.Show("规则表达式验证失败");
|
||||
return;
|
||||
}
|
||||
|
||||
if (UpdateRuleToDb(rule))
|
||||
{
|
||||
// 更新缓存
|
||||
var updatedDto = LogicRuleDtos.FirstOrDefault(r => r.Id == rule.Id);
|
||||
var insertIndex = LogicRuleDtos.ToList().FindIndex(x => x.Id > rule.Id);
|
||||
if (updatedDto != null)
|
||||
{
|
||||
//移除数据
|
||||
LogicRuleDtos.Remove(updatedDto);
|
||||
if (insertIndex == -1)
|
||||
{
|
||||
LogicRuleDtos.Add(Mapper.Map<LogicRuleDto>(rule));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 在找到的位置插入
|
||||
LogicRuleDtos.Insert(insertIndex - 1, Mapper.Map<LogicRuleDto>(rule));
|
||||
}
|
||||
|
||||
//有可能更改的是名称,那么新名称的话在_expressionCache中肯定是找不到的,可以用之前的ruleOld
|
||||
_expressionCache.TryRemove(ruleOld.Name!, out _);
|
||||
CacheExpression(updatedDto);
|
||||
}
|
||||
}
|
||||
|
||||
//LogService.Info($"更新规则: {rule.Name}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新规格到数据库中
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool UpdateRuleToDb(LogicRule rule)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 更新规则到数据库
|
||||
var result = FreeSql.Update<LogicRule>()
|
||||
.Set(a => a.Name, rule.Name)
|
||||
.Set(a => a.Description, rule.Description)
|
||||
.Set(a => a.Expression, rule.Expression)
|
||||
.Set(a => a.ParameterType, rule.ParameterType)
|
||||
.Where(r => r.Id == rule.Id)
|
||||
.ExecuteUpdated();
|
||||
|
||||
// 检查影响的行数
|
||||
bool success = result.Count() > 0;
|
||||
|
||||
if (success)
|
||||
{
|
||||
//LogService.Info($"成功更新规则: {rule.Name}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//LogService.Warn($"更新规则失败: {rule.Name},没有行受影响");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//LogService.Error($"更新规则到数据库时发生异常: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除规则
|
||||
/// </summary>
|
||||
/// <param name="ruleName">规则名称</param>
|
||||
public void DeleteRule(string ruleName)
|
||||
{
|
||||
var rule = LogicRuleDtos.FirstOrDefault(r => r.Name == ruleName);
|
||||
if (rule == null)
|
||||
{
|
||||
MessageBox.Show("找不到删除的数据");
|
||||
return;
|
||||
}
|
||||
|
||||
var Count = FreeSql.Delete<LogicRule>().Where(r => r.Id == rule.Id).ExecuteAffrows();
|
||||
if (Count > 0)
|
||||
{
|
||||
// 删除规则
|
||||
LogicRuleDtos.Remove(rule);
|
||||
// 从缓存中移除表达式
|
||||
_expressionCache.TryRemove(ruleName, out _);
|
||||
}
|
||||
|
||||
//LogService.Info($"删除规则: {ruleName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证表达式是否有效
|
||||
/// </summary>
|
||||
/// <param name="expression">表达式字符串</param>
|
||||
/// <returns>表达式是否有效</returns>
|
||||
private bool ValidateExpression(string expression)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建测试解释器并直接设置变量
|
||||
var interpreter = new Interpreter()
|
||||
.Reference(typeof(Math)) // 引用Math类
|
||||
.SetVariable("Math", typeof(Math))
|
||||
.SetVariable("value", 100); // 直接设置值变量
|
||||
|
||||
// 尝试编译表达式
|
||||
var lambda = interpreter.Parse(expression);
|
||||
|
||||
// 尝试执行表达式
|
||||
var result = lambda.Invoke();
|
||||
|
||||
// 检查结果是否为数值类型
|
||||
if (result is double doubleResult)
|
||||
{
|
||||
// 验证结果不是NaN或Infinity
|
||||
if (double.IsNaN(doubleResult) || double.IsInfinity(doubleResult))
|
||||
{
|
||||
//LogService.Warn($"表达式执行结果无效 (NaN或Infinity): {expression}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Warn($"验证表达式失败: {expression}, 错误: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据参数类型获取适用的规则
|
||||
/// </summary>
|
||||
/// <param name="parameterType">参数类型</param>
|
||||
/// <returns>适用的规则列表</returns>
|
||||
public IEnumerable<LogicRuleDto> GetRulesByParameterType(string parameterType)
|
||||
{
|
||||
return LogicRuleDtos.Where(r => r.ParameterType == parameterType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定名称的规则
|
||||
/// </summary>
|
||||
/// <param name="ruleName">规则名称</param>
|
||||
/// <returns>规则对象</returns>
|
||||
public LogicRuleDto GetRuleByName(string ruleName)
|
||||
{
|
||||
var rule = LogicRuleDtos.FirstOrDefault(r => r.Name == ruleName);
|
||||
if (rule == null)
|
||||
{
|
||||
throw new KeyNotFoundException($"找不到名为 {ruleName} 的规则");
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 将规则表达式预编译并缓存到字典中
|
||||
/// </summary>
|
||||
/// <param name="rule">要缓存的规则</param>
|
||||
private void CacheExpression(LogicRuleDto rule)
|
||||
{
|
||||
if (string.IsNullOrEmpty(rule.Name) || string.IsNullOrEmpty(rule.Expression))
|
||||
{
|
||||
return; // 防止空名称或空表达式
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// ****如下步骤很重要,尝试了很多次才正常运行****
|
||||
|
||||
// 使用已有的CreateParameters方法创建参数声明
|
||||
var parameter = CreateParameters(0); // 值不重要,只是为了获取参数声明
|
||||
// 只解析一次,得到 Lambda 对象
|
||||
var lambda = CurInterpreter.Parse(rule.Expression, parameter); // 只定义参数类型,不传值
|
||||
// 编译为强类型委托
|
||||
var compiledFunc = lambda.Compile<Func<double, double>>();
|
||||
|
||||
// 存入缓存
|
||||
_expressionCache[rule.Name] = compiledFunc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogService.Error($"缓存规则 {rule.Name} 表达式失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预热表达式缓存 - 预编译所有规则
|
||||
/// </summary>
|
||||
private void WarmUpExpressionCache()
|
||||
{
|
||||
foreach (var rule in LogicRuleDtos)
|
||||
{
|
||||
if (!_expressionCache.ContainsKey(rule.Name))
|
||||
{
|
||||
CacheExpression(rule);
|
||||
}
|
||||
}
|
||||
LogService.Info($"已预编译 {_expressionCache.Count} 条规则表达式");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据规则应用表达式(高性能版本)
|
||||
/// </summary>
|
||||
/// <param name="value">输入值</param>
|
||||
/// <param name="rule">规则对象</param>
|
||||
/// <returns>转换后的输出值</returns>
|
||||
public double ApplyExpression(double value, LogicRuleDto rule)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 尝试从缓存获取预编译的表达式
|
||||
if (!_expressionCache.TryGetValue(rule.Name, out var compiledExpression))
|
||||
{
|
||||
// 如果缓存中没有,则编译并添加到缓存
|
||||
CacheExpression(rule);
|
||||
|
||||
// 再次尝试获取
|
||||
if (!_expressionCache.TryGetValue(rule.Name, out compiledExpression))
|
||||
{
|
||||
// 初始解析表达式(只需执行一次)
|
||||
string expressionText = rule.Expression;
|
||||
|
||||
// 强类型函数
|
||||
Func<double, double> compiledFunc = (v) =>
|
||||
{
|
||||
// 高性能版本:直接根据公式计算
|
||||
try
|
||||
{
|
||||
if (expressionText.Contains("value"))
|
||||
{
|
||||
var parameters = CreateParameters(v);
|
||||
var lambda = CurInterpreter.Parse(expressionText, parameters);
|
||||
return (double)lambda.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 简单表达式使用直接求值
|
||||
return v / 100.0; // 默认处理
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 出错时返回原值
|
||||
return v;
|
||||
}
|
||||
};
|
||||
// 再次尝试缓存
|
||||
CacheExpression(rule);
|
||||
|
||||
return compiledFunc(value);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建包含实际值的参数
|
||||
var parameter = new Parameter("value", typeof(double), value);
|
||||
// 使用预编译的表达式执行计算(高性能)
|
||||
var convertedValue = (double)compiledExpression.Invoke(value);
|
||||
|
||||
return convertedValue;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//LogService.Error($"应用规则 {rule.Name} 失败: {ex.Message}");
|
||||
return value; // 出错时返回原始值
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 快速的执行数据
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="rule"></param>
|
||||
/// <returns></returns>
|
||||
public double ApplyExpressionFast(double value, LogicRuleDto rule)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_expressionCache.TryGetValue(rule.Name, out var CurActiveFunc))
|
||||
{
|
||||
CacheExpression(rule);
|
||||
if (!_expressionCache.TryGetValue(rule.Name, out CurActiveFunc))
|
||||
return value;
|
||||
}
|
||||
|
||||
// 直接调用委托,无反射开销
|
||||
return CurActiveFunc(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 如果需要对多个数据应用相同规则,考虑实现批处理版本:
|
||||
/// </summary>
|
||||
/// <param name="values"></param>
|
||||
/// <param name="rule"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<double> ApplyExpressionBatch(IEnumerable<double> values, LogicRuleDto rule)
|
||||
{
|
||||
if (!_expressionCache.TryGetValue(rule.Name, out var func))
|
||||
{
|
||||
CacheExpression(rule);
|
||||
if (!_expressionCache.TryGetValue(rule.Name, out func))
|
||||
return values;
|
||||
}
|
||||
|
||||
// 使用并行处理大量数据
|
||||
return values.AsParallel().Select(v =>
|
||||
{
|
||||
try { return func(v); }
|
||||
catch { return v; }
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ namespace CapMachine.Wpf.Services
|
||||
public AlarmService AlarmService { get; }
|
||||
public ConfigService ConfigService { get; }
|
||||
public CanDriveService CanDriveService { get; }
|
||||
public CanFdDriveService CanFdDriveService { get; }
|
||||
public LinDriveService LinDriveService { get; }
|
||||
public SysRunService SysRunService { get; }
|
||||
|
||||
@@ -118,7 +119,7 @@ namespace CapMachine.Wpf.Services
|
||||
/// </summary>
|
||||
/// <param name="eventAggregator"></param>
|
||||
public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService, ConfigService configService,
|
||||
CanDriveService canDriveService, LinDriveService linDriveService, SysRunService sysRunService)//, AlarmService alarmService
|
||||
CanDriveService canDriveService, CanFdDriveService canFdDriveService, LinDriveService linDriveService, SysRunService sysRunService)//, AlarmService alarmService
|
||||
{
|
||||
//ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>();
|
||||
|
||||
@@ -136,6 +137,7 @@ namespace CapMachine.Wpf.Services
|
||||
AlarmService = alarmService;
|
||||
ConfigService = configService;
|
||||
CanDriveService = canDriveService;
|
||||
CanFdDriveService = canFdDriveService;
|
||||
LinDriveService = linDriveService;
|
||||
SysRunService = sysRunService;
|
||||
|
||||
@@ -1193,6 +1195,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)CanFdDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)LinDriveService.GetLdfSpeedValueBySpeedName("通讯Cmp转速"));
|
||||
@@ -1212,6 +1219,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯Cmp母线电压") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯Cmp母线电压") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯Cmp母线电压") * itemTag.Value.Precision));
|
||||
@@ -1230,6 +1242,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯Cmp母线电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯Cmp母线电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯Cmp母线电流") * itemTag.Value.Precision));
|
||||
@@ -1248,6 +1265,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯Cmp相电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯Cmp相电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯Cmp相电流") * itemTag.Value.Precision));
|
||||
@@ -1266,6 +1288,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯Cmp功率") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯Cmp功率") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯Cmp功率") * itemTag.Value.Precision));
|
||||
@@ -1284,6 +1311,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯Cmp芯片温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯Cmp芯片温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯Cmp芯片温度") * itemTag.Value.Precision));
|
||||
@@ -1302,6 +1334,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯Cmp逆变器温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯Cmp逆变器温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯Cmp逆变器温度") * itemTag.Value.Precision));
|
||||
@@ -1320,6 +1357,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯PTC入水温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯PTC入水温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯PTC入水温度") * itemTag.Value.Precision));
|
||||
@@ -1338,6 +1380,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯PTC出水温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯PTC出水温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯PTC出水温度") * itemTag.Value.Precision));
|
||||
@@ -1356,6 +1403,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯PTC峰值电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯PTC峰值电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯PTC峰值电流") * itemTag.Value.Precision));
|
||||
@@ -1374,6 +1426,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯PTC母线电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯PTC母线电流") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯PTC母线电流") * itemTag.Value.Precision));
|
||||
@@ -1392,6 +1449,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯PTC膜温") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯PTC膜温") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯PTC膜温") * itemTag.Value.Precision));
|
||||
@@ -1410,6 +1472,11 @@ namespace CapMachine.Wpf.Services
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanDriveService.GetDbcValueByName("通讯PTC模块温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(CanFdDriveService.GetDbcValueByName("通讯PTC模块温度") * itemTag.Value.Precision));
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//通信转速 Dbc中间配置名称的转速数据读取出来 给PLC
|
||||
SiemensDrive.Write(itemTag.Value.PVAddress, (short)(LinDriveService.GetLdfValueByName("通讯PTC模块温度") * itemTag.Value.Precision));
|
||||
@@ -1444,6 +1511,15 @@ namespace CapMachine.Wpf.Services
|
||||
itemTag.Value.EngPvValue = CanDriveService.GetDbcValueByName(itemTag.Value.NameNoUnit);
|
||||
}
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//CAN数据读取 //回读CAN通信的数据到集合中
|
||||
//CAN组合并且在循环接收数据中时,才读取数据
|
||||
if (itemTag.Value.Group == "CANLIN")
|
||||
{
|
||||
//回读CAN通信的DBC集合数据到集合中
|
||||
itemTag.Value.EngPvValue = CanFdDriveService.GetDbcValueByName(itemTag.Value.NameNoUnit);
|
||||
}
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//LIN数据读取 //回读LIN通信的数据到集合中
|
||||
//LIN组合并且在循环接收数据中时,才读取数据
|
||||
@@ -1482,6 +1558,11 @@ namespace CapMachine.Wpf.Services
|
||||
CanDriveService.UpdateSpeedCmdData(itemTag!.Value.EngSvValue);
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//获取PLC的SV数据 更新SV的速度值到压缩机
|
||||
CanFdDriveService.UpdateSpeedCmdData(itemTag!.Value.EngSvValue);
|
||||
//itemTag.Value.EngPvValue = 0;
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//获取PLC的SV数据 更新SV的速度值到压缩机
|
||||
LinDriveService.UpdateSpeedCmdData(itemTag!.Value.EngSvValue);
|
||||
@@ -1552,6 +1633,10 @@ namespace CapMachine.Wpf.Services
|
||||
//获取PLC的使能状态,更新到CAN的使能状态
|
||||
CanDriveService.UpdateCapEnableCmdData(OperateResultValue.Content[0] == 0 ? false : true);
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//获取PLC的使能状态,更新到CAN的使能状态
|
||||
CanFdDriveService.UpdateCapEnableCmdData(OperateResultValue.Content[0] == 0 ? false : true);
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//获取PLC的使能状态,更新到LIN的使能状态
|
||||
LinDriveService.UpdateCapEnableCmdData(OperateResultValue.Content[0] == 0 ? false : true);
|
||||
@@ -1583,6 +1668,10 @@ namespace CapMachine.Wpf.Services
|
||||
//获取PLC的 PTC使能,更新到CAN的 PTC使能
|
||||
CanDriveService.UpdateCapPTCEnableCmdData(OperateResultValue.Content[20] == 0 ? false : true);
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//获取PLC的 PTC使能,更新到CAN的 PTC使能
|
||||
CanFdDriveService.UpdateCapPTCEnableCmdData(OperateResultValue.Content[20] == 0 ? false : true);
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//获取PLC的 PTC使能,更新到LIN的 PTC使能
|
||||
LinDriveService.UpdateCapPTCEnableCmdData(OperateResultValue.Content[20] == 0 ? false : true);
|
||||
@@ -1598,6 +1687,10 @@ namespace CapMachine.Wpf.Services
|
||||
//获取PLC的 PTC功率,更新到CAN的 PTC功率
|
||||
CanDriveService.UpdateCapPTCPwCmdData(OperateResultValue.Content[22]);
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//获取PLC的 PTC功率,更新到CAN的 PTC功率
|
||||
CanFdDriveService.UpdateCapPTCPwCmdData(OperateResultValue.Content[22]);
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//获取PLC的 PTC功率,更新到LIN的 PTC功率
|
||||
LinDriveService.UpdateCapPTCPwCmdData(OperateResultValue.Content[22]);
|
||||
@@ -1613,6 +1706,10 @@ namespace CapMachine.Wpf.Services
|
||||
//获取PLC的 PTC水流量信号,更新到CAN的 PTC水流量信号
|
||||
CanDriveService.UpdateCapPTCFlowCmdData(OperateResultValue.Content[24]);
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//获取PLC的 PTC水流量信号,更新到CAN的 PTC水流量信号
|
||||
CanFdDriveService.UpdateCapPTCFlowCmdData(OperateResultValue.Content[24]);
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//获取PLC的 PTC水流量信号,更新到LIN的 PTC水流量信号
|
||||
LinDriveService.UpdateCapPTCFlowCmdData(OperateResultValue.Content[24]);
|
||||
@@ -1628,6 +1725,10 @@ namespace CapMachine.Wpf.Services
|
||||
//获取PLC的 PTC水温,更新到CAN的 PTC水温
|
||||
CanDriveService.UpdateCapPTCWaterTempCmdData(OperateResultValue.Content[26]);
|
||||
break;
|
||||
case CanLinEnum.CANFD:
|
||||
//获取PLC的 PTC水温,更新到CAN的 PTC水温
|
||||
CanFdDriveService.UpdateCapPTCWaterTempCmdData(OperateResultValue.Content[26]);
|
||||
break;
|
||||
case CanLinEnum.Lin:
|
||||
//获取PLC的 PTC水温,更新到LIN的 PTC水温
|
||||
LinDriveService.UpdateCapPTCWaterTempCmdData(OperateResultValue.Content[26]);
|
||||
|
||||
@@ -40,6 +40,10 @@ namespace CapMachine.Wpf.Services
|
||||
new NavigationItem("SuperHeatCool","过热度/过冷度配置","DialogSuperHeatCoolConfigView"),
|
||||
//new NavigationItem("Palette","过冷度",""),
|
||||
}),
|
||||
new NavigationItem("", "规则设置","",new ObservableCollection<NavigationItem>()
|
||||
{
|
||||
new NavigationItem("Rule","规则转换","DialogLogicRuleView"),
|
||||
}),
|
||||
//new NavigationItem("", "PID设置","",new ObservableCollection<NavigationItem>()
|
||||
//{
|
||||
// new NavigationItem("Circle","转速PID",""),
|
||||
@@ -73,6 +77,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"));
|
||||
|
||||
Reference in New Issue
Block a user