From 9825ad76e8bd99d84fa5b51f675db41213ea6267 Mon Sep 17 00:00:00 2001 From: liuwf Date: Mon, 1 Jan 2024 15:45:47 +0800 Subject: [PATCH 1/5] change. --- Aucma.Core.DoorFoam/appsettings.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Aucma.Core.DoorFoam/appsettings.json b/Aucma.Core.DoorFoam/appsettings.json index a7e5997d..4c09523e 100644 --- a/Aucma.Core.DoorFoam/appsettings.json +++ b/Aucma.Core.DoorFoam/appsettings.json @@ -199,9 +199,11 @@ "PLCServer": [ { "Id": 1, - "EquipName": "发泡Plc", + "EquipName": "门体发泡Plc", + "PlcType": "Siemens", + "Enabled": true, "IP": "127.0.0.1", - "Port": 6000 + "Port": 102 } ], "IpRateLimiting": { From 918b0157e6769337954c4b0c256d4270412a0dd8 Mon Sep 17 00:00:00 2001 From: liuwf Date: Mon, 1 Jan 2024 16:21:46 +0800 Subject: [PATCH 2/5] change --- .../Business/DoorCollection.cs | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Aucma.Core.DoorFoam/Business/DoorCollection.cs b/Aucma.Core.DoorFoam/Business/DoorCollection.cs index ae3bd209..237a65a2 100644 --- a/Aucma.Core.DoorFoam/Business/DoorCollection.cs +++ b/Aucma.Core.DoorFoam/Business/DoorCollection.cs @@ -59,14 +59,14 @@ namespace Aucma.Core.DoorFoam.Business // ReadModeStatus(obj, BoxTypeList); // 1-5 6-10 11-15 16-20 21-25 25-30 - // ReadModeType(obj, "DB4.142", BoxTypeList); + // ReadModeType(obj, "DB4.142", BoxTypeList); // ReadModeType(obj, "DB4.342", BoxTypeList); // ReadModeType(obj, "DB4.542", BoxTypeList); // ReadModeType(obj, "DB4.742", BoxTypeList); // ReadModeType(obj, "DB4.942", BoxTypeList); // ReadModeType(obj, "DB4.1142", BoxTypeList); // 31-34 - // ReadModeTypeLast(obj, "DB4.1342", BoxTypeList); + ReadModeTypeLast(obj, "DB4.1342", BoxTypeList); // ReadModeProduct(obj, "DB4.1542", BoxTypeList); // ReadModeProduct(obj, "DB4.1702", BoxTypeList); @@ -193,30 +193,30 @@ namespace Aucma.Core.DoorFoam.Business { if (obj.plc.IsConnected) { - byte[] info = obj.plc.Read(startStr, 200); + byte[] info = obj.plc.Read(startStr, 202); if (info == null) return; //1#台车1#枪A门,1#台车1#枪B门,1#台车2#枪A门,1#台车2#枪B门 - string temp1 = asciiEncoding.GetString(info.Skip(0).Take(10).ToArray()).Trim('\n'); - string temp2 = asciiEncoding.GetString(info.Skip(10).Take(10).ToArray()).Trim('\n'); - string temp3 = asciiEncoding.GetString(info.Skip(20).Take(10).ToArray()).Trim('\n'); - string temp4 = asciiEncoding.GetString(info.Skip(30).Take(10).ToArray()).Trim('\n'); - string temp5 = asciiEncoding.GetString(info.Skip(40).Take(10).ToArray()).Trim('\n'); - string temp6 = asciiEncoding.GetString(info.Skip(50).Take(10).ToArray()).Trim('\n'); - string temp7 = asciiEncoding.GetString(info.Skip(60).Take(10).ToArray()).Trim('\n'); - string temp8 = asciiEncoding.GetString(info.Skip(70).Take(10).ToArray()).Trim('\n'); - string temp9 = asciiEncoding.GetString(info.Skip(80).Take(10).ToArray()).Trim('\n'); - string temp10 = asciiEncoding.GetString(info.Skip(90).Take(10).ToArray()).Trim('\n'); - string temp11 = asciiEncoding.GetString(info.Skip(100).Take(10).ToArray()).Trim('\n'); - string temp12 = asciiEncoding.GetString(info.Skip(110).Take(10).ToArray()).Trim('\n'); - string temp13 = asciiEncoding.GetString(info.Skip(120).Take(10).ToArray()).Trim('\n'); - string temp14 = asciiEncoding.GetString(info.Skip(130).Take(10).ToArray()).Trim('\n'); - string temp15 = asciiEncoding.GetString(info.Skip(140).Take(10).ToArray()).Trim('\n'); - string temp16 = asciiEncoding.GetString(info.Skip(150).Take(10).ToArray()).Trim('\n'); - string temp17 = asciiEncoding.GetString(info.Skip(160).Take(10).ToArray()).Trim('\n'); - string temp18 = asciiEncoding.GetString(info.Skip(170).Take(10).ToArray()).Trim('\n'); - string temp19 = asciiEncoding.GetString(info.Skip(180).Take(10).ToArray()).Trim('\n'); - string temp20 = asciiEncoding.GetString(info.Skip(190).Take(10).ToArray()).Trim('\n'); + string temp1 = asciiEncoding.GetString(info.Skip(2).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp2 = asciiEncoding.GetString(info.Skip(12).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp3 = asciiEncoding.GetString(info.Skip(22).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp4 = asciiEncoding.GetString(info.Skip(32).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp5 = asciiEncoding.GetString(info.Skip(42).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp6 = asciiEncoding.GetString(info.Skip(52).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp7 = asciiEncoding.GetString(info.Skip(62).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp8 = asciiEncoding.GetString(info.Skip(72).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp9 = asciiEncoding.GetString(info.Skip(82).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp10 = asciiEncoding.GetString(info.Skip(92).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp11 = asciiEncoding.GetString(info.Skip(102).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp12 = asciiEncoding.GetString(info.Skip(112).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp13 = asciiEncoding.GetString(info.Skip(122).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp14 = asciiEncoding.GetString(info.Skip(132).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp15 = asciiEncoding.GetString(info.Skip(142).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp16 = asciiEncoding.GetString(info.Skip(152).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp17 = asciiEncoding.GetString(info.Skip(162).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp18 = asciiEncoding.GetString(info.Skip(172).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp19 = asciiEncoding.GetString(info.Skip(182).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp20 = asciiEncoding.GetString(info.Skip(192).Take(10).ToArray()).Trim('\n').Trim('\0'); Console.WriteLine(temp20); } @@ -232,27 +232,27 @@ namespace Aucma.Core.DoorFoam.Business { if (obj.plc.IsConnected) { - byte[] info = obj.plc.Read(startStr, 160); + byte[] info = obj.plc.Read(startStr, 162); if (info == null) return; //1#台车1#枪A门,1#台车1#枪B门,1#台车2#枪A门,1#台车2#枪B门 - string temp1 = asciiEncoding.GetString(info.Skip(0).Take(10).ToArray()).Trim('\n'); - string temp2 = asciiEncoding.GetString(info.Skip(10).Take(10).ToArray()).Trim('\n'); - string temp3 = asciiEncoding.GetString(info.Skip(20).Take(10).ToArray()).Trim('\n'); - string temp4 = asciiEncoding.GetString(info.Skip(30).Take(10).ToArray()).Trim('\n'); - string temp5 = asciiEncoding.GetString(info.Skip(40).Take(10).ToArray()).Trim('\n'); - string temp6 = asciiEncoding.GetString(info.Skip(50).Take(10).ToArray()).Trim('\n'); - string temp7 = asciiEncoding.GetString(info.Skip(60).Take(10).ToArray()).Trim('\n'); - string temp8 = asciiEncoding.GetString(info.Skip(70).Take(10).ToArray()).Trim('\n'); - string temp9 = asciiEncoding.GetString(info.Skip(80).Take(10).ToArray()).Trim('\n'); - string temp10 = asciiEncoding.GetString(info.Skip(90).Take(10).ToArray()).Trim('\n'); - string temp11 = asciiEncoding.GetString(info.Skip(100).Take(10).ToArray()).Trim('\n'); - string temp12 = asciiEncoding.GetString(info.Skip(110).Take(10).ToArray()).Trim('\n'); - string temp13 = asciiEncoding.GetString(info.Skip(120).Take(10).ToArray()).Trim('\n'); - string temp14 = asciiEncoding.GetString(info.Skip(130).Take(10).ToArray()).Trim('\n'); - string temp15 = asciiEncoding.GetString(info.Skip(140).Take(10).ToArray()).Trim('\n'); - string temp16 = asciiEncoding.GetString(info.Skip(150).Take(10).ToArray()).Trim('\n'); - + string temp1 = asciiEncoding.GetString(info.Skip(2).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp2 = asciiEncoding.GetString(info.Skip(12).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp3 = asciiEncoding.GetString(info.Skip(22).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp4 = asciiEncoding.GetString(info.Skip(32).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp5 = asciiEncoding.GetString(info.Skip(42).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp6 = asciiEncoding.GetString(info.Skip(52).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp7 = asciiEncoding.GetString(info.Skip(62).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp8 = asciiEncoding.GetString(info.Skip(72).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp9 = asciiEncoding.GetString(info.Skip(82).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp10 = asciiEncoding.GetString(info.Skip(92).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp11 = asciiEncoding.GetString(info.Skip(102).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp12 = asciiEncoding.GetString(info.Skip(112).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp13 = asciiEncoding.GetString(info.Skip(122).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp14 = asciiEncoding.GetString(info.Skip(132).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp15 = asciiEncoding.GetString(info.Skip(142).Take(10).ToArray()).Trim('\n').Trim('\0'); + string temp16 = asciiEncoding.GetString(info.Skip(152).Take(10).ToArray()).Trim('\n').Trim('\0'); + Console.WriteLine(temp16); } From 99e4752e98956283407c5971ddc89a799faf8500 Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 2 Jan 2024 00:15:07 +0800 Subject: [PATCH 3/5] change. --- .../Business/CollectionFoamLine.cs | 7 + .../Business/CollectionFoamMachine.cs | 306 +++++++----- .../Models/FoamMachinesModel.cs | 275 ++--------- .../ViewModels/FoamMachinesPageViewModel.cs | 456 ++++++++++++------ .../ViewModels/MainWindowViewModel.cs | 19 +- .../Views/FoamMachinesPageView.xaml | 38 +- Aucma.Core.BoxFoam/appsettings.json | 8 + 7 files changed, 572 insertions(+), 537 deletions(-) diff --git a/Aucma.Core.BoxFoam/Business/CollectionFoamLine.cs b/Aucma.Core.BoxFoam/Business/CollectionFoamLine.cs index 96a17064..25733a77 100644 --- a/Aucma.Core.BoxFoam/Business/CollectionFoamLine.cs +++ b/Aucma.Core.BoxFoam/Business/CollectionFoamLine.cs @@ -194,7 +194,9 @@ namespace Aucma.Core.BoxFoam.Business /// static void ReadFixtureStatus(HwPLc.PlcModel obj, List HolderStatusList) { + if (obj == null || !obj.plc.IsConnected) return; byte[] result = obj.plc.Read("DB8.122", 23); + if (result == null) return; byte[] info = result; int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray())); int temp2 = judgeStatus(ByteArrayToBinary(info.Skip(2).Take(1).ToArray())); @@ -235,6 +237,7 @@ namespace Aucma.Core.BoxFoam.Business if (obj.plc.IsConnected) { byte[] result = obj.plc.Read("DB8.146", 48); + if (result == null) return; byte[] info = result; int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); @@ -275,6 +278,7 @@ namespace Aucma.Core.BoxFoam.Business if (obj.plc.IsConnected) { byte[] result = obj.plc.Read("DB8.194", 48); + if (result == null) return; byte[] info = result; int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); @@ -316,6 +320,7 @@ namespace Aucma.Core.BoxFoam.Business if (obj.plc.IsConnected) { byte[] result = obj.plc.Read("DB8.242", 48); + if (result == null) return; byte[] info = result; int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); @@ -358,6 +363,7 @@ namespace Aucma.Core.BoxFoam.Business if (obj.plc.IsConnected) { byte[] info = obj.plc.Read("DB8.294", 284); + if(info == null) return; float temp1 = byteToFloat(info.Skip(0).Take(4).ToArray()); float temp2 = byteToFloat(info.Skip(16).Take(4).ToArray()); float temp3 = byteToFloat(info.Skip(24).Take(4).ToArray()); @@ -467,6 +473,7 @@ namespace Aucma.Core.BoxFoam.Business /// static void ReadLineStatus(HwPLc.PlcModel obj) { + if (obj == null || !obj.plc.IsConnected) return; byte[] result = obj.plc.Read("DB8.630", 1); byte[] info = result; int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray())); diff --git a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs index 63dd2ecc..07943210 100644 --- a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs +++ b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs @@ -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,27 +24,99 @@ 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; - + List foamMachinesList = new List(); + + Dictionary gunKeys = new Dictionary(); + Dictionary tempKeys = new Dictionary(); + // 系统参数 + Dictionary systemKeys = new Dictionary(); + Semaphore semaphore = new Semaphore(1, 1); + public CollectionFoamMachine() + { + startCollect(); + } + public void startCollect() { 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)) + { + RefreshLastShotDataDelegateEvent?.Invoke(kvPair.Value); + + } + // 关枪时间不同 + else if(!kvPair.Value.MixpistOff.Equals(tempKeys[kvPair.Key].MixpistOff)) + { + 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(); + } + } }); } @@ -52,38 +125,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()); - - 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()); - - float temp10 = byteToFloat(info.Skip(82).Take(4).ToArray()); - - 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()); - - 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()); - - float temp17 = byteToFloat(info.Skip(162).Take(4).ToArray()); - float temp18 = byteToFloat(info.Skip(166).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(); + + 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(); + + model.ISO_Level = byteToFloat(info.Skip(82).Take(4).ToArray()).ToString(); + + 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(); + + 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); + } } } @@ -91,99 +180,58 @@ 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 = ""; + + 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 6b91a444..32ae720b 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(); //Task.WaitAll(LoadData()); } - public void RefreshData(BoxLastShotRecord record) + + #region 刷新系统参数---系统1,系统2 + /// + /// 系统1,系统2数据刷新 + /// + public void RefreshSystemData(Dictionary keys) { - System.Windows.Application.Current.Dispatcher.Invoke((Action)(async () => + foreach (KeyValuePair kvp in keys) { - string system = string.Empty; - if (record.System == "1") { - system = "1系统"; - - // PolFlow1 = record.POLInjecFlowRate; - // IsoFlow1 = record.ISOInjecFlowRate; - // PoleTmperature1 = record.POLInjecTemperatureOfGunHead; - // IsoTemperature1 = record.ISOInjecTemperatureOfGunHead; + if (kvp.Key.Equals("1")) + { + RefreshSystem1(kvp.Value); + } + else if (kvp.Key.Equals("2")) + { + RefreshSystem2(kvp.Value); } - 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 - }); - - })); - + } + } + /// + /// 刷新系统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") + { + system = "1系统"; + // PolFlow1 = record.POLInjecFlowRate; + // IsoFlow1 = record.ISOInjecFlowRate; + // PoleTmperature1 = record.POLInjecTemperatureOfGunHead; + // IsoTemperature1 = record.ISOInjecTemperatureOfGunHead; + + } + 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,32 @@ 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(50); + 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) { - 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 = 1; + } + else + { + 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; + LastShotRecordDataGrid.Insert(0,model); + } })); } @@ -228,79 +372,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 +583,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 } } diff --git a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs index 3b8c0389..1669bbaf 100644 --- a/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/MainWindowViewModel.cs @@ -20,6 +20,13 @@ 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(); + RealTimeInventoryPageView realTimeInventoryPage = new RealTimeInventoryPageView(); + EnterWarehouseStatisticsPageView enterWarehouseStatisticsPage = new EnterWarehouseStatisticsPageView(); + FoamMonitorPageView foamMonitorPageView = new FoamMonitorPageView(); + FoamPlanPageView foamPlanPageView = new FoamPlanPageView(); + MonitorPageView monitorPage = new MonitorPageView();//任务监控 + FoamMachinesPageView foamMachinesPageView = new FoamMachinesPageView(); public MainWindowViewModel() { UserContent = firstPage; @@ -197,27 +204,27 @@ namespace Aucma.Core.BoxFoam.ViewModels UserContent = firstPage; break; case "RealTimeInventoryPage": - RealTimeInventoryPageView realTimeInventoryPage = new RealTimeInventoryPageView(); + // RealTimeInventoryPageView realTimeInventoryPage = new RealTimeInventoryPageView(); UserContent = realTimeInventoryPage; break; case "StatisticsPage": - EnterWarehouseStatisticsPageView enterWarehouseStatisticsPage = new EnterWarehouseStatisticsPageView(); + // EnterWarehouseStatisticsPageView enterWarehouseStatisticsPage = new EnterWarehouseStatisticsPageView(); UserContent = enterWarehouseStatisticsPage; break; case "MonitorPage": - MonitorPageView monitorPage = new MonitorPageView();//任务监控 + // MonitorPageView monitorPage = new MonitorPageView();//任务监控 UserContent = monitorPage; break; case "FoamPlanPage": - FoamPlanPageView foamPlanPageView = new FoamPlanPageView(); + // FoamPlanPageView foamPlanPageView = new FoamPlanPageView(); UserContent = foamPlanPageView; break; case "FoamMonitorPage": - FoamMonitorPageView foamMonitorPageView = new FoamMonitorPageView(); + // FoamMonitorPageView foamMonitorPageView = new FoamMonitorPageView(); UserContent = foamMonitorPageView; break; case "FoamMachinesPage": - FoamMachinesPageView foamMachinesPageView = new FoamMachinesPageView(); + // FoamMachinesPageView foamMachinesPageView = new FoamMachinesPageView(); UserContent = foamMachinesPageView; break; default: diff --git a/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml b/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml index 682ea649..a165faa9 100644 --- a/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml +++ b/Aucma.Core.BoxFoam/Views/FoamMachinesPageView.xaml @@ -147,7 +147,7 @@ - + @@ -233,7 +233,7 @@ - + @@ -246,11 +246,11 @@ - + - + @@ -258,11 +258,11 @@ - + - + @@ -270,22 +270,22 @@ - + - + - + - + @@ -429,7 +429,7 @@ - + @@ -446,11 +446,11 @@ - + - + @@ -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 06d8764a..9e3294d3 100644 --- a/Aucma.Core.BoxFoam/appsettings.json +++ b/Aucma.Core.BoxFoam/appsettings.json @@ -212,6 +212,14 @@ "Enabled": true, "IP": "127.0.0.1", "Port": 102 + }, + { + "Id": 2, + "EquipName": "foamMachinePlc", + "PlcType": "Siemens", + "Enabled": true, + "IP": "127.0.0.1", + "Port": 102 } ], "StoreInfo": { From 04237b6b7c5fb17f20417c26dc09b2389f1316d3 Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 2 Jan 2024 12:33:06 +0800 Subject: [PATCH 4/5] change. --- .../Business/CollectionFoamMachine.cs | 28 ++++++++++++++----- .../ViewModels/FoamMachinesPageViewModel.cs | 5 ++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs b/Aucma.Core.BoxFoam/Business/CollectionFoamMachine.cs index 07943210..63892959 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; @@ -50,6 +50,10 @@ namespace Aucma.Core.BoxFoam.Business // 系统参数 Dictionary systemKeys = new Dictionary(); Semaphore semaphore = new Semaphore(1, 1); + + private readonly IBoxLastShotRecordServices? _lastShotRecordServices = App.ServiceProvider.GetService(); + + public CollectionFoamMachine() { startCollect(); @@ -77,19 +81,29 @@ namespace Aucma.Core.BoxFoam.Business 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); } - // 关枪时间不同 - else if(!kvPair.Value.MixpistOff.Equals(tempKeys[kvPair.Key].MixpistOff)) + if (!kvPair.Value.MixpistOff.Equals(tempKeys[kvPair.Key].MixpistOff)) { + int b=_lastShotRecordServices.AddAsync(kvPair.Value).Result; RefreshLastShotDataDelegateEvent?.Invoke(kvPair.Value); } - + + } } @@ -190,7 +204,7 @@ namespace Aucma.Core.BoxFoam.Business BoxLastShotRecord lastShotRecord = new BoxLastShotRecord(); lastShotRecord.System = gunCode.Substring(1, 1); lastShotRecord.GunCode = gunCode; - lastShotRecord.ProductLineCode = ""; + lastShotRecord.ProductLineCode = "CX_02"; lastShotRecord.PolTemp = byteToFloat(info.Skip(0).Take(4).ToArray()).ToString(); lastShotRecord.PolHp = byteToFloat(info.Skip(4).Take(4).ToArray()).ToString(); diff --git a/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs b/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs index 32ae720b..389c4c2a 100644 --- a/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs +++ b/Aucma.Core.BoxFoam/ViewModels/FoamMachinesPageViewModel.cs @@ -27,7 +27,7 @@ namespace Aucma.Core.BoxFoam.ViewModels CollectionFoamMachine.RefreshGunDataDelegateEvent += RefreshGunData; CollectionFoamMachine.RefreshSystemDataDelegateEvent += RefreshSystemData; _boxLastShotRecordServices = App.ServiceProvider.GetService(); - + LoadData(); //Task.WaitAll(LoadData()); } @@ -215,7 +215,7 @@ namespace Aucma.Core.BoxFoam.ViewModels int i = 1; var list = await _boxLastShotRecordServices.QueryAsync(); if (list == null) return; - list.OrderByDescending(d => d.CreateTime).Take(50); + list.OrderByDescending(d => d.CreateTime).Take(30); foreach (var item in list) { string system = string.Empty; @@ -239,6 +239,7 @@ namespace Aucma.Core.BoxFoam.ViewModels model.IsoInjectiontemperature = item.IsoTemp; model.LastTime = item.CreateTime; model.Createtime = item.CreateTime; + model.StationNumber = item.PourNu; LastShotRecordDataGrid.Insert(0,model); } })); From b6cbd8dde9fece3f513569b1bf83f7fde252b524 Mon Sep 17 00:00:00 2001 From: liuwf Date: Tue, 2 Jan 2024 13:41:23 +0800 Subject: [PATCH 5/5] change. --- Aucma.Core.BoxFoam/appsettings.json | 4 ++-- Aucma.Core.HwPLc/Impl/SiemensPlc.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Aucma.Core.BoxFoam/appsettings.json b/Aucma.Core.BoxFoam/appsettings.json index 9e3294d3..eb78b1cd 100644 --- a/Aucma.Core.BoxFoam/appsettings.json +++ b/Aucma.Core.BoxFoam/appsettings.json @@ -214,11 +214,11 @@ "Port": 102 }, { - "Id": 2, + "Id": 3, "EquipName": "foamMachinePlc", "PlcType": "Siemens", "Enabled": true, - "IP": "127.0.0.1", + "IP": "10.10.93.180", "Port": 102 } ], diff --git a/Aucma.Core.HwPLc/Impl/SiemensPlc.cs b/Aucma.Core.HwPLc/Impl/SiemensPlc.cs index 2dfc82cd..279b9957 100644 --- a/Aucma.Core.HwPLc/Impl/SiemensPlc.cs +++ b/Aucma.Core.HwPLc/Impl/SiemensPlc.cs @@ -15,7 +15,7 @@ namespace Aucma.Core.HwPLc { private readonly log4net.ILog log = LogManager.GetLogger(typeof(MelsecPlc)); private SiemensS7Net siemensS7Net; - private SiemensPLCS siemensPLCS = SiemensPLCS.S1200; + private SiemensPLCS siemensPLCS = SiemensPLCS.S1500; #region 构造函数 //public MelsecPlc() @@ -37,6 +37,7 @@ namespace Aucma.Core.HwPLc // return; //} Console.WriteLine("HwCommunication激活成功!"); + siemensS7Net = new SiemensS7Net(siemensPLCS); siemensS7Net.ConnectTimeOut = 2000; Connect(iP, port);//建立连接 @@ -75,7 +76,7 @@ namespace Aucma.Core.HwPLc /// public bool Connect(string iP, int port) { - //siemensS7Net.IpAddress = iP;//正式环境开启 + siemensS7Net.IpAddress = iP;//正式环境开启 siemensS7Net.Port = port; try {