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; } } }