diff --git a/Aucma.Core.DoorFoam/Business/CollectionFoamMachine.cs b/Aucma.Core.DoorFoam/Business/CollectionFoamMachine.cs index 0024adfe..76a82503 100644 --- a/Aucma.Core.DoorFoam/Business/CollectionFoamMachine.cs +++ b/Aucma.Core.DoorFoam/Business/CollectionFoamMachine.cs @@ -3,7 +3,7 @@ using Admin.Core.IService; using Admin.Core.Model; using Aucma.Core.DoorFoam.Models; using Aucma.Core.HwPLc; - +using Microsoft.Extensions.DependencyInjection; using NetTaste; using NPOI.Util; using System; @@ -22,29 +22,115 @@ namespace Aucma.Core.DoorFoam.Business /// public class CollectionFoamMachine { + /// + /// 刷新最后一枪DATAGRID + /// + public delegate void RefreshLastShotDataDelegate(BoxLastShotRecord record); + public static event RefreshLastShotDataDelegate RefreshLastShotDataDelegateEvent; + + /// + /// 刷新每一枪数据 + /// + public delegate void RefreshGunDataDelegate(Dictionary keys); + public static event RefreshGunDataDelegate RefreshGunDataDelegateEvent; + + /// + /// 刷新系统数据 + /// + public delegate void RefreshSystemDataDelegate(Dictionary keys); + public static event RefreshSystemDataDelegate RefreshSystemDataDelegateEvent; + private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); List foamMachinesList = new List(); - private static BoxLastShotRecord tempLastRecord = null; - - public void startCollect() + + Dictionary gunKeys = new Dictionary(); + Dictionary tempKeys = new Dictionary(); + // 系统参数 + Dictionary systemKeys = new Dictionary(); + Semaphore semaphore = new Semaphore(1, 1); + + private readonly IBoxLastShotRecordServices? _lastShotRecordServices = App.ServiceProvider.GetService(); + + + public CollectionFoamMachine() + { + + } + + public void startCollect() { - Task.Run( () => + Task.Run(() => { - Task.Delay(2000); - - //Thread.Sleep(6000); - var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamMachinePlc")); - if (obj != null) + while (true) { - ReadEquipSystem(obj, "DB50.388"); //采集1系统 - //ReadEquipSystem(obj, "DB50.642"); //采集2系统 - //ReadGunData(obj, "DB50.896"); //A1枪数据 - //ReadGunData(obj, "DB50.1084"); //A1枪数据 - //ReadGunData(obj, "DB50.1272"); //A1枪数据 - //ReadGunData(obj, "DB50.1460"); //A1枪数据 - + + try + { + Thread.Sleep(3000); + var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("FoamPlc")); + if (obj != null) + { + ReadEquipSystem(obj, "DB50.388", systemKeys, "1"); //采集1系统 + ReadEquipSystem(obj, "DB50.642", systemKeys, "2"); //采集2系统 + + ReadGunData(obj, "DB50.896", gunKeys, "A1"); //A1枪数据 + ReadGunData(obj, "DB50.1084", gunKeys, "B1"); //B1枪数据 + ReadGunData(obj, "DB50.1272", gunKeys, "A2"); //A2枪数据 + ReadGunData(obj, "DB50.1460", gunKeys, "B2"); //A2枪数据 + RefreshSystemDataDelegateEvent?.Invoke(systemKeys); + RefreshGunDataDelegateEvent?.Invoke(gunKeys); + + + foreach (KeyValuePair kvPair in gunKeys) + { + //程序启动缓存没数据查数据库 + if (!tempKeys.ContainsKey(kvPair.Key)) + { + BoxLastShotRecord record = _lastShotRecordServices.Query(x => x.System == kvPair.Value.System && x.ProductLineCode == kvPair.Value.ProductLineCode && x.GunCode == kvPair.Value.GunCode).OrderByDescending(x => x.CreateTime).FirstOrDefault(); + if (record == null) + { + // 数据库也没数据 + int a = _lastShotRecordServices.AddAsync(kvPair.Value).Result; + RefreshLastShotDataDelegateEvent?.Invoke(kvPair.Value); + continue; + } + tempKeys.Add(kvPair.Key, record); + } + if (!kvPair.Value.MixpistOff.Equals(tempKeys[kvPair.Key].MixpistOff)) + { + int b = _lastShotRecordServices.AddAsync(kvPair.Value).Result; + RefreshLastShotDataDelegateEvent?.Invoke(kvPair.Value); + } + + + } + } + + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + finally + { + + foreach (KeyValuePair kvp in gunKeys) + { + if (tempKeys.ContainsKey(kvp.Key)) + { + // 键已存在,更新值 + tempKeys[kvp.Key] = kvp.Value; + } + else + { + // 键不存在,添加键值对 + tempKeys.Add(kvp.Key, kvp.Value); + } + } + // tempKeys = gunKeys; + } } - + }); } @@ -52,38 +138,54 @@ namespace Aucma.Core.DoorFoam.Business /// 采集设备系统参数 /// /// - static void ReadEquipSystem(HwPLc.PlcModel obj, string startStr) + static void ReadEquipSystem(HwPLc.PlcModel obj, string startStr, Dictionary keys, string systemId) { - if (obj == null && !obj.plc.IsConnected) return; + if (obj == null || !obj.plc.IsConnected) return; if (obj.plc.IsConnected) { - FoamMachinesModel mode=new FoamMachinesModel(); + byte[] info = obj.plc.Read(startStr, 170); - int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray())); - int temp2 = judgeStatus(ByteArrayToBinary(info.Skip(1).Take(1).ToArray())); - float temp3 = byteToFloat(info.Skip(2).Take(4).ToArray()); - - float temp4 = byteToFloat(info.Skip(14).Take(4).ToArray()); - float temp5 = byteToFloat(info.Skip(18).Take(4).ToArray()); - float temp6 = byteToFloat(info.Skip(22).Take(4).ToArray()); + if (info == null) return; + FoamMachinesModel model = new FoamMachinesModel(); + model.systemId = systemId; + + model.Machine_Status_0 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray())).ToString(); + model.Machine_Status_1 = judgeStatus(ByteArrayToBinary(info.Skip(1).Take(1).ToArray())).ToString(); + model.POL_Level = byteToFloat(info.Skip(2).Take(4).ToArray()).ToString(); + + model.POL_Temp = byteToFloat(info.Skip(14).Take(4).ToArray()).ToString(); + model.POL_LP = byteToFloat(info.Skip(18).Take(4).ToArray()).ToString(); + model.POL_HP = byteToFloat(info.Skip(22).Take(4).ToArray()).ToString(); - float temp7 = byteToFloat(info.Skip(34).Take(4).ToArray()); - float temp8 = byteToFloat(info.Skip(38).Take(4).ToArray()); - float temp9 = byteToFloat(info.Skip(42).Take(4).ToArray()); + model.POL_Vol = byteToFloat(info.Skip(34).Take(4).ToArray()).ToString(); + model.POL_Usage = byteToFloat(info.Skip(38).Take(4).ToArray()).ToString(); + model.POL_Freq_Speed = byteToFloat(info.Skip(42).Take(4).ToArray()).ToString(); - float temp10 = byteToFloat(info.Skip(82).Take(4).ToArray()); + model.ISO_Level = byteToFloat(info.Skip(82).Take(4).ToArray()).ToString(); - float temp11 = byteToFloat(info.Skip(94).Take(4).ToArray()); - float temp12 = byteToFloat(info.Skip(98).Take(4).ToArray()); - float temp13 = byteToFloat(info.Skip(102).Take(4).ToArray()); + model.ISO_Temp = byteToFloat(info.Skip(94).Take(4).ToArray()).ToString(); + model.ISO_LP = byteToFloat(info.Skip(98).Take(4).ToArray()).ToString(); + model.ISO_HP = byteToFloat(info.Skip(102).Take(4).ToArray()).ToString(); - float temp14 = byteToFloat(info.Skip(114).Take(4).ToArray()); - float temp15 = byteToFloat(info.Skip(118).Take(4).ToArray()); - float temp16 = byteToFloat(info.Skip(122).Take(4).ToArray()); + model.ISO_Vol = byteToFloat(info.Skip(114).Take(4).ToArray()).ToString(); + model.ISO_Usage = byteToFloat(info.Skip(118).Take(4).ToArray()).ToString(); + model.ISO_Freq_Speed = byteToFloat(info.Skip(122).Take(4).ToArray()).ToString(); - float temp17 = byteToFloat(info.Skip(162).Take(4).ToArray()); - float temp18 = byteToFloat(info.Skip(166).Take(4).ToArray()); + model.Hydr_Press = byteToFloat(info.Skip(162).Take(4).ToArray()).ToString(); + model.Hydr_Temp = byteToFloat(info.Skip(166).Take(4).ToArray()).ToString(); + model.collectTime = DateTime.Now; + + if (keys.ContainsKey(systemId)) + { + // 键已存在,更新值 + keys[systemId] = model; + } + else + { + // 键不存在,添加键值对 + keys.Add(systemId, model); + } } } @@ -91,98 +193,57 @@ namespace Aucma.Core.DoorFoam.Business /// 每一枪数据 ---A1,B1,A2,B2 /// /// - static void ReadGunData(HwPLc.PlcModel obj, string startStr) + static void ReadGunData(HwPLc.PlcModel obj, string startStr, Dictionary keys, string gunCode) { - if (obj == null && !obj.plc.IsConnected) return; + if (obj == null || !obj.plc.IsConnected) return; if (obj.plc.IsConnected) { - byte[] info = obj.plc.Read(startStr, 88); - - float temp1 = byteToFloat(info.Skip(0).Take(4).ToArray()); - float temp2 = byteToFloat(info.Skip(4).Take(4).ToArray()); - float temp3 = byteToFloat(info.Skip(8).Take(4).ToArray()); - float temp4 = byteToFloat(info.Skip(12).Take(4).ToArray()); - float temp5 = byteToFloat(info.Skip(16).Take(4).ToArray()); - float temp6 = byteToFloat(info.Skip(20).Take(4).ToArray()); - float temp7 = byteToFloat(info.Skip(24).Take(4).ToArray()); - float temp8 = byteToFloat(info.Skip(28).Take(4).ToArray()); - - short temp9 = short.Parse(StringChange.bytesToHexStr(info.Skip(36).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - int temp10 = int.Parse(StringChange.bytesToHexStr(info.Skip(38).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); - float temp11 = byteToFloat(info.Skip(42).Take(4).ToArray()); - float temp12 = byteToFloat(info.Skip(46).Take(4).ToArray()); - float temp13 = byteToFloat(info.Skip(50).Take(4).ToArray()); - float temp14 = byteToFloat(info.Skip(54).Take(4).ToArray()); - int temp15 = int.Parse(StringChange.bytesToHexStr(info.Skip(58).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); - int temp16 = int.Parse(StringChange.bytesToHexStr(info.Skip(62).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); - float temp17 = byteToFloat(info.Skip(66).Take(4).ToArray()); - float temp18 = byteToFloat(info.Skip(70).Take(4).ToArray()); - int temp19 = int.Parse(StringChange.bytesToHexStr(info.Skip(74).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); - int temp20 = int.Parse(StringChange.bytesToHexStr(info.Skip(78).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); - int temp21 = int.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); - - int temp22 = judgeStatus(ByteArrayToBinary(info.Skip(87).Take(1).ToArray())); + if (info == null) return; + BoxLastShotRecord lastShotRecord = new BoxLastShotRecord(); + lastShotRecord.System = gunCode.Substring(1, 1); + lastShotRecord.GunCode = gunCode; + lastShotRecord.ProductLineCode = "CX_02"; + + lastShotRecord.PolTemp = byteToFloat(info.Skip(0).Take(4).ToArray()).ToString(); + lastShotRecord.PolHp = byteToFloat(info.Skip(4).Take(4).ToArray()).ToString(); + lastShotRecord.PolVol = byteToFloat(info.Skip(8).Take(4).ToArray()).ToString(); + lastShotRecord.PolUsage = byteToFloat(info.Skip(12).Take(4).ToArray()).ToString(); + lastShotRecord.IsoTemp = byteToFloat(info.Skip(16).Take(4).ToArray()).ToString(); + lastShotRecord.IsoHp = byteToFloat(info.Skip(20).Take(4).ToArray()).ToString(); + lastShotRecord.IsoVol = byteToFloat(info.Skip(24).Take(4).ToArray()).ToString(); + lastShotRecord.IsoUsage = byteToFloat(info.Skip(28).Take(4).ToArray()).ToString(); + + lastShotRecord.PourNu = short.Parse(StringChange.bytesToHexStr(info.Skip(36).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); + lastShotRecord.SetTime = int.Parse(StringChange.bytesToHexStr(info.Skip(38).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); + lastShotRecord.SetWeight = byteToFloat(info.Skip(42).Take(4).ToArray()).ToString(); + lastShotRecord.SetRatio = byteToFloat(info.Skip(46).Take(4).ToArray()).ToString(); ; + lastShotRecord.PourWeight = byteToFloat(info.Skip(50).Take(4).ToArray()).ToString(); + lastShotRecord.PourRatio = byteToFloat(info.Skip(54).Take(4).ToArray()).ToString(); + lastShotRecord.MpTime = int.Parse(StringChange.bytesToHexStr(info.Skip(58).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); + lastShotRecord.HpTime = int.Parse(StringChange.bytesToHexStr(info.Skip(62).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); + lastShotRecord.HydrPress = byteToFloat(info.Skip(66).Take(4).ToArray()).ToString(); + lastShotRecord.HydrTemp = byteToFloat(info.Skip(70).Take(4).ToArray()).ToString(); + lastShotRecord.MixpistOn = int.Parse(StringChange.bytesToHexStr(info.Skip(74).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); + lastShotRecord.MixpistOff = int.Parse(StringChange.bytesToHexStr(info.Skip(78).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); ; + lastShotRecord.TotalYield = int.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); ; + lastShotRecord.PourEnd = judgeStatus(ByteArrayToBinary(info.Skip(87).Take(1).ToArray())).ToString(); + + lastShotRecord.CreateTime = DateTime.Now; + + if (keys.ContainsKey(gunCode)) + { + // 键已存在,更新值 + keys[gunCode] = lastShotRecord; + } + else + { + // 键不存在,添加键值对 + keys.Add(gunCode, lastShotRecord); + } } } - ///// - ///// 采集最后一枪数据 - ///// - ///// - //public async Task CollectLast() - //{ - // var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("Plc1")); - // if (obj != null && obj.plc.IsConnected) - // { - // BoxLastShotRecord lastShotRecord = new BoxLastShotRecord(); - // byte[] info = obj.plc.ReadBytes("DB50.896", (ushort)88); - // IByteTransform byteTransform = new RegularByteTransform(); - - // lastShotRecord.System = "1"; - // lastShotRecord.GunCode = "A1"; - // lastShotRecord.GunCode = "A1"; - // #region 赋值 - // lastShotRecord.PolTemp = Encoding.ASCII.GetString(info.Skip(0).Take(4).ToArray()); - // lastShotRecord.PolHp = StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4); - // lastShotRecord.PolVol = StringChange.bytesToHexStr(info.Skip(8).Take(4).ToArray(), 4); - // lastShotRecord.PolUsage = StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4); - // lastShotRecord.IsoTemp = StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4); - // lastShotRecord.IsoHp = StringChange.bytesToHexStr(info.Skip(20).Take(4).ToArray(), 4); - // lastShotRecord.IsoVol = StringChange.bytesToHexStr(info.Skip(24).Take(4).ToArray(), 4); - // lastShotRecord.IsoUsage = StringChange.bytesToHexStr(info.Skip(28).Take(4).ToArray(), 4); - // lastShotRecord.PourNu = StringChange.bytesToHexStr(info.Skip(36).Take(2).ToArray(), 2); - // lastShotRecord.SetTime = StringChange.bytesToHexStr(info.Skip(38).Take(4).ToArray(), 4); - // lastShotRecord.SetWeight = StringChange.bytesToHexStr(info.Skip(42).Take(4).ToArray(), 4); - // lastShotRecord.SetRatio = StringChange.bytesToHexStr(info.Skip(46).Take(4).ToArray(), 4); - // lastShotRecord.PourWeight = StringChange.bytesToHexStr(info.Skip(50).Take(4).ToArray(), 4); - // lastShotRecord.PourRatio = StringChange.bytesToHexStr(info.Skip(54).Take(4).ToArray(), 4); - // lastShotRecord.MpTime = StringChange.bytesToHexStr(info.Skip(58).Take(4).ToArray(), 4); - // lastShotRecord.HpTime = StringChange.bytesToHexStr(info.Skip(62).Take(4).ToArray(), 4); - // lastShotRecord.HydrPress = StringChange.bytesToHexStr(info.Skip(66).Take(4).ToArray(), 4); - // lastShotRecord.HydrTemp = StringChange.bytesToHexStr(info.Skip(70).Take(4).ToArray(), 4); - // lastShotRecord.MixpistOn = StringChange.bytesToHexStr(info.Skip(74).Take(4).ToArray(), 4); - // lastShotRecord.MixpistOff = StringChange.bytesToHexStr(info.Skip(78).Take(4).ToArray(), 4); - // lastShotRecord.TotalYield = StringChange.bytesToHexStr(info.Skip(82).Take(4).ToArray(), 4); - // lastShotRecord.PourEnd = StringChange.bytesToHexStr(info.Skip(87).Take(1).ToArray(), 1); - // lastShotRecord.CreateTime = DateTime.Now; - // #endregion - - // //if (tempLastRecord == null) - // //{ - // // //数据库查 - // // tempLastRecord = _lastShotRecordServices.Query(x => x.System == lastShotRecord.System && x.ProductLineCode == lastShotRecord.ProductLineCode && x.GunCode == lastShotRecord.GunCode).OrderByDescending(x => x.CreateTime).FirstOrDefault(); - // //} - // //if (tempLastRecord == null || !tempLastRecord.MixpistOff.Equals(lastShotRecord.MixpistOff)) - // //{ - // // // 刷新页面 - // // RefreshLastShotDataDelegateEvent?.Invoke(lastShotRecord); - // // //保存 - // // _lastShotRecordServices.AddAsync(lastShotRecord); - // // tempLastRecord = lastShotRecord; - // //} - // } - //} #region 字符工具转换方法 /// byte[]转十进制ascii码 @@ -259,3 +320,4 @@ namespace Aucma.Core.DoorFoam.Business + diff --git a/Aucma.Core.DoorFoam/Models/FoamMachinesModel.cs b/Aucma.Core.DoorFoam/Models/FoamMachinesModel.cs index f145cb7f..ecef0ae1 100644 --- a/Aucma.Core.DoorFoam/Models/FoamMachinesModel.cs +++ b/Aucma.Core.DoorFoam/Models/FoamMachinesModel.cs @@ -12,299 +12,104 @@ namespace Aucma.Core.DoorFoam.Models { public partial class FoamMachinesModel { - #region 料位 /// - /// POL料位 + /// 系统编号;1系统 2系统 /// - public int Syst1_POLMaterialLevel { get; set; } + public string systemId { get; set; } /// - /// ISO料位 + /// 开关机信号 /// - public int Syst1_ISOMaterialLevel { get; set; } - #endregion + public string Machine_Status_0 { get; set; } - #region 温度 /// - /// Plo温度 + ///运行状态(自/手动) /// - public string Syst1_PolTmperature { get; set; } - /// - /// ISO温度 - /// - public string Syst1_IsoTmperature { get; set; } - - #endregion - - #region 压力 - /// - /// Pol压力 - /// - public string Syst1_PolPressure { get; set; } - - /// - /// Iso压力 - /// - public string Syst1_IsoPressure { get; set; } - - #endregion + public string Machine_Status_1 { get; set; } - #region 温度 /// - /// Iso温度 + ///POL料位 /// - public string Syst1_PolTemperature { get; set; } - /// - /// Iso温度 - /// - public string Syst1_IsoTemperature { get; set; } - #endregion + public string POL_Level { get; set; } - #region 输出压力 /// - /// POL输出压力 + ///POL温度 /// - public string Syst1_PolOutputPressure { get; set; } - /// - /// ISO输出压力 - /// - public string Syst1_IsoOutputPressure { get; set; } - #endregion + public string POL_Temp { get; set; } - #region 流量 - /// - /// POL流量 - /// - public string Syst1_PolFlow { get; set; } /// - /// ISO流量 + ///POL输入压力 /// - public string Syst1_IsoFlow { get; set; } - #endregion + public string POL_LP { get; set; } - #region 原料用量 - /// - /// POL流量 - /// - public string Syst1_PolMaterialLeve { get; set; } /// - /// ISO流量 + ///POL输出压力 /// - public string Syst1_IsoMaterialLeve { get; set; } - #endregion + public string POL_HP { get; set; } - #region 液压 - /// - /// 液压压力 - /// - public string Syst1_Pressure { get; set; } /// - /// 液压 + ///POL流量 /// - public string Syst1_Temperature { get; set; } - #endregion + public string POL_Vol { get; set; } - #region 结束信号 /// - /// A1结束信号 + ///POL原料用量 /// - public string Syst1_A1_End { get; set; } - /// - /// 结束信号 - /// - public string Syst1_B1_End { get; set; } - #endregion + public string POL_Usage { get; set; } - #region A1-B1 POL注料压力 /// - /// A1 POL注料压力 + ///POL变频器转速 /// - public string Syst1_A1_POLPressure { get; set; } - /// - /// B1 POL注料压力 - /// - public string Syst1_B1_POLPressure { get; set; } - #endregion + public string POL_Freq_Speed { get; set; } - #region A1-B1 POL注料温度 - /// - /// A1 POL注料温度 - /// - public string Syst1_A1_POLTemperature { get; set; } /// - /// B1 POL注料温度 + ///ISO料位 /// - public string Syst1_B1_POLTemperature { get; set; } - #endregion + public string ISO_Level { get; set; } - #region A1-B1 ISO注料压力 - /// - /// A1 ISO注料压力 - /// - public string Syst1_A1_ISOPressure { get; set; } /// - /// B1 ISO注料压力 + ///ISO温度 /// - public string Syst1_B1_ISOPressure { get; set; } - #endregion + public string ISO_Temp { get; set; } - #region A1-B1 ISO注料压力 - /// - /// A1 ISO注料压力 - /// - public string Syst1_A1_ISOTemperature { get; set; } /// - /// B1 ISO注料压力 + ///ISO输入压力 /// - public string Syst1_B1_ISOTemperature { get; set; } - #endregion + public string ISO_LP { get; set; } - - #region 系统2料位 /// - /// POL料位 + ///ISO输出压力 /// - public int Syst2_POLMaterialLevel { get; set; } + public string ISO_HP { get; set; } /// - /// ISO料位 + ///ISO流量 /// - public int Syst2_ISOMaterialLevel { get; set; } - #endregion + public string ISO_Vol { get; set; } - #region 系统2温度 - /// - /// Plo温度 - /// - public string Syst2_PolTmperature { get; set; } /// - /// ISO温度 + ///ISO原料用量 /// - public string Syst2_IsoTmperature { get; set; } + public string ISO_Usage { get; set; } - #endregion - - #region 系统2压力 /// - /// Pol压力 + ///ISO变频器转速 /// - public string Syst2_PolPressure { get; set; } + public string ISO_Freq_Speed { get; set; } /// - /// Iso压力 + ///液压压力 /// - public string Syst2_IsoPressure { get; set; } - - #endregion + public string Hydr_Press { get; set; } - #region 系统2温度 /// - /// Iso温度 + ///液压温度 /// - public string Syst2_PolTemperature { get; set; } - /// - /// Iso温度 - /// - public string Syst2_IsoTemperature { get; set; } - #endregion + public string Hydr_Temp { get; set; } - #region 系统2输出压力 - /// - /// POL输出压力 - /// - public string Syst2_PolOutputPressure { get; set; } - /// - /// ISO输出压力 - /// - public string Syst2_IsoOutputPressure { get; set; } - #endregion - - #region 系统2流量 - /// - /// POL流量 - /// - public string Syst2_PolFlow { get; set; } - /// - /// ISO流量 - /// - public string Syst2_IsoFlow { get; set; } - #endregion - - #region 系统2原料用量 - /// - /// POL流量 - /// - public string Syst2_PolMaterialLeve { get; set; } - /// - /// ISO流量 - /// - public string Syst2_IsoMaterialLeve { get; set; } - #endregion - - #region 系统2液压 - /// - /// 液压压力 - /// - public string Syst2_Pressure { get; set; } - /// - /// 液压 - /// - public string Syst2_Temperature { get; set; } - #endregion - - #region 系统2结束信号 - /// - /// A1结束信号 - /// - public string Syst2_A1_End { get; set; } - /// - /// 结束信号 - /// - public string Syst2_B1_End { get; set; } - #endregion - - #region 系统2 A1-B1 POL注料压力 - /// - /// A1 POL注料压力 - /// - public string Syst2_A1_POLPressure { get; set; } - /// - /// B1 POL注料压力 - /// - public string Syst2_B1_POLPressure { get; set; } - #endregion - - #region 系统2 A1-B1 POL注料温度 - /// - /// A1 POL注料温度 - /// - public string Syst2_A1_POLTemperature { get; set; } - /// - /// B1 POL注料温度 - /// - public string Syst2_B1_POLTemperature { get; set; } - #endregion - - #region 系统2 A1-B1 ISO注料压力 - /// - /// A1 ISO注料压力 - /// - public string Syst2_A1_ISOPressure { get; set; } - /// - /// B1 ISO注料压力 - /// - public string Syst2_B1_ISOPressure { get; set; } - #endregion - - #region 系统2 A1-B1 ISO注料压力 - /// - /// A1 ISO注料压力 - /// - public string Syst2_A1_ISOTemperature { get; set; } /// - /// B1 ISO注料压力 + ///采集时间 /// - public string Syst2_B1_ISOTemperature { get; set; } - #endregion + public DateTime collectTime { get; set; } } } diff --git a/Aucma.Core.DoorFoam/ViewModels/FoamMachinesPageViewModel.cs b/Aucma.Core.DoorFoam/ViewModels/FoamMachinesPageViewModel.cs index 0e5687d9..63425f66 100644 --- a/Aucma.Core.DoorFoam/ViewModels/FoamMachinesPageViewModel.cs +++ b/Aucma.Core.DoorFoam/ViewModels/FoamMachinesPageViewModel.cs @@ -4,6 +4,7 @@ using Admin.Core.Model; using Admin.Core.Model.ViewModels; using Admin.Core.Service; using Admin.Core.Tasks; +using Aucma.Core.DoorFoam.Business; using Aucma.Core.DoorFoam.Models; using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.Extensions.DependencyInjection; @@ -22,48 +23,188 @@ namespace Aucma.Core.DoorFoam.ViewModels public FoamMachinesPageViewModel() { - Job_BoxFoamLastData_Quartz.RefreshLastShotDataDelegateEvent += RefreshData; + CollectionFoamMachine.RefreshLastShotDataDelegateEvent += RefreshData; + CollectionFoamMachine.RefreshGunDataDelegateEvent += RefreshGunData; + CollectionFoamMachine.RefreshSystemDataDelegateEvent += RefreshSystemData; _boxLastShotRecordServices = App.ServiceProvider.GetService(); - // LoadData(); + LoadData(); //Task.WaitAll(LoadData()); } + + #region 刷新系统参数---系统1,系统2 + /// + /// 系统1,系统2数据刷新 + /// + public void RefreshSystemData(Dictionary keys) + { + foreach (KeyValuePair kvp in keys) + { + if (kvp.Key.Equals("1")) + { + RefreshSystem1(kvp.Value); + } + else if (kvp.Key.Equals("2")) + { + RefreshSystem2(kvp.Value); + + } + } + } + /// + /// 刷新系统1 + /// + /// + public void RefreshSystem1(FoamMachinesModel record) + { + PolInputPressure1 = record.POL_LP; + IsoInputPressure1 = record.ISO_LP; + PolOutputPressure1 = record.POL_HP; + IsoOutputPressure1 = record.ISO_HP; + PolFlow1 = record.POL_Vol; + IsoFlow1 = record.ISO_Vol; + PoleTmperature1 = record.POL_Temp; + IsoTemperature1 = record.ISO_Temp; + PolMaterialLevel1 = record.POL_Level; + IsoMaterialLevel1 = record.ISO_Level; + Pressure1 = record.Hydr_Press; + Temperature1 = record.Hydr_Temp; + } + /// + /// 刷新系统2 + /// + /// + public void RefreshSystem2(FoamMachinesModel record) + { + PolInputPressure2 = record.POL_LP; + IsoInputPressure2 = record.ISO_LP; + PolOutputPressure2 = record.POL_HP; + IsoOutputPressure2 = record.ISO_HP; + PolFlow2 = record.POL_Vol; + IsoFlow2 = record.ISO_Vol; + PoleTmperature2 = record.POL_Temp; + IsoTemperature2 = record.ISO_Temp; + PolMaterialLevel2 = record.POL_Level; + IsoMaterialLevel2 = record.ISO_Level; + Pressure2 = record.Hydr_Press; + Temperature2 = record.Hydr_Temp; + } + + #endregion + + + + #region 刷新每一枪数据 + /// + /// A1,B1,A2,B2枪数据刷新 + /// + public void RefreshGunData(Dictionary keys) + { + foreach (KeyValuePair kvp in keys) + { + if (kvp.Key.Equals("A1")) + { + RefreshA1(kvp.Value); + } + else if (kvp.Key.Equals("B1")) + { + RefreshB1(kvp.Value); + } + else if (kvp.Key.Equals("A2")) + { + RefreshA2(kvp.Value); + } + else if (kvp.Key.Equals("B2")) + { + RefreshB2(kvp.Value); + } + } + } + /// + /// 刷新A1数据 + /// + /// + public void RefreshA1(BoxLastShotRecord record) + { + POLPressure1a = record.PolHp; + POLTemperature1a = record.PolTemp; + ISOPressure1a = record.IsoHp; + ISOTemperature1a = record.IsoTemp; + } + /// + /// 刷新B1数据 + /// + /// + public void RefreshB1(BoxLastShotRecord record) + { + POLPressure1b = record.PolHp; + POLTemperature1b = record.PolTemp; + ISOPressure1b = record.IsoHp; + ISOTemperature1b = record.IsoTemp; + + } + /// + /// 刷新A2数据 + /// + /// + public void RefreshA2(BoxLastShotRecord record) + { + POLPressure2a = record.PolHp; + POLTemperature2a = record.PolTemp; + ISOPressure2a = record.IsoHp; + ISOTemperature2a = record.IsoTemp; + } + + /// + /// 刷新B2数据 + /// + /// + public void RefreshB2(BoxLastShotRecord record) + { + POLPressure2b = record.PolHp; + POLTemperature2b = record.PolTemp; + ISOPressure2b = record.IsoHp; + ISOTemperature2b = record.IsoTemp; + } + #endregion + + /// + /// datagrid刷新 + /// + /// public void RefreshData(BoxLastShotRecord record) { System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => { - string system = string.Empty; - if (record.System == "1") { + string system = string.Empty; + if (record.System == "1") + { system = "1系统"; - - // PolFlow1 = record.POLInjecFlowRate; - // IsoFlow1 = record.ISOInjecFlowRate; - // PoleTmperature1 = record.POLInjecTemperatureOfGunHead; - // IsoTemperature1 = record.ISOInjecTemperatureOfGunHead; + // PolFlow1 = record.POLInjecFlowRate; + // IsoFlow1 = record.ISOInjecFlowRate; + // PoleTmperature1 = record.POLInjecTemperatureOfGunHead; + // IsoTemperature1 = record.ISOInjecTemperatureOfGunHead; } - if (record.System == "2") { system = "2系统"; } - LastShotRecordDataGrid.Add(new LastShotRecordModel() - { - No = LastShotRecordDataGrid.Count+1, - System = system, - GunHead = record.GunCode, - // StationNumber = record.StationNumber, - PolInjectionpressure = record.PolHp, - IsoInjectionpressure = record.IsoHp, - PolInjectiontemperature = record.PolTemp, - IsoInjectiontemperature = record.IsoTemp, - LastTime = record.CreateTime, - Createtime = record.CreateTime - }); - + if (record.System == "2") { system = "2系统"; } + LastShotRecordModel model = new LastShotRecordModel(); + model.No = LastShotRecordDataGrid.Count + 1; + model.System = system; + model.GunHead = record.GunCode; + // StationNumber = record.StationNumber, + model.IsoInjectionpressure = record.PolHp; + model.IsoInjectionpressure = record.IsoHp; + model.PolInjectiontemperature = record.PolTemp; + model.IsoInjectiontemperature = record.IsoTemp; + model.PolInjectionpressure = record.PolHp; + model.StationNumber = record.PourNu; + model.LastTime = record.CreateTime; + model.Createtime = record.CreateTime; + LastShotRecordDataGrid.Insert(0, model); })); - } - - - + #region 加载DataGrid数据 private async Task LoadData() { @@ -74,29 +215,33 @@ namespace Aucma.Core.DoorFoam.ViewModels int i = 1; var list = await _boxLastShotRecordServices.QueryAsync(); if (list == null) return; - list.OrderByDescending(d => d.CreateTime); - foreach (var item in list.Take(50)) + list.OrderByDescending(d => d.CreateTime).Take(30); + foreach (var item in list) { string system = string.Empty; if (item.System == "1") { system = "1系统"; } if (item.System == "2") { system = "2系统"; } - LastShotRecordDataGrid.Add(new LastShotRecordModel() + LastShotRecordModel model = new LastShotRecordModel(); + if (LastShotRecordDataGrid.Count() == 0) + { + model.No = 1; + } + else { - No = i, - System = system, - GunHead=item.GunCode, - // StationNumber=item.StationNumber, - PolInjectionpressure = item.PolHp, - IsoInjectionpressure = item.IsoHp, - PolInjectiontemperature = item.PolTemp, - IsoInjectiontemperature = item.IsoTemp, - LastTime = item.CreateTime, - Createtime = item.CreateTime - }); - i++; - }; - // Datalist.Insert(0, Datalist[Datalist.Count - 1]); - // Datalist.RemoveAt(Datalist.Count - 1); + model.No = LastShotRecordDataGrid.Count() + 1; + } + model.No = i; + model.System = system; + model.GunHead = item.GunCode; + model.PolInjectionpressure = item.PolHp; + model.IsoInjectionpressure = item.IsoHp; + model.PolInjectiontemperature = item.PolTemp; + model.IsoInjectiontemperature = item.IsoTemp; + model.LastTime = item.CreateTime; + model.Createtime = item.CreateTime; + model.StationNumber = item.PourNu; + LastShotRecordDataGrid.Insert(0, model); + } })); } @@ -228,79 +373,103 @@ namespace Aucma.Core.DoorFoam.ViewModels get => _temperature1; set => SetProperty(ref _temperature1, value); } + + /// /// A枪状态 /// - private string _status1; - public string Status1 + //private string _status1a; + //public string Status1a + //{ + // get => _status1a; + // set => SetProperty(ref _status1a, value); + //} + + /// + /// pol压力 + /// + private string _POLPressure1a = "0.00"; + public string POLPressure1a { - get => _status1; - set => SetProperty(ref _status1, value); + get => _POLPressure1a; + set => SetProperty(ref _POLPressure1a, value); } + /// - /// B枪状态 + /// A枪POL温度 /// - private string _status11; - public string Status11 + private string _POLTemperature1a = "0.00"; + public string POLTemperature1a { - get => _status11; - set => SetProperty(ref _status11, value); + get => _POLTemperature1a; + set => SetProperty(ref _POLTemperature1a, value); } /// - /// 压力 + /// iso压力 /// - private string _POLPressure1 = "0.00"; - public string POLPressure1 + private string _ISOPressure1a = "0.00"; + public string ISOPressure1a { - get => _POLPressure1; - set => SetProperty(ref _POLPressure1, value); + get => _ISOPressure1a; + set => SetProperty(ref _ISOPressure1a, value); } /// - /// A枪POL温度 + /// iso温度 /// - private string _POLTemperature1 = "0.00"; - public string POLTemperature1 + private string _ISOTemperature1a = "0.0"; + public string ISOTemperature1a { - get => _POLTemperature1; - set => SetProperty(ref _POLTemperature1, value); + get => _ISOTemperature1a; + set => SetProperty(ref _ISOTemperature1a, value); } + /// - /// B枪POL温度 + /// B枪状态 /// - private string _POLTemperature11 = "0.0"; - public string POLTemperature11 + //private string _status1b; + //public string Status1b + //{ + // get => _status1b; + // set => SetProperty(ref _status1b, value); + //} + + /// + /// B枪pol压力 + /// + private string _POLPressure1b = "0.00"; + public string POLPressure1b { - get => _POLTemperature11; - set => SetProperty(ref _POLTemperature11, value); + get => _POLPressure1b; + set => SetProperty(ref _POLPressure1b, value); } + /// - /// 压力 + /// B枪POL温度 /// - private string _ISOPressure1 = "0.00"; - public string ISOPressure1 + private string _POLTemperature1b = "0.00"; + public string POLTemperature1b { - get => _ISOPressure1; - set => SetProperty(ref _ISOPressure1, value); + get => _POLTemperature1b; + set => SetProperty(ref _POLTemperature1b, value); } /// - /// 压力 + /// B枪iso压力 /// - private string _ISOPressure11 = "0.00"; - public string ISOPressure11 + private string _ISOPressure1b = "0.00"; + public string ISOPressure1b { - get => _ISOPressure11; - set => SetProperty(ref _ISOPressure11, value); + get => _ISOPressure1b; + set => SetProperty(ref _ISOPressure1b, value); } /// - /// 温度 + /// B枪iso温度 /// - private string _ISOTemperature11 = "0.0"; - public string ISOTemperature11 + private string _ISOTemperature1b = "0.0"; + public string ISOTemperature1b { - get => _ISOTemperature11; - set => SetProperty(ref _ISOTemperature11, value); + get => _ISOTemperature1b; + set => SetProperty(ref _ISOTemperature1b, value); } - #endregion #region 2系统属性 @@ -415,100 +584,92 @@ namespace Aucma.Core.DoorFoam.ViewModels get => _temperature2; set => SetProperty(ref _temperature2, value); } + /// - /// A枪状态 - /// - private string _status2 = ""; - public string Status2 - { - get => _status2; - set => SetProperty(ref _status2, value); - } - /// - /// B枪状态 + /// A枪POL压力 /// - private string _status12 = ""; - public string Status12 + private string _POLPressure2a = "0.00"; + public string POLPressure2a { - get => _status12; - set => SetProperty(ref _status12, value); + get => _POLPressure2a; + set => SetProperty(ref _POLPressure2a, value); } /// - /// 压力 + /// A枪POL温度 /// - private string _POLPressure2 = "0.00"; - public string POLPressure2 + private string _POLTemperature2a = "0.00"; + public string POLTemperature2a { - get => _POLPressure2; - set => SetProperty(ref _POLPressure2, value); + get => _POLTemperature2a; + set => SetProperty(ref _POLTemperature2a, value); } /// - /// 温度 + /// iso压力 /// - private string _POLTemperature2 = "0.00"; - public string POLTemperature2 + private string _ISOPressure2a = "0.00"; + public string ISOPressure2a { - get => _POLTemperature2; - set => SetProperty(ref _POLTemperature2, value); + get => _ISOPressure2a; + set => SetProperty(ref _ISOPressure2a, value); } /// - /// A枪压力 + /// iso温度 /// - private string _ISOPressure2 = "0.00"; - public string ISOPressure2 + private string _ISOTemperature2a = "0.0"; + public string ISOTemperature2a { - get => _ISOPressure2; - set => SetProperty(ref _ISOPressure2, value); + get => _ISOTemperature2a; + set => SetProperty(ref _ISOTemperature2a, value); } + /// - ///A枪温度 + /// B枪状态 /// - private string _ISOTemperature22 = "0.0"; - public string ISOTemperature22 - { - get => _ISOTemperature22; - set => SetProperty(ref _ISOTemperature22, value); - } + //private string _status2b; + //public string Status2b + //{ + // get => _status2b; + // set => SetProperty(ref _status2b, value); + //} + /// - /// B枪温度 + /// B枪pol压力 /// - private string _ISOTemperature222 = "0.0"; - public string ISOTemperature222 + private string _POLPressure2b = "0.00"; + public string POLPressure2b { - get => _ISOTemperature222; - set => SetProperty(ref _ISOTemperature222, value); + get => _POLPressure2b; + set => SetProperty(ref _POLPressure2b, value); } + /// - /// B枪温度 + /// B枪POL温度 /// - private string _POLPressure22 = "0.0"; - public string POLPressure22 + private string _POLTemperature2b = "0.00"; + public string POLTemperature2b { - get => _POLPressure22; - set => SetProperty(ref _POLPressure22, value); + get => _POLTemperature2b; + set => SetProperty(ref _POLTemperature2b, value); } - /// - /// B枪ISO温度 + /// B枪iso压力 /// - private string _POLTemperature22 = "0.0"; - public string POLTemperature22 + private string _ISOPressure2b = "0.00"; + public string ISOPressure2b { - get => _POLTemperature22; - set => SetProperty(ref _POLTemperature22, value); + get => _ISOPressure2b; + set => SetProperty(ref _ISOPressure2b, value); } - /// - /// B枪ISO压力 + /// B枪iso温度 /// - private string _ISOPressure22 = "0.0"; - public string ISOPressure22 + private string _ISOTemperature2b = "0.0"; + public string ISOTemperature2b { - get => _ISOPressure22; - set => SetProperty(ref _ISOPressure22, value); + get => _ISOTemperature2b; + set => SetProperty(ref _ISOTemperature2b, value); } - #endregion } } diff --git a/Aucma.Core.DoorFoam/ViewModels/IndexPageViewModel.cs b/Aucma.Core.DoorFoam/ViewModels/IndexPageViewModel.cs index 516ffd23..6aff577f 100644 --- a/Aucma.Core.DoorFoam/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.DoorFoam/ViewModels/IndexPageViewModel.cs @@ -32,6 +32,7 @@ namespace Aucma.Core.DoorFoam.ViewModels private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); private DoorCollection doorCollection = new DoorCollection(); + private CollectionFoamMachine collectionFoam = new CollectionFoamMachine(); public IndexPageViewModel() { doorCollection.RefreshDoorFoamMachineEvent += info => @@ -41,9 +42,15 @@ namespace Aucma.Core.DoorFoam.ViewModels Task.Run(() => { - Thread.Sleep(30000); + Thread.Sleep(1000*10); doorCollection.startCollect(); }); + + Task.Run(() => + { + Thread.Sleep(1000 * 10); + collectionFoam.startCollect(); + }); } #region 获取今天的数据 diff --git a/Aucma.Core.DoorFoam/Views/FoamMachinesPageView.xaml b/Aucma.Core.DoorFoam/Views/FoamMachinesPageView.xaml index ce551214..17d40323 100644 --- a/Aucma.Core.DoorFoam/Views/FoamMachinesPageView.xaml +++ b/Aucma.Core.DoorFoam/Views/FoamMachinesPageView.xaml @@ -44,7 +44,7 @@ - + @@ -54,7 +54,7 @@ - + @@ -147,7 +147,7 @@ - + @@ -233,7 +233,7 @@ - + @@ -246,11 +246,11 @@ - + - + @@ -258,11 +258,11 @@ - + - + @@ -270,27 +270,27 @@ - + - + - + - + - + @@ -429,7 +429,7 @@ - + @@ -441,16 +441,16 @@ - + - + - + @@ -458,11 +458,11 @@ - + - + @@ -470,11 +470,11 @@ - + - + @@ -482,11 +482,11 @@ - + - + diff --git a/Aucma.Core.DoorFoam/appsettings.json b/Aucma.Core.DoorFoam/appsettings.json index 03a7fd33..18151360 100644 --- a/Aucma.Core.DoorFoam/appsettings.json +++ b/Aucma.Core.DoorFoam/appsettings.json @@ -199,10 +199,10 @@ "PLCServer": [ { "Id": 1, - "EquipName": "泡前库Plc", + "EquipName": "FoamPlc", "PlcType": "Siemens", - "Enabled": false, - "IP": "10.10.93.41", + "Enabled": true, + "IP": "10.10.93.180", "Port": 102 }, {