This commit is contained in:
2024-09-25 15:44:59 +08:00
parent a76546ebe6
commit 6bf0d5d7ba
72 changed files with 21606 additions and 1608 deletions

View File

@@ -1,7 +1,12 @@
using AutoMapper.Internal;
using CapMachine.Core;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.Models.Tag;
using CapMachine.Wpf.PrismEvent;
using HslCommunication;
using HslCommunication.Profinet.Siemens;
using Microsoft.Extensions.Caching.Memory;
using NPOI.SS.Formula.Atp;
using Prism.Events;
using Prism.Mvvm;
using System;
@@ -11,6 +16,8 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using static CapMachine.Wpf.Models.ComEnum;
namespace CapMachine.Wpf.Services
{
@@ -24,16 +31,41 @@ namespace CapMachine.Wpf.Services
/// </summary>
private IEventAggregator _EventAggregator { get; set; }
/// <summary>
/// PLCScanTask扫描Task
/// </summary>
private static Task PLCScanTask { get; set; }
/// <summary>
/// ScanTask扫描Task
/// </summary>
static Task ScanTask { get; set; }
private static Task ScanTask { get; set; }
/// <summary>
/// 西门子连接驱动程序
/// </summary>
public SiemensS7Net SiemensDrive { get; set; }
/// <summary>
/// PLC连接状态
/// </summary>
public bool SiemensS7LinkState { get; set; }
/// <summary>
/// 仪表数据集合
/// </summary>
public List<MeterRtDataModel> ListMeterRtData { get; set; }
///// <summary>
///// Tag数据集合
///// </summary>
//public List<TagInfo> ListRtDataModel { get; set; }
/// <summary>
/// 标签管理中心
/// </summary>
public TagManager TagManger { get; set; } = new TagManager();
/// <summary>
/// 扫描线程使能
/// </summary>
@@ -52,8 +84,6 @@ namespace CapMachine.Wpf.Services
{
//ConcurrentDictionary<DateTime, RecordInfo> keyValuePairs = new ConcurrentDictionary<DateTime, RecordInfo>();
//Stopwatch stopwatch = new Stopwatch();
////第一次计时
//stopwatch.Start(); //启动Stopwatch
@@ -80,126 +110,266 @@ namespace CapMachine.Wpf.Services
//事件服务
_EventAggregator = eventAggregator;
//TagManger.AddTag(new ByteTag("转速", "Speed", "rpm", ComEnum.TagType.Tag));
//dynamic dad=10;
//TagManger.AddRange(new List<BaseTag>()
//{
// new ByteTag("转速","Speed","rpm",ComEnum.TagType.Tag, (byte)10),
// new ShortTag("排气压力","ExPress","BarA",ComEnum.TagType.Tag),
// new ShortTag("吸气压力","InhPress","BarA",ComEnum.TagType.Tag),
// new ShortTag("吸气温度","InhTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("COND1温度","Cond1Temp","℃",ComEnum.TagType.Tag),
// new ShortTag("润滑油压力","LubePress","BarA",ComEnum.TagType.Tag),
// new ShortTag("COND2压力","Cond2Press","BarA",ComEnum.TagType.Tag),
// new ShortTag("OCR","OCR","%",ComEnum.TagType.Tag),
// new ShortTag("HV","HV","V",ComEnum.TagType.Tag),
// new ShortTag("HV","HVCur","A",ComEnum.TagType.Tag),
// new ShortTag("HV","HV","W",ComEnum.TagType.Tag),
// new ShortTag("LV","LV","V",ComEnum.TagType.Tag),
// new ShortTag("LV","LVCur","A",ComEnum.TagType.Tag),
// new ShortTag("环境温度","EnvTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("环境湿度","EnvRH","%",ComEnum.TagType.Tag),
// new ShortTag("OS1温度","OS1Temp","℃",ComEnum.TagType.Tag),
// new ShortTag("OS2温度","OS2Temp","℃",ComEnum.TagType.Tag),
// new ShortTag("COND2温度","Cond2Temp","℃",ComEnum.TagType.Tag),
// new ShortTag("EVAP出口温度","EVAPExpTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("冷媒流量","VRV","L/min",ComEnum.TagType.Tag),
// new ShortTag("润滑油流量","LubeFlow","L/min",ComEnum.TagType.Tag),
// new ShortTag("排气温度","ExTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("膨胀阀前压力","TxvFrPress","BarA",ComEnum.TagType.Tag),
// new ShortTag("膨胀阀前温度","TxvFrTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("EVAP出口压力","EVAPExpPress","BarA",ComEnum.TagType.Tag),
// new ShortTag("腔内压力","IntrplPress","BarA",ComEnum.TagType.Tag),
// new ShortTag("压缩机表面温度","CapSurfTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("PTC流量","PTCFlow","L/min",ComEnum.TagType.Tag),
// new ShortTag("PTC入水温度","PTCEntTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("PTC出水温度","PTCExpTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("通讯Cmp母线电流","ComCapBusCur","A",ComEnum.TagType.Tag),
// new ShortTag("通讯Cmp母线电压","ComCapBusVol","V",ComEnum.TagType.Tag),
// new ShortTag("通讯Cmp逆变器温度","ComCapInvTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("通讯Cmp相电流","ComCapPhCur","A",ComEnum.TagType.Tag),
// new ShortTag("通讯Cmp功率","ComCapPw","W",ComEnum.TagType.Tag),
// new ShortTag("通讯Cmp芯片温度","ComCapChipTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("通讯PTC入水温度","ComPTCEntTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("通讯PTC出水温度","ComPTCExpTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("通讯PTC峰值电流","ComPTCPeakCur","A",ComEnum.TagType.Tag),
// new ShortTag("通讯PTC母线电流","ComPTCBusCur","A",ComEnum.TagType.Tag),
// new ShortTag("通讯PTC膜温","ComPTCFlmTemp","℃",ComEnum.TagType.Tag),
// new ShortTag("通讯PTC模块温度","ComPTCMdTemp","℃",ComEnum.TagType.Tag),
//});
#region ListMeterRtData实例化
//实例化集合
ListMeterRtData = new List<MeterRtDataModel>()
{
new MeterRtDataModel(){
MeterName = "EVA风量",
RtUIControlTitle="EVA风量" + Environment.NewLine + "m³/h",
RtUIControlTitleIndex="Title5",
Station = 1,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV5",
RtSVUIControlIndex="SV5",
RtPVUIControlIndex="PV5",
MaxValue=500,
MinValue=0,
Accuracy=1,
Unit="m³/h",
MeterEnableStatePLCAddress="V30.3",
},
new MeterRtDataModel(){//目前是DB表
MeterName = "中间轴转速",//原来中间轴转速,先全部改为电机转速-开发过程中某个时刻中间轴转速改为电机转速
RtUIControlTitle="中间轴转速" + Environment.NewLine + "(r/min)",
RtUIControlTitleIndex="Title3",
Station = 2,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV3",
RtSVUIControlIndex="SV3",
RtPVUIControlIndex="PV3",
MaxValue=4000,
MinValue=0,
Accuracy=0,
Unit="(r/min)",
MeterEnableStatePLCAddress="",
},
new MeterRtDataModel(){
MeterName = "加热电力",//加热电力
RtUIControlTitle="加热电力" + Environment.NewLine + "(KW)",
RtUIControlTitleIndex="Title7",
Station = 3,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV7",
RtSVUIControlIndex="SV7",
RtPVUIControlIndex="PV7",
MaxValue=30,
MinValue=0,
Accuracy=2,
Unit="(KW)",
MeterEnableStatePLCAddress="V30.4",
},
new MeterRtDataModel(){
MeterName = "加湿电力",
RtUIControlTitle="加湿电力" + Environment.NewLine + "(KW)",
RtUIControlTitleIndex="Title8",
Station = 4,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV8",
RtSVUIControlIndex="SV8",
RtPVUIControlIndex="PV8",
MaxValue=18,
MinValue=0,
Accuracy=2,
Unit="(KW)",
MeterEnableStatePLCAddress="V30.5",
},
new MeterRtDataModel(){//目前是DB表
MeterName = "EMPCV电流",//EMPCV电力
RtUIControlTitle="EMPCV电流" + Environment.NewLine + "(A)",
RtUIControlTitleIndex="Title9",
Station = 5,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV9",
RtSVUIControlIndex="SV9",
RtPVUIControlIndex="PV9",
MaxValue=1,
MinValue=0,
Accuracy=2,
Unit="(A)",
MeterEnableStatePLCAddress="V30.6",
},
new MeterRtDataModel(){
MeterName = "INJ压力",
RtUIControlTitle="INJ压力" + Environment.NewLine + "(MPa)",
RtUIControlTitleIndex="Title10",
Station = 6,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV10",
RtSVUIControlIndex="SV10",
RtPVUIControlIndex="PV10",
MaxValue=5,
MinValue=0,
Accuracy=3,
Unit="(MPa)",
MeterEnableStatePLCAddress="V30.7",
},
new MeterRtDataModel(){
MeterName = "冷媒流量",
RtUIControlTitle="冷媒流量" + Environment.NewLine + "(kg/h)",
RtUIControlTitleIndex="Title11",
Station = 7,
RtAddressPV = "101",
RtAddressMV = "105",
RtMVUIControlIndex="MV11",
RtSVUIControlIndex="SV11",
RtPVUIControlIndex="PV11",
MaxValue=500,
MinValue=0,
Accuracy=1,
Unit="(kg/h)",
MeterEnableStatePLCAddress="V31.0",
},
};
//ListMeterRtData = new List<MeterRtDataModel>()
//{
// new MeterRtDataModel(){
// MeterName = "EVA风量",
// RtUIControlTitle="EVA风量" + Environment.NewLine + "m³/h",
// RtUIControlTitleIndex="Title5",
// Station = 1,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV5",
// RtSVUIControlIndex="SV5",
// RtPVUIControlIndex="PV5",
// MaxValue=500,
// MinValue=0,
// Accuracy=1,
// Unit="m³/h",
// MeterEnableStatePLCAddress="V30.3",
// },
// new MeterRtDataModel(){//目前是DB表
// MeterName = "中间轴转速",//原来中间轴转速,先全部改为电机转速-开发过程中某个时刻中间轴转速改为电机转速
// RtUIControlTitle="中间轴转速" + Environment.NewLine + "(r/min)",
// RtUIControlTitleIndex="Title3",
// Station = 2,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV3",
// RtSVUIControlIndex="SV3",
// RtPVUIControlIndex="PV3",
// MaxValue=4000,
// MinValue=0,
// Accuracy=0,
// Unit="(r/min)",
// MeterEnableStatePLCAddress="",
// },
// new MeterRtDataModel(){
// MeterName = "加热电力",//加热电力
// RtUIControlTitle="加热电力" + Environment.NewLine + "(KW)",
// RtUIControlTitleIndex="Title7",
// Station = 3,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV7",
// RtSVUIControlIndex="SV7",
// RtPVUIControlIndex="PV7",
// MaxValue=30,
// MinValue=0,
// Accuracy=2,
// Unit="(KW)",
// MeterEnableStatePLCAddress="V30.4",
// },
// new MeterRtDataModel(){
// MeterName = "加湿电力",
// RtUIControlTitle="加湿电力" + Environment.NewLine + "(KW)",
// RtUIControlTitleIndex="Title8",
// Station = 4,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV8",
// RtSVUIControlIndex="SV8",
// RtPVUIControlIndex="PV8",
// MaxValue=18,
// MinValue=0,
// Accuracy=2,
// Unit="(KW)",
// MeterEnableStatePLCAddress="V30.5",
// },
// new MeterRtDataModel(){//目前是DB表
// MeterName = "EMPCV电流",//EMPCV电力
// RtUIControlTitle="EMPCV电流" + Environment.NewLine + "(A)",
// RtUIControlTitleIndex="Title9",
// Station = 5,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV9",
// RtSVUIControlIndex="SV9",
// RtPVUIControlIndex="PV9",
// MaxValue=1,
// MinValue=0,
// Accuracy=2,
// Unit="(A)",
// MeterEnableStatePLCAddress="V30.6",
// },
// new MeterRtDataModel(){
// MeterName = "INJ压力",
// RtUIControlTitle="INJ压力" + Environment.NewLine + "(MPa)",
// RtUIControlTitleIndex="Title10",
// Station = 6,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV10",
// RtSVUIControlIndex="SV10",
// RtPVUIControlIndex="PV10",
// MaxValue=5,
// MinValue=0,
// Accuracy=3,
// Unit="(MPa)",
// MeterEnableStatePLCAddress="V30.7",
// },
// new MeterRtDataModel(){
// MeterName = "冷媒流量",
// RtUIControlTitle="冷媒流量" + Environment.NewLine + "(kg/h)",
// RtUIControlTitleIndex="Title11",
// Station = 7,
// RtAddressPV = "101",
// RtAddressMV = "105",
// RtMVUIControlIndex="MV11",
// RtSVUIControlIndex="SV11",
// RtPVUIControlIndex="PV11",
// MaxValue=500,
// MinValue=0,
// Accuracy=1,
// Unit="(kg/h)",
// MeterEnableStatePLCAddress="V31.0",
// },
//};
#endregion
InitialPLCCom();
PubRtDataStart();
}
/// <summary>
/// 初始化PLC通信
/// </summary>
private void InitialPLCCom()
{
var IPInfo = ConfigHelper.GetValue("PLCIP");
SiemensDrive = new SiemensS7Net(SiemensPLCS.S200Smart, IPInfo);
// 连接对象
OperateResult connect = SiemensDrive.ConnectServer();
if (!connect.IsSuccess)//连接失败
{
SiemensS7LinkState = false;
Console.WriteLine("connect failed:" + connect.Message);
MessageBox.Show($"PLC连接失败:{IPInfo}");
return;
}
else//连接成功
{
SiemensS7LinkState = true;
}
//扫描线程成功
RtScanDeviceStart();
}
/// <summary>
/// PLC扫描线程
/// </summary>
private void RtScanDeviceStart()
{
PLCScanTask = Task.Run(async () =>
{
while (ThreadEnable)
{
await Task.Delay(50);
//DiagnosticsTime.Reset();
//DiagnosticsTime.Start();
try
{
//RT TODO
//SiemensDrive.Read("VW1", 2);
foreach (var itemTag in TagManger.ListTag)
{
switch (itemTag.DataTypeInfo)
{
//case DataType.Byte:
// itemTag.OperateResultSource = SiemensDrive.ReadByte(itemTag.Address);
// break;
//case DataType.Short:
// itemTag.OperateResultSource = SiemensDrive.ReadInt16(itemTag.Address);
// break;
//case DataType.String:
// itemTag.OperateResultSource = SiemensDrive.ReadString(itemTag.Address);
// break;
//case DataType.Double:
// itemTag.OperateResultSource = SiemensDrive.ReadDouble(itemTag.Address);
// break;
default:
break;
}
}
}
catch (Exception ex)
{
//LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}");
}
//DiagnosticsTime.Stop();
//ScanRtTimeinfo = $"电表:{DiagnosticsTime.Elapsed.TotalMilliseconds.ToString()}";
}
});
}
private Random random = new Random();
/// <summary>