更新CAN和数据中心的关联实时数据

This commit is contained in:
2025-01-07 14:02:30 +08:00
parent 1336d082e2
commit 93f9558cac
2 changed files with 63 additions and 28 deletions

View File

@@ -3,6 +3,7 @@ using CapMachine.Wpf.CanDrive;
using ImTools; using ImTools;
using Prism.Ioc; using Prism.Ioc;
using Prism.Mvvm; using Prism.Mvvm;
using SharpDX;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -142,7 +143,7 @@ namespace CapMachine.Wpf.Services
{ {
SpeedCanCmdData.SignalCmdValue = SpeedData; SpeedCanCmdData.SignalCmdValue = SpeedData;
} }
if (EnableCanCmdData!=null) if (EnableCanCmdData != null)
{ {
EnableCanCmdData.SignalCmdValue = 1; EnableCanCmdData.SignalCmdValue = 1;
} }
@@ -231,6 +232,26 @@ namespace CapMachine.Wpf.Services
} }
} }
/// <summary>
/// 获取数据值
/// 从DBC中获取数据给数据中心集合
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
public double GetDbcValueByName(string Name)
{
if (!ToomossCanDrive.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 0;
}
#endregion #endregion

View File

@@ -6,6 +6,7 @@ using CapMachine.Wpf.Models.Tag;
using CapMachine.Wpf.PrismEvent; using CapMachine.Wpf.PrismEvent;
using HslCommunication; using HslCommunication;
using HslCommunication.Profinet.Siemens; using HslCommunication.Profinet.Siemens;
using ImTools;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using NPOI.HSSF.Record.Chart; using NPOI.HSSF.Record.Chart;
using NPOI.SS.Formula.Atp; using NPOI.SS.Formula.Atp;
@@ -579,7 +580,7 @@ namespace CapMachine.Wpf.Services
Name = "压缩机表面温度1[℃]",//名称带单位 Name = "压缩机表面温度1[℃]",//名称带单位
NameNoUnit = "压缩机表面温度1",//无单位名称 NameNoUnit = "压缩机表面温度1",//无单位名称
EnName = "CapSurfTemp1",//英文名称 EnName = "CapSurfTemp1",//英文名称
Group = "CAN",//分组 Group = "程序",//分组
MinValue = 0, MinValue = 0,
MaxValue = 100, MaxValue = 100,
Unit = "℃", Unit = "℃",
@@ -598,7 +599,7 @@ namespace CapMachine.Wpf.Services
Name = "压缩机表面温度2[℃]",//名称带单位 Name = "压缩机表面温度2[℃]",//名称带单位
NameNoUnit = "压缩机表面温度2",//无单位名称 NameNoUnit = "压缩机表面温度2",//无单位名称
EnName = "CapSurfTemp2",//英文名称 EnName = "CapSurfTemp2",//英文名称
Group = "CAN",//分组 Group = "程序",//分组
MinValue = 0, MinValue = 0,
MaxValue = 100, MaxValue = 100,
Unit = "℃", Unit = "℃",
@@ -617,7 +618,7 @@ namespace CapMachine.Wpf.Services
Name = "压缩机表面温度3[℃]",//名称带单位 Name = "压缩机表面温度3[℃]",//名称带单位
NameNoUnit = "压缩机表面温度3",//无单位名称 NameNoUnit = "压缩机表面温度3",//无单位名称
EnName = "CapSurfTemp3",//英文名称 EnName = "CapSurfTemp3",//英文名称
Group = "CAN",//分组 Group = "程序",//分组
MinValue = 0, MinValue = 0,
MaxValue = 100, MaxValue = 100,
Unit = "℃", Unit = "℃",
@@ -664,7 +665,7 @@ namespace CapMachine.Wpf.Services
MVAddress = "", MVAddress = "",
IsMeter = false, IsMeter = false,
Precision = 100, Precision = 100,
DecimalPoint = 1, DecimalPoint = 2,
Samp = 1, Samp = 1,
ValueType = typeof(short), ValueType = typeof(short),
Index = "", Index = "",
@@ -683,7 +684,7 @@ namespace CapMachine.Wpf.Services
MVAddress = "", MVAddress = "",
IsMeter = false, IsMeter = false,
Precision = 100, Precision = 100,
DecimalPoint = 1, DecimalPoint = 2,
Samp = 1, Samp = 1,
ValueType = typeof(short), ValueType = typeof(short),
Index = "", Index = "",
@@ -702,7 +703,7 @@ namespace CapMachine.Wpf.Services
MVAddress = "", MVAddress = "",
IsMeter = false, IsMeter = false,
Precision = 1, Precision = 1,
DecimalPoint = 1, DecimalPoint = 0,
Samp = 1, Samp = 1,
ValueType = typeof(short), ValueType = typeof(short),
Index = "", Index = "",
@@ -1112,27 +1113,38 @@ namespace CapMachine.Wpf.Services
TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.IsShow = IsValueShow; TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.IsShow = IsValueShow;
//仿真数据 ////仿真数据
TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value = (short)Random.Next(1, 100); ////TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value = (short)Random.Next(1, 100);
TagManger.GetTagByName<short>(itemTag.Value.Name).EngPvValue = (short)Random.Next(1, 100) * 1.0 / TagManger.GetTagByName<short>(itemTag.Value.Name)!.Precision; ////TagManger.GetTagByName<short>(itemTag.Value.Name).EngPvValue = (short)Random.Next(1, 100) * 1.0 / TagManger.GetTagByName<short>(itemTag.Value.Name)!.Precision;
////LinkState = false;
//PLC 数据
if (!string.IsNullOrEmpty(itemTag.Value.PVAddress))
{
OperateResultShort = SiemensDrive.ReadInt16(itemTag.Value.PVAddress);
if (OperateResultShort.IsSuccess)
{
TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value = SiemensDrive.ReadInt16(itemTag.Value.PVAddress).Content;
TagManger.GetTagByName<short>(itemTag.Value.Name)!.EngPvValue = TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value * 1.0 / TagManger.GetTagByName<short>(itemTag.Value.Name)!.Precision;
LinkState = true;
}
else
{
LinkState = false; LinkState = false;
}
////PLC 数据 //CAN数据读取 //回读CAN通信的数据到集合中
//if (!string.IsNullOrEmpty(itemTag.Value.PVAddress)) //CAN组合并且在循环接收数据中时才读取数据
//{ if (itemTag.Value.Group == "CAN")
// OperateResultShort = SiemensDrive.ReadInt16(itemTag.Value.PVAddress); {
// if (OperateResultShort.IsSuccess) //回读CAN通信的DBC集合数据到集合中
// { itemTag.Value.EngPvValue = CanDriveService.GetDbcValueByName(itemTag.Value.NameNoUnit);
// TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value = SiemensDrive.ReadInt16(itemTag.Value.PVAddress).Content; }
// TagManger.GetTagByName<short>(itemTag.Value.Name)!.EngPvValue = TagManger.GetTagInfoValueByName<short>(itemTag.Value.Name)!.Value * 1.0 / TagManger.GetTagByName<short>(itemTag.Value.Name)!.Precision; }
// LinkState = true; else //地址为空PLC驱动不读取数据
{
// } }
// else
// {
// LinkState = false;
// }
//}
if (!string.IsNullOrEmpty(itemTag.Value.SVAddress)) if (!string.IsNullOrEmpty(itemTag.Value.SVAddress))
{ {
@@ -1206,6 +1218,8 @@ namespace CapMachine.Wpf.Services
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {