From 5f2390df7bf58a90bc1ee2eb4052a712443cc9ba Mon Sep 17 00:00:00 2001 From: wenjy Date: Fri, 12 Jan 2024 17:41:18 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E8=80=81=E7=BA=BF=E5=8F=91?= =?UTF-8?q?=E6=B3=A1=E6=B3=A8=E6=96=99=E6=B8=A9=E5=BA=A6=E3=80=81=E5=8E=8B?= =?UTF-8?q?=E5=8A=9B=E6=95=B0=E6=8D=AE=E9=87=87=E9=9B=86=EF=BC=8C=E8=BF=87?= =?UTF-8?q?=E7=82=B9=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model_New/MaterialCompletion.cs | 4 + .../RecordBoxFoamFixtureComplateServices.cs | 40 ++++- Aucma.Core.HwPLc/Aucma.Core.HwPLc.csproj | 3 + Aucma.Core.HwPLc/Impl/SiemensPlc.cs | 5 +- Aucma.Core.OldBoxFoam/Business/Collection.cs | 18 +- .../Business/CollectionFoamMachine.cs | 154 ++++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 45 ++++- Aucma.Core.OldBoxFoam/Views/MainWindow.xaml | 12 +- Aucma.Core.OldBoxFoam/appsettings.json | 16 ++ 9 files changed, 270 insertions(+), 27 deletions(-) create mode 100644 Aucma.Core.OldBoxFoam/Business/CollectionFoamMachine.cs diff --git a/Admin.Core.Model/Model_New/MaterialCompletion.cs b/Admin.Core.Model/Model_New/MaterialCompletion.cs index 75d3233e..b599da61 100644 --- a/Admin.Core.Model/Model_New/MaterialCompletion.cs +++ b/Admin.Core.Model/Model_New/MaterialCompletion.cs @@ -49,6 +49,10 @@ namespace Admin.Core.Model.Model_New [SugarColumn(ColumnName = "STATION_NAME")] public string StationName { get; set; } + + [SugarColumn(ColumnName = "PRODUCT_LINE_CODE")] + public string ProductLineCode { get; set; } + /// /// 完成时间 /// diff --git a/Admin.Core.Service/Service_New/RecordBoxFoamFixtureComplateServices.cs b/Admin.Core.Service/Service_New/RecordBoxFoamFixtureComplateServices.cs index f4bf345c..73ee1c05 100644 --- a/Admin.Core.Service/Service_New/RecordBoxFoamFixtureComplateServices.cs +++ b/Admin.Core.Service/Service_New/RecordBoxFoamFixtureComplateServices.cs @@ -31,7 +31,9 @@ namespace Admin.Core.Service.Service_New private readonly IProductPlanInfoServices _productPlanInfoServices; - public RecordBoxFoamFixtureComplateServices(IBaseRepository dal, IOldBoxFoamTypeServices boxFoamTypeServices, IBoxFoamPlanServices boxFoamPlanServices, IBoxFoamDataServices oldBoxFoamDataServices, ISysUserInfoServices sysUserInfoServices, IBaseSpaceInfoServices baseSpaceInfoServices, IProductPlanInfoServices productPlanInfoServices) + private readonly IMaterialCompletionServices _materialCompletionServices; + + public RecordBoxFoamFixtureComplateServices(IBaseRepository dal, IOldBoxFoamTypeServices boxFoamTypeServices, IBoxFoamPlanServices boxFoamPlanServices, IBoxFoamDataServices oldBoxFoamDataServices, ISysUserInfoServices sysUserInfoServices, IBaseSpaceInfoServices baseSpaceInfoServices, IProductPlanInfoServices productPlanInfoServices, IMaterialCompletionServices materialCompletionServices) { this._dal = dal; base.BaseDal = dal; @@ -41,6 +43,7 @@ namespace Admin.Core.Service.Service_New _sysUserInfoServices = sysUserInfoServices; _baseSpaceInfoServices = baseSpaceInfoServices; _productPlanInfoServices = productPlanInfoServices; + _materialCompletionServices = materialCompletionServices; } /// @@ -139,7 +142,7 @@ namespace Admin.Core.Service.Service_New Console.WriteLine($"生产计划更新成功:{boxPlan.CompleteAmount}"); //更新MES计划 - UpdateMesPlanInfo(boxPlan.PlanCode, item.RealOutPut); + UpdateMesPlanInfo(boxPlan.PlanCode, item.RealOutPut,stationCode, productLineCode); } else { @@ -319,7 +322,7 @@ namespace Admin.Core.Service.Service_New /// /// 更新MES计划信息 /// - private void UpdateMesPlanInfo(string planCode,int complateAmount) + private void UpdateMesPlanInfo(string planCode,int complateAmount,string stationCode, string productLine) { if (string.IsNullOrEmpty(planCode)) { @@ -338,8 +341,39 @@ namespace Admin.Core.Service.Service_New _productPlanInfoServices.UpdateProductPlanInfo(planInfo); } + + //保存过点数据 + SaveMaterialComplate(planInfo, complateAmount, stationCode, productLine); } } + + /// + /// 保存过点数据 + /// + /// + /// + /// + private void SaveMaterialComplate(ProductPlanInfo planInfo,int complateAmount,string stationCode,string productLine) + { + try + { + for (int i = 0; i < complateAmount; i++) + { + MaterialCompletion materialCompletion = new MaterialCompletion(); + materialCompletion.ProductLineCode = productLine; + materialCompletion.planCode = planInfo.PlanCode; + materialCompletion.OrderCode = planInfo.OrderCode; + materialCompletion.MaterialCode = planInfo.MaterialCode; + materialCompletion.MaterialName = planInfo.MaterialName; + materialCompletion.StationName = stationCode; + materialCompletion.CompleteDate = DateTime.Now; + _materialCompletionServices.AddAsync(materialCompletion); + } + }catch(Exception ex) + { + logHelper.Error($"保存过点数据异常:{ex.Message}"); + } + } } } diff --git a/Aucma.Core.HwPLc/Aucma.Core.HwPLc.csproj b/Aucma.Core.HwPLc/Aucma.Core.HwPLc.csproj index 8c7cca4e..6f71e4e6 100644 --- a/Aucma.Core.HwPLc/Aucma.Core.HwPLc.csproj +++ b/Aucma.Core.HwPLc/Aucma.Core.HwPLc.csproj @@ -10,6 +10,9 @@ + + ..\dll\HslCommunication.dll + ..\dll\HwCommunication.dll diff --git a/Aucma.Core.HwPLc/Impl/SiemensPlc.cs b/Aucma.Core.HwPLc/Impl/SiemensPlc.cs index 973bdf5b..59a35c58 100644 --- a/Aucma.Core.HwPLc/Impl/SiemensPlc.cs +++ b/Aucma.Core.HwPLc/Impl/SiemensPlc.cs @@ -1,6 +1,5 @@ -using HwCommunication; -using HwCommunication.Profinet.Melsec; -using HwCommunication.Profinet.Siemens; +using HslCommunication; +using HslCommunication.Profinet.Siemens; using log4net; using System; using System.Text; diff --git a/Aucma.Core.OldBoxFoam/Business/Collection.cs b/Aucma.Core.OldBoxFoam/Business/Collection.cs index 0ae8872d..bed84284 100644 --- a/Aucma.Core.OldBoxFoam/Business/Collection.cs +++ b/Aucma.Core.OldBoxFoam/Business/Collection.cs @@ -7,6 +7,7 @@ using Admin.Core.Service; using Aucma.Core.HwPLc; using Aucma.Core.OldBoxFoam.Models; using Consul; +using log4net; using Microsoft.Extensions.DependencyInjection; using NetTaste; using System; @@ -22,10 +23,7 @@ namespace Aucma.Core.OldBoxFoam.Business { public class Collection { - public HwPLc.PlcModel plc1 = null; - public HwPLc.PlcModel plc2 = null; - public HwPLc.PlcModel plc3 = null; - public HwPLc.PlcModel plc4 = null; + private readonly log4net.ILog log = LogManager.GetLogger(typeof(Collection)); public static List listFixtureStatus = new List(); public static List spaceDetailModel = new List(); @@ -59,10 +57,10 @@ namespace Aucma.Core.OldBoxFoam.Business listFixtureStatus = new List(); try { - plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); - plc2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); - plc3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3")); - plc4 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4")); + PlcModel plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); + PlcModel plc2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); + PlcModel plc3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3")); + PlcModel plc4 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4")); List spaceTypeList = ReadStoreType(plc1, plc3); List spaceAmountList = ReadStoreAmount(plc1, plc3); @@ -126,10 +124,10 @@ namespace Aucma.Core.OldBoxFoam.Business } } - catch (Exception) + catch (Exception ex) { - throw; + log.Error($"发泡线数据采集异常:{ex.Message}"); } } diff --git a/Aucma.Core.OldBoxFoam/Business/CollectionFoamMachine.cs b/Aucma.Core.OldBoxFoam/Business/CollectionFoamMachine.cs new file mode 100644 index 00000000..cc29240d --- /dev/null +++ b/Aucma.Core.OldBoxFoam/Business/CollectionFoamMachine.cs @@ -0,0 +1,154 @@ +using Admin.Core.Common.Helper; +using Admin.Core.IService; +using Admin.Core.Model; +using Aucma.Core.HwPLc; +using log4net; +using Microsoft.Extensions.DependencyInjection; +using NetTaste; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using static NPOI.HSSF.Util.HSSFColor; + +namespace Aucma.Core.OldBoxFoam.Business +{ + + public class CollectionFoamMachine + { + private readonly log4net.ILog log = LogManager.GetLogger(typeof(CollectionFoamMachine)); + + private readonly IBoxLastShotRecordServices? _lastShotRecordServices = App.ServiceProvider.GetService(); + + public void startCollect() + { + try + { + Task.Run(() => + { + Thread.Sleep(5000); + while(true) + { + List boxLastShots = new List(); + Thread.Sleep(10000); + var obj_1 = PlcHelper.siemensList.FirstOrDefault(d => d.Id == 5); + var obj_2 = PlcHelper.siemensList.FirstOrDefault(d => d.Id == 6); + + if (obj_1 != null) + { + #region 1#发泡机参数 + byte[] info = obj_1.plc.Read("VD600", 50); + var temp1 = byteToFloat(info.Skip(0).Take(4).ToArray()).ToString("0.00"); + var temp2 = byteToFloat(info.Skip(4).Take(4).ToArray()).ToString("0.00"); + var temp3 = byteToFloat(info.Skip(20).Take(4).ToArray()).ToString("0.00"); + var temp4 = byteToFloat(info.Skip(24).Take(4).ToArray()).ToString("0.00"); + + byte[] phInfo = obj_1.plc.Read("VD200", 100); + var pressure1 = byteToFloat(phInfo.Skip(0).Take(4).ToArray()).ToString("0.00"); + var pressure2 = byteToFloat(phInfo.Skip(20).Take(4).ToArray()).ToString("0.00"); + var pressure3 = byteToFloat(phInfo.Skip(40).Take(4).ToArray()).ToString("0.00"); + var pressure4 = byteToFloat(phInfo.Skip(60).Take(4).ToArray()).ToString("0.00"); + + #endregion + + boxLastShots.Add(new BoxLastShotRecord() + { + ProductLineCode = "CX_01", + StationNumber = "1105", + System = "1", + SystemStatus = 1, + PolTemp = temp1.ToString(), + IsoTemp = temp3.ToString(), + GunCode = "A1", + PolHp = pressure1.ToString(), + IsoHp = pressure3.ToString(), + CreateTime = DateTime.Now, + }); + + boxLastShots.Add(new BoxLastShotRecord() + { + ProductLineCode = "CX_01", + StationNumber = "1105", + System = "1", + SystemStatus = 1, + PolTemp = temp1.ToString(), + IsoTemp = temp3.ToString(), + GunCode = "B1", + PolHp = pressure2.ToString(), + IsoHp = pressure4.ToString(), + CreateTime = DateTime.Now, + }); + } + + if (obj_2 != null) + { + #region 2#发泡机参数 + + byte[] info = obj_1.plc.Read("VD600", 50); + var temp1 = byteToFloat(info.Skip(0).Take(4).ToArray()).ToString("0.00"); + var temp2 = byteToFloat(info.Skip(4).Take(4).ToArray()).ToString("0.00"); + var temp3 = byteToFloat(info.Skip(20).Take(4).ToArray()).ToString("0.00"); + var temp4 = byteToFloat(info.Skip(24).Take(4).ToArray()).ToString("0.00"); + + byte[] phInfo = obj_1.plc.Read("VD200", 100); + var pressure1 = byteToFloat(phInfo.Skip(0).Take(4).ToArray()).ToString("0.00"); + var pressure2 = byteToFloat(phInfo.Skip(20).Take(4).ToArray()).ToString("0.00"); + var pressure3 = byteToFloat(phInfo.Skip(40).Take(4).ToArray()).ToString("0.00"); + var pressure4 = byteToFloat(phInfo.Skip(60).Take(4).ToArray()).ToString("0.00"); + + #endregion + + boxLastShots.Add(new BoxLastShotRecord() + { + ProductLineCode = "CX_01", + StationNumber = "1105", + System = "2", + SystemStatus = 1, + PolTemp = temp1.ToString(), + IsoTemp = temp3.ToString(), + GunCode = "A2", + PolHp = pressure1.ToString(), + IsoHp = pressure3.ToString(), + CreateTime = DateTime.Now, + }); + + boxLastShots.Add(new BoxLastShotRecord() + { + ProductLineCode = "CX_01", + StationNumber = "1105", + System = "2", + SystemStatus = 1, + PolTemp = temp1.ToString(), + IsoTemp = temp3.ToString(), + GunCode = "B2", + PolHp = pressure2.ToString(), + IsoHp = pressure4.ToString(), + CreateTime = DateTime.Now, + }); + } + + _lastShotRecordServices.AddAsync(boxLastShots); + } + + }); + }catch(Exception ex) + { + log.Error($"发泡机参数采集异常:{ex.Message}"); + } + } + + /// + /// byte数组转换为float + /// + private float byteToFloat(byte[] list) + { + float result = 0.00f; + Array.Reverse(list); + result = BitConverter.ToSingle(list, 0); + return result; + + } + } +} diff --git a/Aucma.Core.OldBoxFoam/ViewModels/MainWindowViewModel.cs b/Aucma.Core.OldBoxFoam/ViewModels/MainWindowViewModel.cs index 3d67ea04..7e723958 100644 --- a/Aucma.Core.OldBoxFoam/ViewModels/MainWindowViewModel.cs +++ b/Aucma.Core.OldBoxFoam/ViewModels/MainWindowViewModel.cs @@ -26,11 +26,11 @@ namespace Aucma.Core.OldBoxFoam.ViewModels private FoamPlanPageView foamPlanPage = new FoamPlanPageView(); private RealRoadPageView realRoadPage = new RealRoadPageView(); private RoadKindPageView roadKindPage = new RoadKindPageView(); - + private CollectionFoamMachine collectionFoamMachine = new CollectionFoamMachine(); + public MainWindowViewModel() { UserContent = oldBoxFoamPage; - // 创建一个DispatcherTimer对象 DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); @@ -41,6 +41,8 @@ namespace Aucma.Core.OldBoxFoam.ViewModels { Init(); }); + + collectionFoamMachine.startCollect(); } public Task Init() @@ -107,12 +109,45 @@ namespace Aucma.Core.OldBoxFoam.ViewModels } } } + else + { + PlcUIColor.Clear(); + PlcState(false); + PlcState(false); + PlcState(false); + PlcState(false); + } - for(int i = PlcUIColor.Count - 1; i < 6; i++) + var machine = PlcHelper.siemensList.ToList(); + if (machine != null) { - PlcUIColor.Add("Red"); - PlcUIIcon.Add("Assets/Images/Red.png"); + if (machine.Count > 0) + { + machine = machine.OrderBy(x => x.Id).ToList(); + foreach (var item in machine) + { + if (item.plc.IsConnected) + { + PlcState(true); + } + else + { + PlcState(false); + } + } + } } + else + { + PlcState(false); + PlcState(false); + } + + //for(int i = PlcUIColor.Count - 1; i < 6; i++) + //{ + // PlcUIColor.Add("Red"); + // PlcUIIcon.Add("Assets/Images/Red.png"); + //} #region 原逻辑Delete By wenjy 2024-01-11 17:47:00 //var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); diff --git a/Aucma.Core.OldBoxFoam/Views/MainWindow.xaml b/Aucma.Core.OldBoxFoam/Views/MainWindow.xaml index 25cd3414..2cbbf053 100644 --- a/Aucma.Core.OldBoxFoam/Views/MainWindow.xaml +++ b/Aucma.Core.OldBoxFoam/Views/MainWindow.xaml @@ -87,42 +87,42 @@ - + - + - + - + - + - +