From 793c587e416e291ffd5b8965d1b9052967a39af6 Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 3 Jan 2024 21:12:46 +0800 Subject: [PATCH 1/5] =?UTF-8?q?change-=E6=8F=90=E4=BA=A4=E5=8F=91=E6=B3=A1?= =?UTF-8?q?=E5=89=82=E6=95=B0=E6=8D=AE=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/CollectionFoamMachine.cs | 313 +++++++----- .../Models/FoamMachinesModel.cs | 275 ++--------- .../ViewModels/FoamMachinesPageViewModel.cs | 451 ++++++++++++------ 3 files changed, 534 insertions(+), 505 deletions(-) diff --git a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs index 2fc85f4e..bc826974 100644 --- a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs +++ b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs @@ -4,7 +4,7 @@ using Admin.Core.Model; using Aucma.Core.BoxFoam.Models; using Aucma.Core.BoxFoam.ViewModels; using Aucma.Core.HwPLc; - +using Microsoft.Extensions.DependencyInjection; using NetTaste; using NPOI.Util; using System; @@ -15,6 +15,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Documents; +using System.Windows.Forms; namespace Aucma.Core.BoxFoam.Business { @@ -23,29 +24,116 @@ namespace Aucma.Core.BoxFoam.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() + { + startCollect(); + } + + 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枪数据 - + semaphore.WaitOne(); + try + { + Thread.Sleep(3000); + var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamMachinePlc")); + 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; + semaphore.Release(); + } } - + }); } @@ -53,38 +141,54 @@ namespace Aucma.Core.BoxFoam.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(); - 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_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 temp10 = byteToFloat(info.Skip(82).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 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_Level = byteToFloat(info.Skip(82).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_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 temp17 = byteToFloat(info.Skip(162).Take(4).ToArray()); - float temp18 = byteToFloat(info.Skip(166).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(); + 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); + } } } @@ -92,98 +196,57 @@ namespace Aucma.Core.BoxFoam.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码 diff --git a/Aucma.Core.BoxFoam/Models/FoamMachinesModel.cs b/Aucma.Core.BoxFoam/Models/FoamMachinesModel.cs index ae1c0e71..7cf2182c 100644 --- a/Aucma.Core.BoxFoam/Models/FoamMachinesModel.cs +++ b/Aucma.Core.BoxFoam/Models/FoamMachinesModel.cs @@ -12,299 +12,104 @@ namespace Aucma.Core.BoxFoam.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.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs index 919dd492..41618ef3 100644 --- a/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs +++ b/Aucma.Core.BoxFoam/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.BoxFoam.Business; using Aucma.Core.BoxFoam.Models; using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.Extensions.DependencyInjection; @@ -22,48 +23,188 @@ namespace Aucma.Core.BoxFoam.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.BoxFoam.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.BoxFoam.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.BoxFoam.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 } } From c30e4bcee1931f394b63da37b36db79cf85784b7 Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 3 Jan 2024 21:16:37 +0800 Subject: [PATCH 2/5] =?UTF-8?q?change-=E4=BF=AE=E6=94=B9=E5=8F=91=E6=B3=A1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aucma.Core.BoxFoam/appsettings.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Aucma.Core.BoxFoam/appsettings.json b/Aucma.Core.BoxFoam/appsettings.json index b0c244d5..5e0df1b6 100644 --- a/Aucma.Core.BoxFoam/appsettings.json +++ b/Aucma.Core.BoxFoam/appsettings.json @@ -212,6 +212,14 @@ "Enabled": true, "IP": "10.10.93.1", "Port": 102 + }, + { + "Id": 3, + "EquipName": "foamMachinePlc", + "PlcType": "Siemens", + "Enabled": true, + "IP": "127.0.0.1", + "Port": 102 } ], "StoreInfo": { From 612708d072e271099a9968601a2135d96fc2385c Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 3 Jan 2024 21:23:46 +0800 Subject: [PATCH 3/5] change. --- .../ViewModels/FoamMonitorPageViewModel.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Aucma.Core.BoxFoam/ViewModels/FoamMonitorPageViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/FoamMonitorPageViewModel.cs index 23848209..f6bcb366 100644 --- a/Aucma.Core.BoxFoam/ViewModels/FoamMonitorPageViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/FoamMonitorPageViewModel.cs @@ -342,7 +342,7 @@ namespace Aucma.Core.BoxFoam.ViewModels else { // 白夜班切换 - ShiftChangeAsync(productLineCode, currentTeamTime); + ShiftChangeAsync(productLineCode); } } @@ -422,7 +422,7 @@ namespace Aucma.Core.BoxFoam.ViewModels } } - private async void ShiftChangeAsync(string productLineCode, CurrentTeamTime currentTeamTime) + private async void ShiftChangeAsync(string productLineCode) { try { @@ -434,9 +434,11 @@ namespace Aucma.Core.BoxFoam.ViewModels //更新计划表操作 - //CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync(); + CurrentTeamTime currentTeamTime = await _currentTeamTimeServices.FirstAsync(); + + // 更新当班时间 - currentTeamTime.TeamName = currentTeamTimeList.FirstOrDefault().TeamName; + currentTeamTime.TeamName = currentTeamTimeList.First().TeamName; currentTeamTime.StartTime = currentTeamTimeList.Min(d => d.StartTime); currentTeamTime.EndTime = currentTeamTimeList.Max(d => d.EndTime); bool result = await _currentTeamTimeServices.UpdateAsync(currentTeamTime); From ff8a61db8027b0680812b540249729ebf7021a21 Mon Sep 17 00:00:00 2001 From: "liulb@mesnac.com" Date: Thu, 4 Jan 2024 08:32:49 +0800 Subject: [PATCH 4/5] =?UTF-8?q?add=20=E9=92=A3=E9=87=91=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Admin.Core.Api/Admin.Core.Model.xml | 30 +++++++ .../IExecutePlanInfoRepository.cs | 2 + .../IRepository_New/ISysUserInfoRepository.cs | 7 +- .../IService_New/IExecutePlanInfoServices.cs | 4 + .../IService_New/ISysUserInfoServices.cs | 7 +- .../ViewModels/StationHourAmountView.cs | 44 ++++++++++ .../ExecutePlanInfoRepository.cs | 11 +++ .../Repository_New/SysUserInfoRepository.cs | 21 +---- .../Service_New/ExecutePlanInfoServices.cs | 13 ++- .../Service_New/SysUserInfoServices.cs | 17 ++-- .../ViewModels/OldBoxFoamPageViewModel.cs | 10 --- .../ViewModels/IndexPageViewModel.cs | 87 +++++++++++++++---- .../ViewModels/MainWindowViewModel.cs | 2 +- Aucma.Core.SheetMetal/appsettings.json | 2 +- 14 files changed, 182 insertions(+), 75 deletions(-) create mode 100644 Admin.Core.Model/ViewModels/StationHourAmountView.cs diff --git a/Admin.Core.Api/Admin.Core.Model.xml b/Admin.Core.Api/Admin.Core.Model.xml index 627bd715..4d660a64 100644 --- a/Admin.Core.Api/Admin.Core.Model.xml +++ b/Admin.Core.Api/Admin.Core.Model.xml @@ -4576,6 +4576,36 @@ 工位 + + + 产线编码 + + + + + 产线编码 + + + + + 时间 + + + + + 小时 + + + + + 背板数量 + + + + + 前板数量 + + 条码绑定扫描类型统计 diff --git a/Admin.Core.IRepository/IRepository_New/IExecutePlanInfoRepository.cs b/Admin.Core.IRepository/IRepository_New/IExecutePlanInfoRepository.cs index 5c31e18c..420d63e9 100644 --- a/Admin.Core.IRepository/IRepository_New/IExecutePlanInfoRepository.cs +++ b/Admin.Core.IRepository/IRepository_New/IExecutePlanInfoRepository.cs @@ -12,5 +12,7 @@ namespace Admin.Core.IRepository { Task> GetStationMaterialStats(string stationCode); Task> GetStationHourAmount(string stationCode); + + Task> GetStationSheetMetalHourAmountAsync(string stationCode); } } \ No newline at end of file diff --git a/Admin.Core.IRepository/IRepository_New/ISysUserInfoRepository.cs b/Admin.Core.IRepository/IRepository_New/ISysUserInfoRepository.cs index 3c074a5c..724c35a4 100644 --- a/Admin.Core.IRepository/IRepository_New/ISysUserInfoRepository.cs +++ b/Admin.Core.IRepository/IRepository_New/ISysUserInfoRepository.cs @@ -27,11 +27,6 @@ namespace Admin.Core.IRepository /// /// Task> GetProductLineInfo(string productLineCode); - /// - /// 根据工位查询时间 - /// - /// - /// - List GetStationHourAmountAsync(string stationCode); + } } \ No newline at end of file diff --git a/Admin.Core.IService/IService_New/IExecutePlanInfoServices.cs b/Admin.Core.IService/IService_New/IExecutePlanInfoServices.cs index 46f6967e..273d5c40 100644 --- a/Admin.Core.IService/IService_New/IExecutePlanInfoServices.cs +++ b/Admin.Core.IService/IService_New/IExecutePlanInfoServices.cs @@ -107,6 +107,10 @@ namespace Admin.Core.IService /// /// Task> GetStationMaterialStats(string stationCode); + + Task> GetStationSheetMetalHourAmountAsync(string stationCode); + + #endregion } } \ No newline at end of file diff --git a/Admin.Core.IService/IService_New/ISysUserInfoServices.cs b/Admin.Core.IService/IService_New/ISysUserInfoServices.cs index 3d770376..ed361950 100644 --- a/Admin.Core.IService/IService_New/ISysUserInfoServices.cs +++ b/Admin.Core.IService/IService_New/ISysUserInfoServices.cs @@ -36,11 +36,6 @@ namespace Admin.Core.IService /// /// Task GetProductLineInfo(string productLineCode); - /// - /// 根据工位查询小时 - /// - /// - /// - List GetStationHourAmountAsync(string stationCode); + } } \ No newline at end of file diff --git a/Admin.Core.Model/ViewModels/StationHourAmountView.cs b/Admin.Core.Model/ViewModels/StationHourAmountView.cs new file mode 100644 index 00000000..a02e588b --- /dev/null +++ b/Admin.Core.Model/ViewModels/StationHourAmountView.cs @@ -0,0 +1,44 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Admin.Core.Model.ViewModels +{ + public class StationHourAmountView + { + /// + /// 产线编码 + /// + [SugarColumn(ColumnName = "ROWNUM")] + public string RowNum { get; set; } + /// + /// 产线编码 + /// + [SugarColumn(ColumnName = "PRODUCTLINE_CODE")] + public string ProductlineCode { get; set; } + + /// + /// 时间 + /// + [SugarColumn(ColumnName = "PRODUCT_DATE")] + public string ProductDate { get; set; } + /// + /// 小时 + /// + [SugarColumn(ColumnName = "PRODUCT_HOUR")] + public string ProductHour { get; set; } + /// + /// 背板数量 + /// + [SugarColumn(ColumnName = "BACKPANELHOURAMOUNT")] + public string BackPanelHourAmount { get; set; } + /// + /// 前板数量 + /// + [SugarColumn(ColumnName = "SIDPANELHOURAMOUNT")] + public string SidPanelHourAmount { get; set; } + } +} diff --git a/Admin.Core.Repository/Repository_New/ExecutePlanInfoRepository.cs b/Admin.Core.Repository/Repository_New/ExecutePlanInfoRepository.cs index c8eb6bf6..89bf2811 100644 --- a/Admin.Core.Repository/Repository_New/ExecutePlanInfoRepository.cs +++ b/Admin.Core.Repository/Repository_New/ExecutePlanInfoRepository.cs @@ -2,6 +2,7 @@ using Admin.Core.Model; using SqlSugar; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; namespace Admin.Core.Repository @@ -24,5 +25,15 @@ namespace Admin.Core.Repository { return await Db.Queryable().AS("GET_STATION_HOURAMOUNT").Where("PRODUCTLINE_CODE = @stationCode", new { stationCode = stationCode }).ToListAsync(); } + + /// + /// 获取钣金生产小时数 + /// + /// + /// + public async Task> GetStationSheetMetalHourAmountAsync(string stationCode) + { + return await Db.Queryable().AS("GET_STATION_SHEETMETALHOURAMOUNT").ToListAsync(); + } } } \ No newline at end of file diff --git a/Admin.Core.Repository/Repository_New/SysUserInfoRepository.cs b/Admin.Core.Repository/Repository_New/SysUserInfoRepository.cs index 6d35c4ae..e95aaf86 100644 --- a/Admin.Core.Repository/Repository_New/SysUserInfoRepository.cs +++ b/Admin.Core.Repository/Repository_New/SysUserInfoRepository.cs @@ -6,6 +6,7 @@ using Admin.Core.Model.Model_New; using System.Collections.Generic; using System; using Microsoft.IdentityModel.Logging; +using System.Linq; namespace Admin.Core.Repository { @@ -56,24 +57,6 @@ namespace Admin.Core.Repository #endregion - /// - /// 获取班组小时数 - /// - /// - /// - public List GetStationHourAmountAsync(string stationCode) - { - List result = null; - try - { - result = Db.Queryable().AS("GET_STATION_HOURAMOUNT").Where("PRODUCTLINE_CODE = @stationCode", new { stationCode = stationCode }).ToList(); - - } - catch (Exception ex) - { - - } - return result; - } + } } \ No newline at end of file diff --git a/Admin.Core.Service/Service_New/ExecutePlanInfoServices.cs b/Admin.Core.Service/Service_New/ExecutePlanInfoServices.cs index 13942e25..87eb28d9 100644 --- a/Admin.Core.Service/Service_New/ExecutePlanInfoServices.cs +++ b/Admin.Core.Service/Service_New/ExecutePlanInfoServices.cs @@ -23,12 +23,13 @@ namespace Admin.Core.Service private readonly IProductPlanInfoServices _productPlanInfoServices; public ExecutePlanInfoServices(IBaseRepository dal, IProductOrderInfoServices productOrderInfoServices, - IProductPlanInfoServices productPlanInfoServices) + IProductPlanInfoServices productPlanInfoServices, IExecutePlanInfoRepository executePlanInfoRepository) { this._dal = dal; base.BaseDal = dal; _productOrderInfoServices = productOrderInfoServices; _productPlanInfoServices = productPlanInfoServices; + _executePlanInfoRepository = executePlanInfoRepository; } #region 计划删除 @@ -385,5 +386,15 @@ namespace Admin.Core.Service } return planInfos; } + + /// + /// 获取钣金生产小时数 + /// + /// + /// + public async Task> GetStationSheetMetalHourAmountAsync(string stationCode) + { + return await _executePlanInfoRepository.GetStationSheetMetalHourAmountAsync(stationCode); + } } } \ No newline at end of file diff --git a/Admin.Core.Service/Service_New/SysUserInfoServices.cs b/Admin.Core.Service/Service_New/SysUserInfoServices.cs index 47a49b81..47ca4939 100644 --- a/Admin.Core.Service/Service_New/SysUserInfoServices.cs +++ b/Admin.Core.Service/Service_New/SysUserInfoServices.cs @@ -29,14 +29,14 @@ namespace Admin.Core.IService public async Task> GetTeamData() { return await _sysUserInfoRepository.GetTeamData(); - + } public async Task GetTeamData(DateTime nowDate) { - var list= await _sysUserInfoRepository.GetTeamData(); + var list = await _sysUserInfoRepository.GetTeamData(); if (list.Count() == 0) return null; - CurrentTeamTimeView view = list.SingleOrDefault(d=>d.StartTime<= nowDate && nowDate <= d.EndTime); + CurrentTeamTimeView view = list.SingleOrDefault(d => d.StartTime <= nowDate && nowDate <= d.EndTime); if (view != null) return view; else @@ -67,14 +67,7 @@ namespace Admin.Core.IService var obj = list.SingleOrDefault(d => d.ProductlineCode == productLineCode); return obj; } - /// - /// 根据工位查询小时 - /// - /// - /// - public List GetStationHourAmountAsync(string stationCode) - { - return _sysUserInfoRepository.GetStationHourAmountAsync(stationCode); - } + + } } \ No newline at end of file diff --git a/Aucma.Core.OldBoxFoam/ViewModels/OldBoxFoamPageViewModel.cs b/Aucma.Core.OldBoxFoam/ViewModels/OldBoxFoamPageViewModel.cs index ef097755..5c658f63 100644 --- a/Aucma.Core.OldBoxFoam/ViewModels/OldBoxFoamPageViewModel.cs +++ b/Aucma.Core.OldBoxFoam/ViewModels/OldBoxFoamPageViewModel.cs @@ -2,28 +2,19 @@ using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Model.Model_New; -using Admin.Core.Model.ViewModels; -using Admin.Core.Service; -using Admin.Core.Tasks; using Aucma.Core.HwPLc; using Aucma.Core.OldBoxFoam.Business; using Aucma.Core.OldBoxFoam.Models; -using Aucma.Core.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using log4net; using Microsoft.Extensions.DependencyInjection; -using NPOI.SS.Formula.Functions; using System; -using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Numerics; -using System.Text; using System.Threading; using System.Threading.Tasks; using System.Timers; -using System.Windows.Documents; /** * 老发泡线监控 * */ @@ -300,7 +291,6 @@ namespace Aucma.Core.OldBoxFoam.ViewModels BoxFoamDataRealTime bfd = bfds.SingleOrDefault(d => d.FixtureBoxtype == bLis[j].FixtureBoxType && d.SerialNumber == bLis[j].ObjId); if (bfd != null) { - //更新计划数量 complateAmount = bLis[j].Yield - bfd.FixtureProductioncapacity; UpdateClampData(bLis[j], bfd); diff --git a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs index 5f99734f..c7b440b0 100644 --- a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs @@ -11,21 +11,15 @@ using System.Threading.Tasks; using Admin.Core.IService; using Microsoft.Extensions.DependencyInjection; using Aucma.Core.SheetMetal.Common; -using Admin.Core.Tasks; -using CommunityToolkit.Mvvm.Messaging; using LiveCharts; using LiveCharts.Wpf; using Admin.Core.Model; using System.Windows.Media; -using log4net; using Admin.Core.Common; using LiveCharts.Defaults; using Aucma.Core.SheetMetal.Business; -using static Aucma.Core.SheetMetal.Business.SheetMetalPlanTaskHandle; -using System.Threading; -using NetTaste; -using Aucma.Core.HwPLc; -using Admin.Core.Model.ViewModels; +using Admin.Core.Service; +using NPOI.SS.Formula.Functions; /* * 首页信息 */ @@ -34,9 +28,9 @@ namespace Aucma.Core.SheetMetal.ViewModels public partial class IndexPageViewModel : ObservableObject { protected readonly IExecutePlanInfoServices? _taskExecutionPlanInfoServices; - protected readonly ISysUserInfoServices? _sysUserInfoServices; - //private SheetMetalPlanTaskHandle _taskHandle = new SheetMetalPlanTaskHandle(); - + protected readonly IRecordBackPanelComplateServices _recordBackPanelComplateServices; + protected readonly IRecordSidePanelComplateServices _recordSidePanelComplateServices; + protected readonly IBaseBomInfoServices _baseBomInfoServices; private AppConfigHelper appConfig = new AppConfigHelper(); List list = new List() { new SelectModel() { @@ -55,14 +49,16 @@ namespace Aucma.Core.SheetMetal.ViewModels { _stationName = Appsettings.app("StationInfo", "StationName");//工位名称 _taskExecutionPlanInfoServices = App.ServiceProvider.GetService(); - _sysUserInfoServices = App.ServiceProvider.GetService(); + _recordBackPanelComplateServices = App.ServiceProvider.GetService(); + _recordSidePanelComplateServices = App.ServiceProvider.GetService(); + _baseBomInfoServices = App.ServiceProvider.GetService(); //Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod; //Job_SheetMetalTask_Quartz.SmTaskDelegateEvent += UpdatePlanSHow;//计划内容展示 //WeakReferenceMessenger.Default.Register(this, Recive); Task.WaitAll(LoadData()); - //InitEveryDayMethod(); AddSelectData();//添加下拉菜单 - //RefreshHourAmount();//小时产量 + RefreshHourAmount();//小时产量 + //RefreshMaterialStats();//型号产量 SheetMetalPlanTaskHandle.RefreshCurrentPlanInfoEvent += RefreshCurrentPlanInfo; } @@ -669,17 +665,20 @@ namespace Aucma.Core.SheetMetal.ViewModels App.Current.Dispatcher.Invoke((Action)(() => { //获取小时产量 - string stationCode = Appsettings.app("StoreInfo", "StationCode"); - List hourAmount = _sysUserInfoServices.GetStationHourAmountAsync(stationCode); + string stationCode = Appsettings.app("StationInfo", "StationCode"); + List hourAmount = _taskExecutionPlanInfoServices.GetStationSheetMetalHourAmountAsync(stationCode).Result; if (hourAmount != null) { Achievement.Clear(); ProductionHourList = new List(); - ChartValues hourAchievement = new ChartValues(); + //ChartValues hourAchievement = new ChartValues(); + ChartValues hourAchievement = new ChartValues(); foreach (var item in hourAmount) { + ObservablePoint point=new ObservablePoint(Convert.ToInt32(item.SIDPANELHOURAMOUNT), Convert.ToInt32(item.BACKPANELHOURAMOUNT)); ProductionHourList.Add(item.PRODUCT_HOUR); - hourAchievement.Add(Convert.ToDouble(item.PRODUCT_AMOUNT)); + hourAchievement.Add(point); + //hourAchievement.Add(Convert.ToDouble(item.PRODUCT_AMOUNT)); } var houeColumn = new ColumnSeries(); houeColumn.DataLabels = true; @@ -689,7 +688,57 @@ namespace Aucma.Core.SheetMetal.ViewModels Achievement.Add(houeColumn); } })); - } + } #endregion + + + + #region 刷新物料型号统计 + /// + /// 刷新物料型号统计 + /// + private void RefreshMaterialStats() + { + App.Current.Dispatcher.Invoke((Action)(() => + { + + //获取物料型号统计 + string stationCode = Appsettings.app("StationInfo", "StationCode"); + List materialStats = _taskExecutionPlanInfoServices.GetStationMaterialStats(stationCode).Result; + var baseBomInfoList = _baseBomInfoServices.QueryAsync().Result; + var taskExecutionPlanInfo=_taskExecutionPlanInfoServices.QueryAsync(d=>d.ProductLineCode== stationCode).Result; + var recordBackPanelList = _recordBackPanelComplateServices.QueryAsync().Result; + + //有问题,需要修改才可以 + var list = (from d in recordBackPanelList + join t in taskExecutionPlanInfo on d.PlanCode equals t.TaskCode + join b in baseBomInfoList on d.MaterialCode equals b.MaterialCode + select new + { + MaterialCode=b.MaterialCode, + ProductPlanCode=t.ProductPlanCode, + CompleteAmount= t.CompleteAmount + }).ToList(); + + if (list != null) + { + ModelStatistics.Clear(); + MaterialNameList = new List(); + ChartValues materialAchievement = new ChartValues(); + foreach (var item in materialStats) + { + MaterialNameList.Add(item.MATERIAL_NAME); + materialAchievement.Add(Convert.ToDouble(item.PRODUCT_AMOUNT)); + } + var materialColumn = new ColumnSeries(); + materialColumn.DataLabels = true; + materialColumn.Title = "型号"; + materialColumn.Values = materialAchievement; + materialColumn.Foreground = Brushes.White; + ModelStatistics.Add(materialColumn); + } + })); + #endregion + } } } diff --git a/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs index 8aa09389..515f5293 100644 --- a/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/MainWindowViewModel.cs @@ -10,7 +10,7 @@ using System.Windows.Interop; using System.Collections.ObjectModel; using Admin.Core.Common; using System.IO; -using Aucma.Core.PLc; +using Aucma.Core.HwPLc; using Aucma.Core.Scanner; using System.Linq; using System.Threading.Tasks; diff --git a/Aucma.Core.SheetMetal/appsettings.json b/Aucma.Core.SheetMetal/appsettings.json index 8114a567..f3054b0d 100644 --- a/Aucma.Core.SheetMetal/appsettings.json +++ b/Aucma.Core.SheetMetal/appsettings.json @@ -44,7 +44,7 @@ "ConnId": "AUCMA_SCADA", "DBType": 3, "Enabled": true, - "HitRate": 50, + "HitRate": 30, //"Connection": "Data Source=localhost;Initial Catalog=Hsdb;User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False", "Connection": "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.100.72.20)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB)));User ID=c##aucma_scada;Password=aucma;", "ProviderName": "System.Data.SqlClient" From 47fa29cd4c719d63646ad71211e9295d957c7fe1 Mon Sep 17 00:00:00 2001 From: liuwf Date: Thu, 4 Jan 2024 09:07:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?change-=E6=81=A2=E5=A4=8D=E7=AE=B1=E4=BD=93?= =?UTF-8?q?=E5=8F=91=E6=B3=A1=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/PerfusionCollection.cs | 247 ------------------ .../ViewModels/MainWindowViewModel.cs | 2 + .../Views/FoamMachinesPageView.xaml | 46 ++-- Aucma.Core.BoxFoam/appsettings.json | 2 +- .../Business/PerfusionCollection.cs | 23 +- 5 files changed, 43 insertions(+), 277 deletions(-) delete mode 100644 Aucam.Core.PerfusionService/Business/PerfusionCollection.cs diff --git a/Aucam.Core.PerfusionService/Business/PerfusionCollection.cs b/Aucam.Core.PerfusionService/Business/PerfusionCollection.cs deleted file mode 100644 index 1443c31f..00000000 --- a/Aucam.Core.PerfusionService/Business/PerfusionCollection.cs +++ /dev/null @@ -1,247 +0,0 @@ -using Admin.Core.Common.Helper; -using Admin.Core.IRepository; -using Admin.Core.IService; -using Admin.Core.Model; -using Admin.Core.Model.Model_New; -using Admin.Core.Repository; -using Admin.Core.Service; -using Aucma.Core.HwPLc; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Aucam.Core.PerfusionService.Business -{ - /// - /// 采集灌注数据 - /// - public class PerfusionCollection - { - Semaphore semaphore = new Semaphore(1, 1); - protected readonly IPerfusionRecordServices? _perfusionRecordServices ; - protected readonly IPerfusionAlarmServices ?_perfusionAlarmServices; - protected readonly IPerfusionDeviceStatusServices? _perfusionDeviceStatusServices; - - - private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); - private Perfusion_Record record = new Perfusion_Record(); - private Perfusion_Record temprRecord; - - private Perfusion_DeviceStatus perfusion_DeviceStatus = new Perfusion_DeviceStatus(); - private Perfusion_Alarm perfusion_Alarm = new Perfusion_Alarm(); - public PerfusionCollection(PerfusionRecordServices perfusionRecordServices, IPerfusionAlarmServices perfusionAlarmServices, IPerfusionDeviceStatusServices perfusionDeviceStatusServices) - { - _perfusionRecordServices = perfusionRecordServices; - _perfusionAlarmServices = perfusionAlarmServices; - _perfusionDeviceStatusServices = perfusionDeviceStatusServices; - startCollect(); - } - - - public void startCollect() - { - Task.Run(() => - { - while (true) - { - semaphore.WaitOne(); - try - { - Thread.Sleep(3000); - var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("PerfusionPlc")); - if (obj != null && obj.plc.IsConnected) - { - //采集数据 - ReadEquipSystem(obj,record, perfusion_DeviceStatus, perfusion_Alarm); - //更新设备状态 - // _perfusionDeviceStatusServices.UpdateAsync; - // 更新报警信息 - - //充注结束 - if (record.PerfusionFinishStatus == "1") - { - //缓存没数据查数据库 - if(temprRecord == null) - { - Perfusion_Record lastRecord = _perfusionRecordServices.Query(d => d.PerfusionBoxCode.Equals(record.PerfusionBoxCode)).FirstOrDefault(); - // 数据库没有数据 - if (lastRecord == null) - { - _= _perfusionRecordServices.AddAsync(record).Result; - return; - } - } - // 箱体码和上次不一样,或者箱体码一样但是充铸结果不一样 - else if(temprRecord.PerfusionBoxCode!=record.PerfusionBoxCode || (temprRecord.PerfusionBoxCode == record.PerfusionBoxCode && temprRecord.PerfusionResult!=record.PerfusionResult) ) - { - _ = _perfusionRecordServices.AddAsync(record).Result; - } - } - - } - - } - catch (Exception ex) - { - Console.WriteLine(ex); - } - finally - { - - temprRecord = record; - semaphore.Release(); - } - } - - }); - } - - /// - /// 采集灌注参数 - /// - /// - static void ReadEquipSystem(Aucma.Core.HwPLc.PlcModel obj, Perfusion_Record record, Perfusion_DeviceStatus deviceStatus, Perfusion_Alarm alarmInfo) - { - byte[] info = obj.plc.Read("DB55.0", 84); - if (info == null) return; - #region 灌注记录赋值 - record.PerfusionActualVolume=byteToDouble(info.Skip(0).Take(8).ToArray()).ToString(); - record.PerfusionR = byteToDouble(info.Skip(8).Take(4).ToArray()).ToString().ToString(); - record.PerfusionL = byteToFloat(info.Skip(55).Take(4).ToArray()).ToString(); - record.PerfusionDuration = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); - record.Yield = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber).ToString(); - record.PerfusionBoxCode = asciiEncoding.GetString(info.Skip(20).Take(24).ToArray()).Replace("\0", "").Trim('\n'); - record.PerfusionRefrigerantTypeLeft = asciiEncoding.GetString(info.Skip(58).Take(7).ToArray()).Trim('\n'); - record.PerfusionRefrigerantTypeRight = asciiEncoding.GetString(info.Skip(68).Take(7).ToArray()).Trim('\n'); - record.PerfusionSetVolume = byteToFloat(info.Skip(78).Take(4).ToArray()).ToString(); - record.PerfusionSystem =short.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - ///灌注完成状态字 - record.PerfusionFinishStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(46).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - record.PerfusionResult = short.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - record.CreatedBy = "equip"; - record.CreatedTime = DateTime.Now; - record.UpdatedBy = "equip"; - record.UpdatedTime = DateTime.Now; - #endregion - - #region 设备状态赋值 - deviceStatus.PerfusionDevicetype = "灌注"; - deviceStatus.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(50).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - deviceStatus.CreatedBy = "equip"; - deviceStatus.CreatedTime = DateTime.Now; - deviceStatus.UpdatedBy = "equip"; - deviceStatus.UpdatedTime = DateTime.Now; - #endregion - - #region 设备报警赋值 - alarmInfo.PerfusionBoxcode = record.PerfusionBoxCode; - alarmInfo.PerfusionStatus = short.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - alarmInfo.PerfusionAlarm = AlarmTrans(alarmInfo.PerfusionStatus); - alarmInfo.PerfusionCompleted = "1"; - alarmInfo.CreatedBy = "equip"; - alarmInfo.CreatedTime = DateTime.Now; - alarmInfo.UpdatedBy = "equip"; - alarmInfo.UpdatedTime = DateTime.Now; - #endregion - } - static string AlarmTrans(short code) - { - string result = ""; - switch (code) - { - case 2: result = "充注枪真空不合格"; break; - case 4: result = "充注故障"; break; - case 8: result = "充注时真空度超限定"; break; - case 16: result = "回升检测不合格"; break; - case 32: result = "工件真空不合格"; break; - case 64: result = "平衡缸接近开关异常"; break; - case 128: result = "增压超时"; break; - case 256: result = "风压不足"; break; - } - return result; - } - - - #region 字符工具转换方法 - /// byte[]转十进制ascii码 - /// - /// - static string ByteArrayToString(byte[] bytes) - { - string result = string.Empty; - foreach (byte b in bytes) - { - int decimalValue = Convert.ToInt32(b); // 将字节转换为十进制值 - result += decimalValue; - } - return result; - } - /// - /// byte[]转二进制 - /// - /// - static string ByteArrayToBinary(byte[] bytes) - { - StringBuilder binaryString = new StringBuilder(); - - foreach (byte b in bytes) - { - binaryString.Append(Convert.ToString(b, 2).PadLeft(8, '0')); - } - - // Console.WriteLine(binaryString); - - string reversedStr = new string(binaryString.ToString().Reverse().ToArray()); - // Console.WriteLine(reversedStr); - - return reversedStr; - } - - /// - /// 根据二进制字符串确定夹具状态 1正常生产 2暂停生产 - /// - static int judgeStatus(string str1) - { - int item1 = 0; - if (str1.Substring(0, 1) == "1") - { - item1 = 1; // - } - else if (str1.Substring(1, 1) == "1") - { - item1 = 2; // - } - return item1; - } - - - /// - /// byte数组转换为float - /// - static float byteToFloat(byte[] list) - { - float result = 0.00f; - Array.Reverse(list); - result = BitConverter.ToSingle(list, 0); - return result; - - } - - /// - /// byte数组转换为float - /// - static double byteToDouble(byte[] list) - { - double result = 0; - Array.Reverse(list); - result = BitConverter.ToDouble(list, 0); - return result; - - } - - #endregion - } -} diff --git a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs index 3b8c0389..d8b0e915 100644 --- a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs @@ -20,6 +20,8 @@ namespace Aucma.Core.BoxFoam.ViewModels private static readonly log4net.ILog log = LogManager.GetLogger(typeof(MainWindowViewModel)); private IndexPageView firstPage = new IndexPageView();//首页 CollectionFoamLine line=new CollectionFoamLine(); + CollectionFoamMachine machine = new CollectionFoamMachine(); + public MainWindowViewModel() { UserContent = firstPage; diff --git a/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml b/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml index 682ea649..b8f45f81 100644 --- a/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml +++ b/Aucma.Core.BoxFoam/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.BoxFoam/appsettings.json b/Aucma.Core.BoxFoam/appsettings.json index 5e0df1b6..b50af66b 100644 --- a/Aucma.Core.BoxFoam/appsettings.json +++ b/Aucma.Core.BoxFoam/appsettings.json @@ -218,7 +218,7 @@ "EquipName": "foamMachinePlc", "PlcType": "Siemens", "Enabled": true, - "IP": "127.0.0.1", + "IP": "10.10.93.180", "Port": 102 } ], diff --git a/Aucma.Core.Tasks/Business/PerfusionCollection.cs b/Aucma.Core.Tasks/Business/PerfusionCollection.cs index 9d331e68..355e4d9e 100644 --- a/Aucma.Core.Tasks/Business/PerfusionCollection.cs +++ b/Aucma.Core.Tasks/Business/PerfusionCollection.cs @@ -46,7 +46,6 @@ namespace Aucma.Core.Tasks.Business { while (true) { - semaphore.WaitOne(); try { Thread.Sleep(3000); @@ -56,9 +55,24 @@ namespace Aucma.Core.Tasks.Business //采集数据 ReadEquipSystem(obj,record, perfusion_DeviceStatus, perfusion_Alarm); //更新设备状态 - // _perfusionDeviceStatusServices.UpdateAsync; - // 更新报警信息 + Perfusion_DeviceStatus device = _perfusionDeviceStatusServices.FirstAsync().Result; + if (device == null) + { + _ = _perfusionDeviceStatusServices.AddAsync(perfusion_DeviceStatus).Result; + } + else + { + _perfusionDeviceStatusServices.UpdateAsync(perfusion_DeviceStatus); + } + //// 更新报警信息 + _perfusionAlarmServices.AddAsync(perfusion_Alarm); + //Perfusion_Alarm alarmRecord = _perfusionAlarmServices.FirstAsync(x=>x.PerfusionBoxcode==perfusion_Alarm.PerfusionBoxcode).Result; + //if (alarmRecord == null) + //{ + + //} + //充注结束 if (record.PerfusionFinishStatus == "1") { @@ -81,7 +95,6 @@ namespace Aucma.Core.Tasks.Business } } - } catch (Exception ex) { @@ -89,9 +102,7 @@ namespace Aucma.Core.Tasks.Business } finally { - temprRecord = record; - semaphore.Release(); } }