diff --git a/Admin.Core.Api/Admin.Core.Model.xml b/Admin.Core.Api/Admin.Core.Model.xml index a4821010..9c1d5724 100644 --- a/Admin.Core.Api/Admin.Core.Model.xml +++ b/Admin.Core.Api/Admin.Core.Model.xml @@ -2496,6 +2496,56 @@ 是否标识 + + + 完成记录 + + + + + 主键标识 + + + + + 计划编号 + + + + + 物料编号 + + + + + 计划工位 + + + + + 完成数量 + + + + + 下线数量 + + + + + 实际产量 + + + + + 记录时间 + + + + + 是否标识 + + 钣金每日生产记录表 diff --git a/Admin.Core.IService/IService_New/IRecordSidePanelComplateServices.cs b/Admin.Core.IService/IService_New/IRecordSidePanelComplateServices.cs new file mode 100644 index 00000000..f6ef5578 --- /dev/null +++ b/Admin.Core.IService/IService_New/IRecordSidePanelComplateServices.cs @@ -0,0 +1,14 @@ +using Admin.Core.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Admin.Core.IService +{ + public interface IRecordSidePanelComplateServices : IBaseServices + { + Task InsertSidePanelCimplate(RecordSidePanelComplate sidePanelComplate); + } +} diff --git a/Admin.Core.Model/Model_New/RecordSidePanelComplate.cs b/Admin.Core.Model/Model_New/RecordSidePanelComplate.cs new file mode 100644 index 00000000..27cf817e --- /dev/null +++ b/Admin.Core.Model/Model_New/RecordSidePanelComplate.cs @@ -0,0 +1,71 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Admin.Core.Model +{ + /// + /// 完成记录 + /// + [SugarTable("RECORD_SIDEPANEL_COMPLAte", "AUCMA_SCADA")] + public class RecordSidePanelComplate + { + /// + /// 主键标识 + /// + [SugarColumn(ColumnName = "OBJ_ID", IsPrimaryKey = true, OracleSequenceName = "SEQ_RECORD_SIDEPANEL_COMPLATE")] + public decimal ObjId { get; set; } + /// + /// 计划编号 + /// + [SugarColumn(ColumnName = "PLAN_CODE")] + public string PlanCode { get; set; } + /// + /// 物料编号 + /// + [SugarColumn(ColumnName = "MATERIAL_CODE")] + public string MaterialCode { get; set; } + /// + /// 计划工位 + /// + [SugarColumn(ColumnName = "PRODUCTLINE_CODE")] + public string ProductlineCode { get; set; } + /// + /// 完成数量 + /// + [SugarColumn(ColumnName = "COMPLETE_AMOUNT")] + public int CompleteAmount { get; set; } + + /// + /// 下线数量 + /// + [SugarColumn(ColumnName = "OFFLINE_AMOUNT")] + public int OffLineAmount { get; set; } + + /// + /// 实际产量 + /// + [SugarColumn(ColumnName = "OUTPUT_AMOUNT")] + public int OutPutAmount { get; set; } + + [SugarColumn(ColumnName = "DEVICE_STATUS")] + public decimal? DeviceStatus { get; set; } + + [SugarColumn(ColumnName = "PRODUCTION_BEAT")] + public decimal? ProductionBeat { get; set; } + + /// + /// 记录时间 + /// + [SugarColumn(ColumnName = "RECORD_TIME")] + public DateTime? RecordTime { get; set; } + /// + /// 是否标识 + /// + [SugarColumn(ColumnName = "IS_FLAG")] + public decimal? IsFlag { get; set; } + } +} diff --git a/Admin.Core.Service/Service_New/RecordSidePanelComplateServices.cs b/Admin.Core.Service/Service_New/RecordSidePanelComplateServices.cs new file mode 100644 index 00000000..17494499 --- /dev/null +++ b/Admin.Core.Service/Service_New/RecordSidePanelComplateServices.cs @@ -0,0 +1,41 @@ +using Admin.Core.IRepository; +using Admin.Core.IService; +using Admin.Core.Model; +using log4net; +using System; +using System.Threading.Tasks; + +namespace Admin.Core.Service +{ + /// + /// RecordProductFinishServices + /// + public class RecordSidePanelComplateServices : BaseServices, IRecordSidePanelComplateServices + { + private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(RecordOutStoreServices)); + private readonly IBaseRepository _dal; + public RecordSidePanelComplateServices(IBaseRepository dal) + { + this._dal = dal; + base.BaseDal = dal; + } + + + public async Task InsertSidePanelCimplate(RecordSidePanelComplate sidePanelComplate) + { + bool result = false; + try + { + int r =await _dal.AddAsync(sidePanelComplate); + if (r > 0) result=true; + + } + catch (Exception ex) + { + logHelper.Error("完成记录添加异常", ex); + } + + return result; + } + } +} \ No newline at end of file diff --git a/Aucma.Core.OldBoxFoam/Business/Collection.cs b/Aucma.Core.OldBoxFoam/Business/Collection.cs index c760ac11..154a2b27 100644 --- a/Aucma.Core.OldBoxFoam/Business/Collection.cs +++ b/Aucma.Core.OldBoxFoam/Business/Collection.cs @@ -21,12 +21,12 @@ namespace Aucma.Core.OldBoxFoam.Business public List listFixtureStatus = new List(); public List spaceDetailModel = new List(); - public List BoxTypeList = new List(); - public List HolderStatusList = new List(); - public List HolderOutPutList = new List(); - public List SolidifyTimeList = new List(); - public List StoreTypeList = new List(); - public List StoreAmountList = new List(); + public static List BoxTypeList = new List(); + public static List HolderStatusList = new List(); + public static List HolderOutPutList = new List(); + public static List SolidifyTimeList = new List(); + public static List StoreTypeList = new List(); + public static List StoreAmountList = new List(); public Collection() { @@ -133,9 +133,18 @@ namespace Aucma.Core.OldBoxFoam.Business /// /// 读取夹具箱型 /// - static void ReadBoxType(HwPLc.PlcModel obj, List BoxTypeList) + static void ReadBoxType(HwPLc.PlcModel obj, List HolderStatusList) { - if (obj == null) return; + if (obj == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } if (obj.plc.IsConnected) { @@ -156,6 +165,15 @@ namespace Aucma.Core.OldBoxFoam.Business BoxTypeList.Add(temp6); Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); } + else + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + } } /// @@ -163,7 +181,16 @@ namespace Aucma.Core.OldBoxFoam.Business /// static void ReadHolderStatus(PlcModel obj1, List HolderStatusList) { - if (obj1 == null) return; + if (obj1 == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] result = obj1.plc.Read("YF0", 1); if (result == null) return; //输出二进制字符串,1#-3#手动、自动数据 @@ -271,9 +298,27 @@ namespace Aucma.Core.OldBoxFoam.Business /// static void ReadHolderOutPut(PlcModel obj,List HolderOutPutList) { - if (obj == null) return; + if (obj == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] result = obj.plc.Read("D182", 24); - if (result == null) return; + if (result == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] info = result; int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(2).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); @@ -296,9 +341,27 @@ namespace Aucma.Core.OldBoxFoam.Business /// static void ReadSolidifyTime(PlcModel obj,List SolidifyTimeList) { - if (obj == null) return; + if (obj == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] result = obj.plc.Read("D910", 24); - if (result == null) return; + if (result == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] info = result; int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(2).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); @@ -320,10 +383,28 @@ namespace Aucma.Core.OldBoxFoam.Business /// static void ReadStoreType(PlcModel obj, List storeType) { - if (obj == null) return; + if (obj == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } //夹具箱型 byte[] result = obj.plc.Read("D2010", 40); - if (result == null) return; + if (result == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] info = result; int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(20).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); @@ -341,9 +422,27 @@ namespace Aucma.Core.OldBoxFoam.Business /// static void ReadStoreAmount(PlcModel obj, List storeAmount) { - if (obj == null) return; + if (obj == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } byte[] result = obj.plc.Read("L101", 1); - if (result == null) return; + if (result == null) + { + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + BoxTypeList.Add(0); + return; + } string str1 = ByteArrayToBinary(array(result)).Substring(0, 3); int item1 = Regex.Matches(str1, "1").Count; diff --git a/Aucma.Core.OldBoxFoam/Views/RealRoadPageView.xaml b/Aucma.Core.OldBoxFoam/Views/RealRoadPageView.xaml index 8af474ab..8600eca3 100644 --- a/Aucma.Core.OldBoxFoam/Views/RealRoadPageView.xaml +++ b/Aucma.Core.OldBoxFoam/Views/RealRoadPageView.xaml @@ -231,10 +231,25 @@ - - - - + + + + + + + + + + diff --git a/Aucma.Core.RunPlc/RunPlcService.cs b/Aucma.Core.RunPlc/RunPlcService.cs index 2f1e8685..1f161106 100644 --- a/Aucma.Core.RunPlc/RunPlcService.cs +++ b/Aucma.Core.RunPlc/RunPlcService.cs @@ -11,8 +11,8 @@ namespace Aucma.Core.RunPlc /// public class RunPlcService : IRunPlcService { - System.Timers.Timer timer = new System.Timers.Timer(5000);//创建定时器,设置间隔时间为1000毫秒; - + System.Timers.Timer timer = new System.Timers.Timer(3000);//创建定时器,设置间隔时间为1000毫秒; + System.Timers.Timer timer1 = new System.Timers.Timer(3000); #region 构造函数 public RunPlcService() { @@ -29,10 +29,10 @@ namespace Aucma.Core.RunPlc timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它, timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true; - timer.Elapsed += new System.Timers.ElapsedEventHandler(ExecSiemensHeartTask); - timer.AutoReset = true;//设置是执行一次(false)还是一直执行(true); - timer.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它, - timer.Start();//timer.Start()的内部原理还是设置timer.Enabled = true; + timer1.Elapsed += new System.Timers.ElapsedEventHandler(ExecSiemensHeartTask); + timer1.AutoReset = true;//设置是执行一次(false)还是一直执行(true); + timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它, + timer1.Start();//timer.Start()的内部原理还是设置timer.Enabled = true; return Task.CompletedTask; } @@ -87,7 +87,7 @@ namespace Aucma.Core.RunPlc { var item = PlcHelper.melsecList.Where(c => c.Id == i).FirstOrDefault(); if (item == null) continue; - if (await item.plc.Read("M100")) + if (item.plc.Read("M100").Result) { item.IsConnect = true; item.plc.IsConnected = true; diff --git a/Aucma.Core.SheetMetal/Business/SheetMetalPlanTaskHandle.cs b/Aucma.Core.SheetMetal/Business/SheetMetalPlanTaskHandle.cs index a3fef6ad..7b7db0dc 100644 --- a/Aucma.Core.SheetMetal/Business/SheetMetalPlanTaskHandle.cs +++ b/Aucma.Core.SheetMetal/Business/SheetMetalPlanTaskHandle.cs @@ -1,9 +1,11 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading; using System.Windows; +using System.Windows.Documents; using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.Model; @@ -25,127 +27,262 @@ public class SheetMetalPlanTaskHandle public event RefreshCurrentPlanInfo RefreshCurrentPlanInfoEvent; protected readonly IExecutePlanInfoServices? _executePlanInfoServices; - + protected readonly IRecordSidePanelComplateServices _sidePanelComplateServices; + public HwPLc.PlcModel plc1 = null; + public SheetMetalPlanTaskHandle() { _executePlanInfoServices = App.ServiceProvider.GetService(); + _sidePanelComplateServices = App.ServiceProvider.GetService(); } /// - /// 箱壳计划任务下发⾄设备PLC + /// 下发围板生产计划 /// - /// - public void SendPlanTaskToDevice() + /// + /// + public void SendPlanTask_WB(ExecutePlanInfo planInfo, PlcModel obj) { - - Thread.Sleep(5000); try { lock (string.Empty) { - string stationCode = Appsettings.app("StoreInfo", "StationCode"); - //获取待执⾏的计划,根据计划序号进⾏排序依次下发 - var list = _executePlanInfoServices.Query(d => - d.ProductLineCode.Equals(stationCode) && d.ExecuteStatus == 1); - if (list != null) + if (obj != null) { + //计划编号10个字:D6000-D6009、物料编号10个字:D6010-D6019、计划数量1个字:D6020、应答字1个字D6021 + obj.plc.WriteString("D6000", planInfo.TaskCode); + string processNumber = GetProcessNumberBy(planInfo.MaterialCode); + obj.plc.WriteString("D6010", "BCD/310NF"); + obj.plc.WriteInt32("D6020", planInfo.PlanAmount); + obj.plc.WriteInt32("D6021", 1); + + Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待围板设备应答。。。。。。"); + //下发完成后读取PLC应答,应答后复位应答信号 - if (list.Count > 0) + #region PLC反馈信号逻辑处理 + //循环读取PLC应答信号,PLC应答后复位应答信号、更新计划状态为执行中 + bool isFlag = true; + do { - ExecutePlanInfo task = list.OrderBy(x => x.ExecuteOrder).First(); - - var obj = PlcHelper.melsecList.FirstOrDefault(d => - d.EquipName.Equals("OldTypePlc1")); - if (obj != null) + if (obj.plc.ReadInt32("D6021") == 2) { - //计划编号10个字:D6000-D6009、物料编号10个字:D6010-D6019、计划数量1个字:D6020、应答字1个字D6021 - obj.plc.WriteString("D6000", task.TaskCode); - string processNumber = GetProcessNumberBy(task.MaterialCode); - obj.plc.WriteString("D6010", "BCD/310NF"); - obj.plc.WriteInt32("D6020", task.PlanAmount); - obj.plc.WriteInt32("D6021", 1); - - Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待设备应答。。。。。。"); - //下发完成后读取PLC应答,应答后复位应答信号 - ReadPlcFeedBack(obj); - - //更新计划状态为2执行中 - task.ExecuteStatus = 2; - _executePlanInfoServices.UpdateExecutePlanInfo(task); - RefreshCurrentPlanInfoEvent?.Invoke(task); - - //读取设备进度,完成后再次下发新任务 - ReadDeviceComplate(obj); + obj.plc.WriteInt32("D6021", 0); + Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到围板设备应答信号,复位应答地址"); + isFlag = false; } - } - else - { - Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>未获取到需要下发的生产计划!"); - } + Thread.Sleep(2000); + } while (isFlag); + + //更新计划状态为2执行中 + planInfo.ExecuteStatus = 2; + //SheetMetalPlanTaskHandle handle = new SheetMetalPlanTaskHandle(); + //plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); + //handle.SendPlanTask_WB(list, plc1); + _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + RefreshCurrentPlanInfoEvent?.Invoke(planInfo); + + #endregion + + //读取设备进度,完成后再次下发新任务 + ReadDeviceComplate_WB(obj); + } } } catch (Exception ex) { - MessageBox.Show($"箱壳⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error, + MessageBox.Show($"围板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } - + /// - /// 读取PLC应答反馈,PLC反馈后复位应答地址 + /// 读取围板生产数据 /// - private void ReadPlcFeedBack(PlcModel obj) + /// + public void ReadDeviceComplate_WB(PlcModel obj) { - bool isFlag = true; - if (obj != null) + try { do { + //计划编号:D6030-D6039,物料编号:D6040-D6049,计划完成数:D6050,计划下线数:D6051,设备状态:D6052-D6056,生产节拍:D6057-D6058 + byte[] info = obj.plc.Read("D6030", 59); + //计划编号 + string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()); + //物料编号 + string materialCode = Encoding.ASCII.GetString(info.Skip(20).Take(20).ToArray()); + //完成数量 + int complateAmount = short.Parse(bytesToHexStr(info.Skip(40).Take(1).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); + //下线数量 + int offLineAmount = short.Parse(bytesToHexStr(info.Skip(41).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); + //设备状态 + int deviceStatus = short.Parse(bytesToHexStr(info.Skip(43).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); + //生产节拍 + int productionBeat = short.Parse(bytesToHexStr(info.Skip(51).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); + + Console.WriteLine($"设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}"); + + //添加完工记录 + RecordSidePanelComplate sidePanelComplate = new RecordSidePanelComplate() + { + ProductlineCode = "1001", + PlanCode = planCode, + MaterialCode = materialCode, + CompleteAmount = complateAmount, + OffLineAmount = offLineAmount, + DeviceStatus = deviceStatus, + ProductionBeat = productionBeat, + RecordTime = DateTime.Now + }; - if (obj.plc.ReadInt32("D6021") == 1) + //先查询该计划编号下的前一条完工记录,如果不存在本条记录产量为0 + List sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1001" && x.PlanCode == planCode); + int lastComplateAmount = 0; //前一条完成记录的计划完成数量 + int sumComplateAmount = 0; //当前计划总产量 + if (sidePanelComplates != null) { - obj.plc.WriteInt32("D6021", 0); - Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到设备应答信号,复位应答地址"); - isFlag = false; + if (sidePanelComplates.Count > 0) + { + sidePanelComplates = sidePanelComplates.OrderByDescending(x => x.RecordTime).ToList(); + + lastComplateAmount = sidePanelComplates.First().CompleteAmount; + sidePanelComplate.OutPutAmount = complateAmount - lastComplateAmount; + sumComplateAmount = sidePanelComplates.Sum(x => x.OutPutAmount) + sidePanelComplate.OutPutAmount; + if (sidePanelComplate.OutPutAmount == 0) + { + Thread.Sleep(5000); + continue; + } + else + { + if (sumComplateAmount > 0) + { + ExecutePlanInfo planInfo = _executePlanInfoServices.Query(x => x.TaskCode.Equals(planCode.Substring(0, 13)) && x.ExecuteStatus == 2).FirstOrDefault(); + + if (planInfo != null) + { + if (sumComplateAmount > planInfo.CompleteAmount) + { + + if (planInfo.PlanAmount - sumComplateAmount == 0) + { + Console.WriteLine($"计划:{planCode},执行完成!!!"); + planInfo.CompleteAmount = sumComplateAmount; + planInfo.ExecuteStatus = 3; + _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + + isFlag = false; + } + else + { + Console.WriteLine( + $"设备当前计划:{planCode},计划数量:{planInfo.PlanAmount},实际完成:{sumComplateAmount},差异:{planInfo.PlanAmount - sumComplateAmount}"); + planInfo.CompleteAmount = sumComplateAmount; + _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + } + + RefreshCurrentPlanInfoEvent?.Invoke(planInfo); + } + } + } + } + + + } } - Thread.Sleep(2000); + + _sidePanelComplateServices.InsertSidePanelCimplate(sidePanelComplate); + + Thread.Sleep(5000); } while (isFlag); } + catch (Exception e) + { + Console.WriteLine($"读取设备完成数据异常:{e.Message}"); + } } + + /// - /// 读取设备完成数据 + /// 下发背板生产计划 /// + /// /// - public void ReadDeviceComplate(PlcModel obj) + public void SendPlanTaskTo_BB(ExecutePlanInfo planInfo, PlcModel obj) { - bool isFlag = true; - + Thread.Sleep(5000); try { - if (obj != null) + lock (string.Empty) { - do + if (obj != null) { - //计划编号:D6030-D6039,物料编号:D6040-D6049,计划完成数:D6050,计划下线数:D6051,设备状态:D6052-D6056,生产节拍:D6057-D6058 - - #region 单个地址读取 + //计划编号10个字:D6000-D6009、物料编号10个字:D6010-D6019、计划数量1个字:D6020、应答字1个字D6021 + obj.plc.WriteString("D6000", planInfo.TaskCode); + string processNumber = GetProcessNumberBy(planInfo.MaterialCode); + obj.plc.WriteString("D6010", "BCD/310NF"); + obj.plc.WriteInt32("D6020", planInfo.PlanAmount); + obj.plc.WriteInt32("D6021", 1); + + Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>等待背板设备应答。。。。。。"); + + #region PLC反馈信号逻辑处理 + //循环读取PLC应答信号,PLC应答后复位应答信号、更新计划状态为执行中 + bool isFlag = true; + do + { - /* - string planCode = obj.plc.ReadString("D6030"); - string materialCode = obj.plc.ReadString("D6040"); - int complateAmount = obj.plc.ReadInt32("D6050"); - int offLineAmount = obj.plc.ReadInt32("D6051"); - int productionBeat = obj.plc.ReadInt32("D6057"); - */ + if (obj.plc.ReadInt32("D6021") == 2) + { + obj.plc.WriteInt32("D6021", 0); + Console.WriteLine($"{DateTime.Now.ToString("HH:m:s")}===>收到背板板设备应答信号,复位应答地址"); + isFlag = false; + } + Thread.Sleep(2000); + } while (isFlag); + + //更新计划状态为2执行中 + planInfo.ExecuteStatus = 2; + _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + RefreshCurrentPlanInfoEvent?.Invoke(planInfo); #endregion - + + //读取设备进度,完成后再次下发新任务 + ReadDeviceComplate_BB(obj); + } + else + { + return; + } + } + } + catch (Exception ex) + { + MessageBox.Show($"背板⽣产计划下发异常:{ex.Message}", "提示", MessageBoxButton.OK, MessageBoxImage.Error, + MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); + } + } + + /// + /// 读取背板生产数据 + /// + /// + public void ReadDeviceComplate_BB(PlcModel obj) + { + bool isFlag = true; + + try + { + do + { + //计划编号:D6030-D6039,物料编号:D6040-D6049,计划完成数:D6050,计划下线数:D6051,设备状态:D6052-D6056,生产节拍:D6057-D6058 byte[] info = obj.plc.Read("D6030", 59); //计划编号 string planCode = Encoding.ASCII.GetString(info.Skip(0).Take(20).ToArray()); @@ -162,44 +299,87 @@ public class SheetMetalPlanTaskHandle Console.WriteLine($"设备数据读取====>>>>当前计划:{planCode},物料编号:{materialCode},完成数量:{complateAmount},下线数量:{offLineAmount},设备状态:{deviceStatus},生产节拍:{productionBeat}"); - //更新执行计划,差异值为0后任务结束再次下发新任务 - ExecutePlanInfo planInfo = _executePlanInfoServices.Query(x=>x.TaskCode.Equals(planCode.Substring(0,13)) && x.ExecuteStatus == 2).FirstOrDefault(); + //添加完工记录 + RecordSidePanelComplate sidePanelComplate = new RecordSidePanelComplate() + { + ProductlineCode = "1002", + PlanCode = planCode, + MaterialCode = materialCode, + CompleteAmount = complateAmount, + OffLineAmount = offLineAmount, + DeviceStatus = deviceStatus, + ProductionBeat = productionBeat, + RecordTime = DateTime.Now + }; - if (planInfo != null) + //先查询该计划编号下的前一条完工记录,如果不存在本条记录产量为0 + List sidePanelComplates = _sidePanelComplateServices.Query(x => x.ProductlineCode == "1002" && x.PlanCode == planCode); + int lastComplateAmount = 0; //前一条完成记录的计划完成数量 + int sumComplateAmount = 0; //当前计划总产量 + if (sidePanelComplates != null) { - if (complateAmount > planInfo.CompleteAmount) + if (sidePanelComplates.Count > 0) { - - if (planInfo.PlanAmount - complateAmount == 0) + sidePanelComplates = sidePanelComplates.OrderByDescending(x => x.RecordTime).ToList(); + + lastComplateAmount = sidePanelComplates.First().CompleteAmount; + sidePanelComplate.OutPutAmount = complateAmount - lastComplateAmount; + sumComplateAmount = sidePanelComplates.Sum(x => x.OutPutAmount) + sidePanelComplate.OutPutAmount; + if (sidePanelComplate.OutPutAmount == 0) { - Console.WriteLine($"计划:{planCode},执行完成!!!"); - planInfo.CompleteAmount = complateAmount; - planInfo.ExecuteStatus = 3; - _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); - - isFlag = false; + Thread.Sleep(5000); + continue; } else { - Console.WriteLine( - $"设备当前计划:{planCode},计划数量:{planInfo.PlanAmount},实际完成:{complateAmount},差异:{planInfo.PlanAmount - complateAmount}"); - planInfo.CompleteAmount = complateAmount; - _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + if (sumComplateAmount > 0) + { + ExecutePlanInfo planInfo = _executePlanInfoServices.Query(x=>x.TaskCode.Equals(planCode.Substring(0,13)) && x.ExecuteStatus == 2).FirstOrDefault(); + + if (planInfo != null) + { + if (sumComplateAmount > planInfo.CompleteAmount) + { + + if (planInfo.PlanAmount - sumComplateAmount == 0) + { + Console.WriteLine($"计划:{planCode},执行完成!!!"); + planInfo.CompleteAmount = sumComplateAmount; + planInfo.ExecuteStatus = 3; + _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + + isFlag = false; + } + else + { + Console.WriteLine( + $"设备当前计划:{planCode},计划数量:{planInfo.PlanAmount},实际完成:{sumComplateAmount},差异:{planInfo.PlanAmount - sumComplateAmount}"); + planInfo.CompleteAmount = sumComplateAmount; + _executePlanInfoServices.UpdateExecutePlanInfo(planInfo); + } + + RefreshCurrentPlanInfoEvent?.Invoke(planInfo); + } + } + } } + - RefreshCurrentPlanInfoEvent?.Invoke(planInfo); } } + _sidePanelComplateServices.InsertSidePanelCimplate(sidePanelComplate); + Thread.Sleep(5000); } while (isFlag); - } } catch (Exception e) { Console.WriteLine($"读取设备完成数据异常:{e.Message}"); } } + + /// /// 通过物料编号获取工艺编号 diff --git a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs index 620961f4..5dfe8c8a 100644 --- a/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/IndexPageViewModel.cs @@ -52,11 +52,10 @@ namespace Aucma.Core.SheetMetal.ViewModels { _taskExecutionPlanInfoServices = App.ServiceProvider.GetService(); - StationName = Appsettings.app("StoreInfo", "StationName"); + _stationName = Appsettings.app("StationInfo", "StationName"); Job_SheetMetalTask_Quartz.SmEverDayDelegateEvent += InitEveryDayMethod; Job_SheetMetalTask_Quartz.SmTaskDelegateEvent += UpdatePlanSHow;//计划内容展示 WeakReferenceMessenger.Default.Register(this, Recive); - Task.WaitAll(LoadData(), InitExecMethod()); InitEveryDayMethod(); @@ -69,7 +68,7 @@ namespace Aucma.Core.SheetMetal.ViewModels Task.Run(() => { Thread.Sleep(5000); - _taskHandle.SendPlanTaskToDevice(); + //_taskHandle.SendPlanTaskToDevice(); }); } #endregion @@ -631,7 +630,7 @@ namespace Aucma.Core.SheetMetal.ViewModels App.Current.Dispatcher.BeginInvoke((Action)(() => { PlanInfoDataGrid.Clear(); - LoadData(); + _= LoadData(); })); } } diff --git a/Aucma.Core.SheetMetal/ViewModels/QuantityIssuedViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/QuantityIssuedViewModel.cs index 66609248..b52b6cad 100644 --- a/Aucma.Core.SheetMetal/ViewModels/QuantityIssuedViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/QuantityIssuedViewModel.cs @@ -3,6 +3,7 @@ using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Service; using Aucma.Core.HwPLc; +using Aucma.Core.SheetMetal.Business; using Aucma.Core.SheetMetal.Models; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; @@ -13,6 +14,7 @@ using Microsoft.IdentityModel.Logging; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -102,10 +104,24 @@ namespace Aucma.Core.SheetMetal.ViewModels if (obj == null) { return; } if (obj.plc.IsConnected) { - obj.plc.WriteInt16("D8000", _TransmitAmount);//计划编号 - obj.plc.WriteInt16("D8009", _TransmitAmount);//计划编号 - obj.plc.WriteInt16("D8050", _TransmitAmount);//计划数量 - obj.plc.ReadInt16("D8021");//应答字 + //obj.plc.WriteInt16("D8000", _TransmitAmount);//计划编号 + //obj.plc.WriteInt16("D8009", _TransmitAmount);//计划编号 + //obj.plc.WriteInt16("D8050", _TransmitAmount);//计划数量 + //obj.plc.ReadInt16("D8021");//应答字 + SheetMetalPlanTaskHandle handle = new SheetMetalPlanTaskHandle(); + if (productPlanInfo.PlanType== 1) + { + handle.SendPlanTaskTo_BB(task, obj); + handle.SendPlanTask_WB(task, obj); + } + if (productPlanInfo.PlanType == 2) + { + handle.SendPlanTask_WB(task, obj); + } + if (productPlanInfo.PlanType == 2) + { + handle.SendPlanTaskTo_BB(task, obj); + } } MessageBox.Show("计划拆分成功!", "系统提醒"); WeakReferenceMessenger.Default.Send("Refresh");//刷新窗口 diff --git a/Aucma.Core.SheetMetal/ViewModels/SplitPlanViewModel.cs b/Aucma.Core.SheetMetal/ViewModels/SplitPlanViewModel.cs index d74096d7..23c2b0e2 100644 --- a/Aucma.Core.SheetMetal/ViewModels/SplitPlanViewModel.cs +++ b/Aucma.Core.SheetMetal/ViewModels/SplitPlanViewModel.cs @@ -19,6 +19,8 @@ using Aucma.Core.SheetMetal.Common; using System.Windows.Input; using Admin.Core.Common; using System.Drawing.Drawing2D; +using Aucma.Core.SheetMetal.Business; +using Aucma.Core.HwPLc; namespace Aucma.Core.SheetMetal.ViewModels { @@ -29,7 +31,7 @@ namespace Aucma.Core.SheetMetal.ViewModels //protected readonly ISmTaskExecutionServices? _smTaskExecutionServices; protected readonly IExecutePlanInfoServices? _executePlanInfoServices; private AppConfigHelper appConfig = new AppConfigHelper(); - + public SplitPlanViewModel() { _productPlanInfoServices = App.ServiceProvider.GetService(); @@ -141,6 +143,7 @@ namespace Aucma.Core.SheetMetal.ViewModels MessageBox.Show("请选中需要拆分的计划!", "系统提醒"); return; } + string productLineCode=Appsettings.app("StationInfo", "ProductLineCode"); string plan_code = SelectedCells.PlanCode; string order_code = SelectedCells.OrderCode; string material_code = SelectedCells.MaterialCode; @@ -165,6 +168,7 @@ namespace Aucma.Core.SheetMetal.ViewModels task.PlanAmount = SelectedCells.SpliteResidueAmount; task.CompleteAmount = 0; task.CreatedTime = DateTime.Now; + var result = await _executePlanInfoServices.AddAsync(task); if (result>0) { diff --git a/Aucma.Core.SheetMetal/Views/IndexPageView.xaml b/Aucma.Core.SheetMetal/Views/IndexPageView.xaml index 026b445b..e0177469 100644 --- a/Aucma.Core.SheetMetal/Views/IndexPageView.xaml +++ b/Aucma.Core.SheetMetal/Views/IndexPageView.xaml @@ -70,7 +70,7 @@ - + @@ -311,7 +311,7 @@ - + diff --git a/Aucma.Core.SheetMetal/appsettings.json b/Aucma.Core.SheetMetal/appsettings.json index 3443ee56..8392a81b 100644 --- a/Aucma.Core.SheetMetal/appsettings.json +++ b/Aucma.Core.SheetMetal/appsettings.json @@ -113,7 +113,7 @@ "Enabled": true } }, - "StoreInfo": { + "StationInfo": { "StationName": "箱壳前后板生产", "StationCode": "1001", "ShellStoreCode": "XKJCK-001", diff --git a/Aucma.Core.Tasks/AucamTaskService.cs b/Aucma.Core.Tasks/AucamTaskService.cs index 18fd863d..040d937f 100644 --- a/Aucma.Core.Tasks/AucamTaskService.cs +++ b/Aucma.Core.Tasks/AucamTaskService.cs @@ -17,62 +17,26 @@ namespace Aucma.Core.Tasks /// 老发泡线更新事件 /// /// - public delegate Task RefreshOldBoxFoamDataDelegate(List list); - public static event RefreshOldBoxFoamDataDelegate RefreshOldBoxFoamDataDelegateEvent; - private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(AucamTaskService)); - - private readonly IOldBoxFoamTypeServices _oldBoxFoamTypeServices; - private readonly IBoxFoamDataServices _oldBoxFoamDataServices; - private readonly ISysUserInfoServices _sysUserInfoServices; - private readonly ICurrentTeamTimeServices _currentTeamTimeServices; - private readonly IBoxFoamDataRecordServices _boxFoamDataRecordServices; - private readonly IBoxFoamPlanServices _boxFoamPlanServices; - private readonly IBoxDeviceInfoServices _boxDeviceInfoServices; - - public AucamTaskService(IOldBoxFoamTypeServices oldBoxFoamTypeServices, IBoxFoamDataServices oldBoxFoamDataServices, - ISysUserInfoServices sysUserInfoServices, ICurrentTeamTimeServices currentTeamTimeServices, - IBoxFoamDataRecordServices boxFoamDataRecordServices, IBoxDeviceInfoServices boxDeviceInfoServices - ) + public HwPLc.PlcModel plc1 = null; + public HwPLc.PlcModel plc2 = null; + public HwPLc.PlcModel plc3 = null; + public HwPLc.PlcModel plc4 = null; + public AucamTaskService() { - _oldBoxFoamTypeServices = oldBoxFoamTypeServices; - _oldBoxFoamDataServices = oldBoxFoamDataServices; - _sysUserInfoServices = sysUserInfoServices; - _currentTeamTimeServices = currentTeamTimeServices; - _boxFoamDataRecordServices = boxFoamDataRecordServices; - _boxDeviceInfoServices = boxDeviceInfoServices; } System.Timers.Timer timer1 = new System.Timers.Timer(1000); - System.Timers.Timer timer2 = new System.Timers.Timer(1000); - System.Timers.Timer timer3 = new System.Timers.Timer(1000); - System.Timers.Timer timer4 = new System.Timers.Timer(1000); bool qFlay=true;//前板标识 bool hFlay = true;//后板标识 public void AucamTaskAsync() { - //timer1.Elapsed += new System.Timers.ElapsedEventHandler(Run1); //到达时间的时候执行事件; - //timer1.AutoReset = true;//设置是执行一次(false)还是一直执行(true); - //timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它, - //timer1.Start();//timer.Start()的内部原理还是设置timer.Enabled = true; - - //timer2.Elapsed += new System.Timers.ElapsedEventHandler(Run2); //到达时间的时候执行事件; - //timer2.AutoReset = true; - //timer2.Enabled = true; - //timer2.Start(); - - //timer3.Elapsed += new System.Timers.ElapsedEventHandler(Run3); - //timer3.AutoReset = true; - //timer3.Enabled = true; - //timer3.Start(); - - //timer4.Elapsed += new System.Timers.ElapsedEventHandler(Run4); - //timer4.AutoReset = true; - //timer4.Enabled = true; - //timer4.Start(); - + timer1.Elapsed += new System.Timers.ElapsedEventHandler(Run1); //到达时间的时候执行事件; + timer1.AutoReset = true;//设置是执行一次(false)还是一直执行(true); + timer1.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它, + timer1.Start();//timer.Start()的内部原理还是设置timer.Enabled = true; } #region 钣金——前板 @@ -88,4265 +52,22 @@ namespace Aucma.Core.Tasks qFlay = false; try { - GetData(); - qFlay = true; - } - catch (Exception) - { - - throw; - } - finally - { - //List old = _oldBoxFoamDataServices.QueryAsync().Result; - //RefreshOldBoxFoamDataDelegateEvent?.Invoke(old); - } - - - } - - } + var plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); - #endregion - - #region 钣金——前板 - /// - /// 钣金——前板 - /// - /// - /// - private void Run2(object? sender, ElapsedEventArgs e) - { - if (qFlay) - { - qFlay = false; - try - { - GetData2(); - qFlay = true; } catch (Exception) { - qFlay = true; - throw; - } - finally - { - //List old = _oldBoxFoamDataServices.QueryAsync().Result; - //RefreshOldBoxFoamDataDelegateEvent?.Invoke(old); - } - - - } - - } - - #endregion - #region 钣金——前板 - /// - /// 钣金——前板 - /// - /// - /// - private void Run3(object? sender, ElapsedEventArgs e) - { - if (qFlay) - { - qFlay = false; - try - { - GetData3(); - qFlay = true; - } - catch (Exception) - { - qFlay = true; throw; } finally - { - //List old = _oldBoxFoamDataServices.QueryAsync().Result; - //RefreshOldBoxFoamDataDelegateEvent?.Invoke(old); - } - - - } - - } - - #endregion - - #region 钣金——前板 - /// - /// 钣金——前板 - /// - /// - /// - private void Run4(object? sender, ElapsedEventArgs e) - { - if (qFlay) - { - qFlay = false; - try - { - GetData4(); - qFlay = true; - } - catch (Exception) { qFlay = true; - throw; - } - finally - { - List old = _oldBoxFoamDataServices.QueryAsync().Result; - RefreshOldBoxFoamDataDelegateEvent?.Invoke(old); } - - } - } #endregion - public async void GetData() - { - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - try - { - List bfList = new List(); - List addList = new List(); - //var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); - //if (obj2 == null) { return; } - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); - if (obj == null) { return; } - - byte[] arr1 = obj.plc.ReadByte("D3140", (ushort)48); - if (arr1 == null) return; - //var arr1 = ArrReverse(bt); - - byte[] arr3 = obj.plc.ReadByte("D182", (ushort)24); - if (arr3 == null) return; - //var arr3 = ArrReverse(bt3); - byte[] arr4 = obj.plc.ReadByte("D910", (ushort)24); - if (arr4 == null) return; - //var arr4 = ArrReverse(bt4); - byte[] arr5 = obj.plc.ReadByte("T3", (ushort)24); - if (arr5 == null) return; - //var arr5 = ArrReverse(bt5); - - - string productLineCode = Appsettings.app("StationInfo", "ProductLineCode"); - List fdList = _oldBoxFoamDataServices.QueryAsync(d => d.ProductLineCode == productLineCode).Result; - - var fixtureboxtype1 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList1 = fdList.SingleOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 1); - if (oldList1 != null) - { - //只更新小时数量 - oldList1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr(result1, result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr(result2, result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr(result3, result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - oldList1.Fixturestatus = 1; - } - else - { - oldList1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList1.AnHour = num - oldList1.AnHour; - break; - case 2: - oldList1.TwoHour = num - oldList1.TwoHour; - break; - case 3: - oldList1.ThreeHour = num - oldList1.ThreeHour; - break; - case 4: - oldList1.FourHour = num - oldList1.FourHour; - break; - case 5: - oldList1.FiveHour = num - oldList1.FiveHour; - break; - case 6: - oldList1.SixHour = num - oldList1.SixHour; - break; - case 7: - oldList1.SevenHour = num - oldList1.SevenHour; - break; - case 8: - oldList1.EightHour = num - oldList1.EightHour; ; - break; - case 9: - oldList1.NineHour = num - oldList1.NineHour; - break; - case 10: - oldList1.TenHour = num - oldList1.TenHour; - break; - case 11: - oldList1.ElevenHour = num - oldList1.ElevenHour; - break; - case 12: - oldList1.TwelveHour = num - oldList1.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList1.Production = obj.plc.ReadInt16("D182");//short.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.UpdatedTime = DateTime.Now; - oldList1.ProductLineCode = "CX_01"; - oldList1.MainId = 1; - bfList.Add(oldList1); - //await _oldBoxFoamDataServices.UpdateAsync(oldList1); - } - else - { - BoxFoamData boxfoam1 = new BoxFoamData(); - //新增 - boxfoam1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - boxfoam1.Fixturestatus = 1; - } - else - { - boxfoam1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam1.AnHour = num; - break; - case 2: - boxfoam1.TwoHour = num; - break; - case 3: - boxfoam1.ThreeHour = num; - break; - case 4: - boxfoam1.FourHour = num; - break; - case 5: - boxfoam1.FiveHour = num; - break; - case 6: - boxfoam1.SixHour = num; - break; - case 7: - boxfoam1.SevenHour = num; - break; - case 8: - boxfoam1.EightHour = num; - break; - case 9: - boxfoam1.NineHour = num; - break; - case 10: - boxfoam1.TenHour = num; - break; - case 11: - boxfoam1.ElevenHour = num; - break; - case 12: - boxfoam1.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam1.Production = obj.plc.ReadInt16("D182");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.UpdatedTime = DateTime.Now; - boxfoam1.ProductLineCode = "CX_01"; - boxfoam1.MainId = 1; - addList.Add(boxfoam1); - //await _oldBoxFoamDataServices.AddAsync(boxfoam1); - } - - var fixtureboxtype2 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList2 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 2); - if (oldList2 != null) - { - oldList2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList2.AnHour = num - oldList2.AnHour; - break; - case 2: - oldList2.TwoHour = num - oldList2.TwoHour; - break; - case 3: - oldList2.ThreeHour = num - oldList2.ThreeHour; - break; - case 4: - oldList2.FourHour = num - oldList2.FourHour; - break; - case 5: - oldList2.FiveHour = num - oldList2.FiveHour; - break; - case 6: - oldList2.SixHour = num - oldList2.SixHour; - break; - case 7: - oldList2.SevenHour = num - oldList2.SevenHour; - break; - case 8: - oldList2.EightHour = num - oldList2.EightHour; ; - break; - case 9: - oldList2.NineHour = num - oldList2.NineHour; - break; - case 10: - oldList2.TenHour = num - oldList2.TenHour; - break; - case 11: - oldList2.ElevenHour = num - oldList2.ElevenHour; - break; - case 12: - oldList2.TwelveHour = num - oldList2.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.UpdatedTime = DateTime.Now; - oldList2.ProductLineCode = "CX_01"; - oldList2.MainId = 2; - bfList.Add(oldList2); - //await _oldBoxFoamDataServices.UpdateAsync(oldList2); - } - else - { - BoxFoamData boxfoam2 = new BoxFoamData(); - boxfoam2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - boxfoam2.Fixturestatus = 1; - } - else - { - boxfoam2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D183");//int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam2.AnHour = num; - break; - case 2: - boxfoam2.TwoHour = num; - break; - case 3: - boxfoam2.ThreeHour = num; - break; - case 4: - boxfoam2.FourHour = num; - break; - case 5: - boxfoam2.FiveHour = num; - break; - case 6: - boxfoam2.SixHour = num; - break; - case 7: - boxfoam2.SevenHour = num; - break; - case 8: - boxfoam2.EightHour = num; - break; - case 9: - boxfoam2.NineHour = num; - break; - case 10: - boxfoam2.TenHour = num; - break; - case 11: - boxfoam2.ElevenHour = num; - break; - case 12: - boxfoam2.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.UpdatedTime = DateTime.Now; - boxfoam2.MainId = 2; - boxfoam2.ProductLineCode = "CX_01"; - addList.Add(boxfoam2); - //await _oldBoxFoamDataServices.AddAsync(boxfoam2); - } - - var fixtureboxtype3 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(8).Take(9).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList3 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype3 && d.MainId == 3); - if (oldList3 != null) - { - oldList3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList3.AnHour = num - oldList3.AnHour; - break; - case 2: - oldList3.TwoHour = num - oldList3.TwoHour; - break; - case 3: - oldList3.ThreeHour = num - oldList3.ThreeHour; - break; - case 4: - oldList3.FourHour = num - oldList3.FourHour; - break; - case 5: - oldList3.FiveHour = num - oldList3.FiveHour; - break; - case 6: - oldList3.SixHour = num - oldList3.SixHour; - break; - case 7: - oldList3.SevenHour = num - oldList3.SevenHour; - break; - case 8: - oldList3.EightHour = num - oldList3.EightHour; ; - break; - case 9: - oldList3.NineHour = num - oldList3.NineHour; - break; - case 10: - oldList3.TenHour = num - oldList3.TenHour; - break; - case 11: - oldList3.ElevenHour = num - oldList3.ElevenHour; - break; - case 12: - oldList3.TwelveHour = num - oldList3.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList3.Production = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 1), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.UpdatedTime = DateTime.Now; - oldList3.MainId = 3; - oldList3.ProductLineCode = "CX_01"; - bfList.Add(oldList3); - //await _oldBoxFoamDataServices.UpdateAsync(oldList3); - } - else - { - BoxFoamData boxfoam3 = new BoxFoamData(); - boxfoam3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - boxfoam3.Fixturestatus = 1; - } - else - { - boxfoam3.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam3.AnHour = num; - break; - case 2: - boxfoam3.TwoHour = num; - break; - case 3: - boxfoam3.ThreeHour = num; - break; - case 4: - boxfoam3.FourHour = num; - break; - case 5: - boxfoam3.FiveHour = num; - break; - case 6: - boxfoam3.SixHour = num; - break; - case 7: - boxfoam3.SevenHour = num; - break; - case 8: - boxfoam3.EightHour = num; - break; - case 9: - boxfoam3.NineHour = num; - break; - case 10: - boxfoam3.TenHour = num; - break; - case 11: - boxfoam3.ElevenHour = num; - break; - case 12: - boxfoam3.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam3.Production = obj.plc.ReadInt16("D184");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.UpdatedTime = DateTime.Now; - boxfoam3.MainId = 3; - boxfoam3.ProductLineCode = "CX_01"; - addList.Add(boxfoam3); - //await _oldBoxFoamDataServices.AddAsync(boxfoam3); - } - - - var fixtureboxtype4 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(12).Take(13).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList4 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype4 && d.MainId == 4); - if (oldList4 != null) - { - oldList4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList4.Fixturestatus = 1; - } - else - { - oldList4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D185"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList4.AnHour = num - oldList4.AnHour; - break; - case 2: - oldList4.TwoHour = num - oldList4.TwoHour; - break; - case 3: - oldList4.ThreeHour = num - oldList4.ThreeHour; - break; - case 4: - oldList4.FourHour = num - oldList4.FourHour; - break; - case 5: - oldList4.FiveHour = num - oldList4.FiveHour; - break; - case 6: - oldList4.SixHour = num - oldList4.SixHour; - break; - case 7: - oldList4.SevenHour = num - oldList4.SevenHour; - break; - case 8: - oldList4.EightHour = num - oldList4.EightHour; ; - break; - case 9: - oldList4.NineHour = num - oldList4.NineHour; - break; - case 10: - oldList4.TenHour = num - oldList4.TenHour; - break; - case 11: - oldList4.ElevenHour = num - oldList4.ElevenHour; - break; - case 12: - oldList4.TwelveHour = num - oldList4.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - oldList4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(12).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.UpdatedTime = DateTime.Now; - oldList4.MainId = 4; - oldList4.ProductLineCode = "CX_01"; - bfList.Add(oldList4); - //await _oldBoxFoamDataServices.UpdateAsync(oldList4); - } - else - { - BoxFoamData boxfoam4 = new BoxFoamData(); - boxfoam4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam4.Fixturestatus = 1; - } - else - { - boxfoam4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam4.AnHour = num; - break; - case 2: - boxfoam4.TwoHour = num; - break; - case 3: - boxfoam4.ThreeHour = num; - break; - case 4: - boxfoam4.FourHour = num; - break; - case 5: - boxfoam4.FiveHour = num; - break; - case 6: - boxfoam4.SixHour = num; - break; - case 7: - boxfoam4.SevenHour = num; - break; - case 8: - boxfoam4.EightHour = num; - break; - case 9: - boxfoam4.NineHour = num; - break; - case 10: - boxfoam4.TenHour = num; - break; - case 11: - boxfoam4.ElevenHour = num; - break; - case 12: - boxfoam4.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.UpdatedTime = DateTime.Now; - boxfoam4.MainId = 4; - boxfoam4.ProductLineCode = "CX_01"; - addList.Add(boxfoam4); - //await _oldBoxFoamDataServices.AddAsync(boxfoam4); - } - - var fixtureboxtype5 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(16).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList5 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype5 && d.MainId == 5); - if (oldList5 != null) - { - oldList5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList5.Fixturestatus = 1; - } - else - { - oldList5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList5.AnHour = num - oldList5.AnHour; - break; - case 2: - oldList5.TwoHour = num - oldList5.TwoHour; - break; - case 3: - oldList5.ThreeHour = num - oldList5.ThreeHour; - break; - case 4: - oldList5.FourHour = num - oldList5.FourHour; - break; - case 5: - oldList5.FiveHour = num - oldList5.FiveHour; - break; - case 6: - oldList5.SixHour = num - oldList5.SixHour; - break; - case 7: - oldList5.SevenHour = num - oldList5.SevenHour; - break; - case 8: - oldList5.EightHour = num - oldList5.EightHour; ; - break; - case 9: - oldList5.NineHour = num - oldList5.NineHour; - break; - case 10: - oldList5.TenHour = num - oldList5.TenHour; - break; - case 11: - oldList5.ElevenHour = num - oldList5.ElevenHour; - break; - case 12: - oldList5.TwelveHour = num - oldList5.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList5.Production = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - oldList5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.UpdatedTime = DateTime.Now; - oldList5.MainId = 5; - oldList5.ProductLineCode = "CX_01"; - bfList.Add(oldList5); - //await _oldBoxFoamDataServices.UpdateAsync(oldList5); - } - else - { - BoxFoamData boxfoam5 = new BoxFoamData(); - boxfoam5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam5.Fixturestatus = 1; - } - else - { - boxfoam5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam5.AnHour = num; - break; - case 2: - boxfoam5.TwoHour = num; - break; - case 3: - boxfoam5.ThreeHour = num; - break; - case 4: - boxfoam5.FourHour = num; - break; - case 5: - boxfoam5.FiveHour = num; - break; - case 6: - boxfoam5.SixHour = num; - break; - case 7: - boxfoam5.SevenHour = num; - break; - case 8: - boxfoam5.EightHour = num; - break; - case 9: - boxfoam5.NineHour = num; - break; - case 10: - boxfoam5.TenHour = num; - break; - case 11: - boxfoam5.ElevenHour = num; - break; - case 12: - boxfoam5.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam5.Production = obj.plc.ReadInt16("D186"); int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.UpdatedTime = DateTime.Now; - boxfoam5.MainId = 5; - boxfoam5.ProductLineCode = "CX_01"; - addList.Add(boxfoam5); - //await _oldBoxFoamDataServices.AddAsync(boxfoam5); - } - var fixtureboxtype6 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(20).Take(21).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList6 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype6 && d.MainId == 6); - if (oldList6 != null) - { - oldList6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - oldList6.Fixturestatus = 1; - } - else - { - oldList6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList6.AnHour = num - oldList6.AnHour; - break; - case 2: - oldList6.TwoHour = num - oldList6.TwoHour; - break; - case 3: - oldList6.ThreeHour = num - oldList6.ThreeHour; - break; - case 4: - oldList6.FourHour = num - oldList6.FourHour; - break; - case 5: - oldList6.FiveHour = num - oldList6.FiveHour; - break; - case 6: - oldList6.SixHour = num - oldList6.SixHour; - break; - case 7: - oldList6.SevenHour = num - oldList6.SevenHour; - break; - case 8: - oldList6.EightHour = num - oldList6.EightHour; ; - break; - case 9: - oldList6.NineHour = num - oldList6.NineHour; - break; - case 10: - oldList6.TenHour = num - oldList6.TenHour; - break; - case 11: - oldList6.ElevenHour = num - oldList6.ElevenHour; - break; - case 12: - oldList6.TwelveHour = num - oldList6.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.UpdatedTime = DateTime.Now; - oldList6.MainId = 6; - oldList6.ProductLineCode = "CX_01"; - bfList.Add(oldList6); - //await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - else - { - BoxFoamData boxfoam6 = new BoxFoamData(); - boxfoam6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - boxfoam6.Fixturestatus = 1; - } - else - { - boxfoam6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam6.AnHour = num; - break; - case 2: - boxfoam6.TwoHour = num; - break; - case 3: - boxfoam6.ThreeHour = num; - break; - case 4: - boxfoam6.FourHour = num; - break; - case 5: - boxfoam6.FiveHour = num; - break; - case 6: - boxfoam6.SixHour = num; - break; - case 7: - boxfoam6.SevenHour = num; - break; - case 8: - boxfoam6.EightHour = num; - break; - case 9: - boxfoam6.NineHour = num; - break; - case 10: - boxfoam6.TenHour = num; - break; - case 11: - boxfoam6.ElevenHour = num; - break; - case 12: - boxfoam6.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.UpdatedTime = DateTime.Now; - boxfoam6.MainId = 6; - boxfoam6.ProductLineCode = "CX_01"; - addList.Add(boxfoam6); - //await _oldBoxFoamDataServices.AddAsync(boxfoam6); - } - if (bfList != null) - { - await _oldBoxFoamDataServices.UpdateAsync(bfList); - } - if (addList != null) - { - await _oldBoxFoamDataServices.AddAsync(addList); - } - } - catch (Exception ex) - { - - throw; - } - - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - } - - public async void GetData2() - { - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - try - { - List bfList = new List(); - List addList = new List(); - //var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); - //if (obj2 == null) { return; } - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); - if (obj == null) { return; } - - byte[] arr1 = obj.plc.ReadByte("D3140", (ushort)48); - if (arr1 == null) return; - //var arr1 = ArrReverse(bt); - - byte[] arr3 = obj.plc.ReadByte("D182", (ushort)24); - if (arr3 == null) return; - //var arr3 = ArrReverse(bt3); - byte[] arr4 = obj.plc.ReadByte("D910", (ushort)24); - if (arr4 == null) return; - //var arr4 = ArrReverse(bt4); - byte[] arr5 = obj.plc.ReadByte("T3", (ushort)24); - if (arr5 == null) return; - //var arr5 = ArrReverse(bt5); - - - string productLineCode = Appsettings.app("StationInfo", "ProductLineCode"); - List fdList = _oldBoxFoamDataServices.QueryAsync(d => d.ProductLineCode == productLineCode).Result; - - var fixtureboxtype1 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList1 = fdList.SingleOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 1); - if (oldList1 != null) - { - //只更新小时数量 - oldList1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr(result1, result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr(result2, result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr(result3, result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - oldList1.Fixturestatus = 1; - } - else - { - oldList1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList1.AnHour = num - oldList1.AnHour; - break; - case 2: - oldList1.TwoHour = num - oldList1.TwoHour; - break; - case 3: - oldList1.ThreeHour = num - oldList1.ThreeHour; - break; - case 4: - oldList1.FourHour = num - oldList1.FourHour; - break; - case 5: - oldList1.FiveHour = num - oldList1.FiveHour; - break; - case 6: - oldList1.SixHour = num - oldList1.SixHour; - break; - case 7: - oldList1.SevenHour = num - oldList1.SevenHour; - break; - case 8: - oldList1.EightHour = num - oldList1.EightHour; ; - break; - case 9: - oldList1.NineHour = num - oldList1.NineHour; - break; - case 10: - oldList1.TenHour = num - oldList1.TenHour; - break; - case 11: - oldList1.ElevenHour = num - oldList1.ElevenHour; - break; - case 12: - oldList1.TwelveHour = num - oldList1.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList1.Production = obj.plc.ReadInt16("D182");//short.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.UpdatedTime = DateTime.Now; - oldList1.ProductLineCode = "CX_01"; - oldList1.MainId = 1; - bfList.Add(oldList1); - //await _oldBoxFoamDataServices.UpdateAsync(oldList1); - } - else - { - BoxFoamData boxfoam1 = new BoxFoamData(); - //新增 - boxfoam1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - boxfoam1.Fixturestatus = 1; - } - else - { - boxfoam1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam1.AnHour = num; - break; - case 2: - boxfoam1.TwoHour = num; - break; - case 3: - boxfoam1.ThreeHour = num; - break; - case 4: - boxfoam1.FourHour = num; - break; - case 5: - boxfoam1.FiveHour = num; - break; - case 6: - boxfoam1.SixHour = num; - break; - case 7: - boxfoam1.SevenHour = num; - break; - case 8: - boxfoam1.EightHour = num; - break; - case 9: - boxfoam1.NineHour = num; - break; - case 10: - boxfoam1.TenHour = num; - break; - case 11: - boxfoam1.ElevenHour = num; - break; - case 12: - boxfoam1.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam1.Production = obj.plc.ReadInt16("D182");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.UpdatedTime = DateTime.Now; - boxfoam1.ProductLineCode = "CX_01"; - boxfoam1.MainId = 1; - addList.Add(boxfoam1); - //await _oldBoxFoamDataServices.AddAsync(boxfoam1); - } - - var fixtureboxtype2 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList2 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 2); - if (oldList2 != null) - { - oldList2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList2.AnHour = num - oldList2.AnHour; - break; - case 2: - oldList2.TwoHour = num - oldList2.TwoHour; - break; - case 3: - oldList2.ThreeHour = num - oldList2.ThreeHour; - break; - case 4: - oldList2.FourHour = num - oldList2.FourHour; - break; - case 5: - oldList2.FiveHour = num - oldList2.FiveHour; - break; - case 6: - oldList2.SixHour = num - oldList2.SixHour; - break; - case 7: - oldList2.SevenHour = num - oldList2.SevenHour; - break; - case 8: - oldList2.EightHour = num - oldList2.EightHour; ; - break; - case 9: - oldList2.NineHour = num - oldList2.NineHour; - break; - case 10: - oldList2.TenHour = num - oldList2.TenHour; - break; - case 11: - oldList2.ElevenHour = num - oldList2.ElevenHour; - break; - case 12: - oldList2.TwelveHour = num - oldList2.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.UpdatedTime = DateTime.Now; - oldList2.ProductLineCode = "CX_01"; - oldList2.MainId = 2; - bfList.Add(oldList2); - //await _oldBoxFoamDataServices.UpdateAsync(oldList2); - } - else - { - BoxFoamData boxfoam2 = new BoxFoamData(); - boxfoam2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - boxfoam2.Fixturestatus = 1; - } - else - { - boxfoam2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D183");//int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam2.AnHour = num; - break; - case 2: - boxfoam2.TwoHour = num; - break; - case 3: - boxfoam2.ThreeHour = num; - break; - case 4: - boxfoam2.FourHour = num; - break; - case 5: - boxfoam2.FiveHour = num; - break; - case 6: - boxfoam2.SixHour = num; - break; - case 7: - boxfoam2.SevenHour = num; - break; - case 8: - boxfoam2.EightHour = num; - break; - case 9: - boxfoam2.NineHour = num; - break; - case 10: - boxfoam2.TenHour = num; - break; - case 11: - boxfoam2.ElevenHour = num; - break; - case 12: - boxfoam2.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.UpdatedTime = DateTime.Now; - boxfoam2.MainId = 2; - boxfoam2.ProductLineCode = "CX_01"; - addList.Add(boxfoam2); - //await _oldBoxFoamDataServices.AddAsync(boxfoam2); - } - - var fixtureboxtype3 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(8).Take(9).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList3 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype3 && d.MainId == 3); - if (oldList3 != null) - { - oldList3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList3.AnHour = num - oldList3.AnHour; - break; - case 2: - oldList3.TwoHour = num - oldList3.TwoHour; - break; - case 3: - oldList3.ThreeHour = num - oldList3.ThreeHour; - break; - case 4: - oldList3.FourHour = num - oldList3.FourHour; - break; - case 5: - oldList3.FiveHour = num - oldList3.FiveHour; - break; - case 6: - oldList3.SixHour = num - oldList3.SixHour; - break; - case 7: - oldList3.SevenHour = num - oldList3.SevenHour; - break; - case 8: - oldList3.EightHour = num - oldList3.EightHour; ; - break; - case 9: - oldList3.NineHour = num - oldList3.NineHour; - break; - case 10: - oldList3.TenHour = num - oldList3.TenHour; - break; - case 11: - oldList3.ElevenHour = num - oldList3.ElevenHour; - break; - case 12: - oldList3.TwelveHour = num - oldList3.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList3.Production = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 1), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.UpdatedTime = DateTime.Now; - oldList3.MainId = 3; - oldList3.ProductLineCode = "CX_01"; - bfList.Add(oldList3); - //await _oldBoxFoamDataServices.UpdateAsync(oldList3); - } - else - { - BoxFoamData boxfoam3 = new BoxFoamData(); - boxfoam3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - boxfoam3.Fixturestatus = 1; - } - else - { - boxfoam3.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam3.AnHour = num; - break; - case 2: - boxfoam3.TwoHour = num; - break; - case 3: - boxfoam3.ThreeHour = num; - break; - case 4: - boxfoam3.FourHour = num; - break; - case 5: - boxfoam3.FiveHour = num; - break; - case 6: - boxfoam3.SixHour = num; - break; - case 7: - boxfoam3.SevenHour = num; - break; - case 8: - boxfoam3.EightHour = num; - break; - case 9: - boxfoam3.NineHour = num; - break; - case 10: - boxfoam3.TenHour = num; - break; - case 11: - boxfoam3.ElevenHour = num; - break; - case 12: - boxfoam3.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam3.Production = obj.plc.ReadInt16("D184");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.UpdatedTime = DateTime.Now; - boxfoam3.MainId = 3; - boxfoam3.ProductLineCode = "CX_01"; - addList.Add(boxfoam3); - //await _oldBoxFoamDataServices.AddAsync(boxfoam3); - } - - - var fixtureboxtype4 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(12).Take(13).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList4 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype4 && d.MainId == 4); - if (oldList4 != null) - { - oldList4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList4.Fixturestatus = 1; - } - else - { - oldList4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D185"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList4.AnHour = num - oldList4.AnHour; - break; - case 2: - oldList4.TwoHour = num - oldList4.TwoHour; - break; - case 3: - oldList4.ThreeHour = num - oldList4.ThreeHour; - break; - case 4: - oldList4.FourHour = num - oldList4.FourHour; - break; - case 5: - oldList4.FiveHour = num - oldList4.FiveHour; - break; - case 6: - oldList4.SixHour = num - oldList4.SixHour; - break; - case 7: - oldList4.SevenHour = num - oldList4.SevenHour; - break; - case 8: - oldList4.EightHour = num - oldList4.EightHour; ; - break; - case 9: - oldList4.NineHour = num - oldList4.NineHour; - break; - case 10: - oldList4.TenHour = num - oldList4.TenHour; - break; - case 11: - oldList4.ElevenHour = num - oldList4.ElevenHour; - break; - case 12: - oldList4.TwelveHour = num - oldList4.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - oldList4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(12).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.UpdatedTime = DateTime.Now; - oldList4.MainId = 4; - oldList4.ProductLineCode = "CX_01"; - bfList.Add(oldList4); - //await _oldBoxFoamDataServices.UpdateAsync(oldList4); - } - else - { - BoxFoamData boxfoam4 = new BoxFoamData(); - boxfoam4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam4.Fixturestatus = 1; - } - else - { - boxfoam4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam4.AnHour = num; - break; - case 2: - boxfoam4.TwoHour = num; - break; - case 3: - boxfoam4.ThreeHour = num; - break; - case 4: - boxfoam4.FourHour = num; - break; - case 5: - boxfoam4.FiveHour = num; - break; - case 6: - boxfoam4.SixHour = num; - break; - case 7: - boxfoam4.SevenHour = num; - break; - case 8: - boxfoam4.EightHour = num; - break; - case 9: - boxfoam4.NineHour = num; - break; - case 10: - boxfoam4.TenHour = num; - break; - case 11: - boxfoam4.ElevenHour = num; - break; - case 12: - boxfoam4.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.UpdatedTime = DateTime.Now; - boxfoam4.MainId = 4; - boxfoam4.ProductLineCode = "CX_01"; - addList.Add(boxfoam4); - //await _oldBoxFoamDataServices.AddAsync(boxfoam4); - } - - var fixtureboxtype5 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(16).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList5 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype5 && d.MainId == 5); - if (oldList5 != null) - { - oldList5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList5.Fixturestatus = 1; - } - else - { - oldList5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList5.AnHour = num - oldList5.AnHour; - break; - case 2: - oldList5.TwoHour = num - oldList5.TwoHour; - break; - case 3: - oldList5.ThreeHour = num - oldList5.ThreeHour; - break; - case 4: - oldList5.FourHour = num - oldList5.FourHour; - break; - case 5: - oldList5.FiveHour = num - oldList5.FiveHour; - break; - case 6: - oldList5.SixHour = num - oldList5.SixHour; - break; - case 7: - oldList5.SevenHour = num - oldList5.SevenHour; - break; - case 8: - oldList5.EightHour = num - oldList5.EightHour; ; - break; - case 9: - oldList5.NineHour = num - oldList5.NineHour; - break; - case 10: - oldList5.TenHour = num - oldList5.TenHour; - break; - case 11: - oldList5.ElevenHour = num - oldList5.ElevenHour; - break; - case 12: - oldList5.TwelveHour = num - oldList5.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList5.Production = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - oldList5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.UpdatedTime = DateTime.Now; - oldList5.MainId = 5; - oldList5.ProductLineCode = "CX_01"; - bfList.Add(oldList5); - //await _oldBoxFoamDataServices.UpdateAsync(oldList5); - } - else - { - BoxFoamData boxfoam5 = new BoxFoamData(); - boxfoam5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam5.Fixturestatus = 1; - } - else - { - boxfoam5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam5.AnHour = num; - break; - case 2: - boxfoam5.TwoHour = num; - break; - case 3: - boxfoam5.ThreeHour = num; - break; - case 4: - boxfoam5.FourHour = num; - break; - case 5: - boxfoam5.FiveHour = num; - break; - case 6: - boxfoam5.SixHour = num; - break; - case 7: - boxfoam5.SevenHour = num; - break; - case 8: - boxfoam5.EightHour = num; - break; - case 9: - boxfoam5.NineHour = num; - break; - case 10: - boxfoam5.TenHour = num; - break; - case 11: - boxfoam5.ElevenHour = num; - break; - case 12: - boxfoam5.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam5.Production = obj.plc.ReadInt16("D186"); int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.UpdatedTime = DateTime.Now; - boxfoam5.MainId = 5; - boxfoam5.ProductLineCode = "CX_01"; - addList.Add(boxfoam5); - //await _oldBoxFoamDataServices.AddAsync(boxfoam5); - } - var fixtureboxtype6 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(20).Take(21).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList6 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype6 && d.MainId == 6); - if (oldList6 != null) - { - oldList6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - oldList6.Fixturestatus = 1; - } - else - { - oldList6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList6.AnHour = num - oldList6.AnHour; - break; - case 2: - oldList6.TwoHour = num - oldList6.TwoHour; - break; - case 3: - oldList6.ThreeHour = num - oldList6.ThreeHour; - break; - case 4: - oldList6.FourHour = num - oldList6.FourHour; - break; - case 5: - oldList6.FiveHour = num - oldList6.FiveHour; - break; - case 6: - oldList6.SixHour = num - oldList6.SixHour; - break; - case 7: - oldList6.SevenHour = num - oldList6.SevenHour; - break; - case 8: - oldList6.EightHour = num - oldList6.EightHour; ; - break; - case 9: - oldList6.NineHour = num - oldList6.NineHour; - break; - case 10: - oldList6.TenHour = num - oldList6.TenHour; - break; - case 11: - oldList6.ElevenHour = num - oldList6.ElevenHour; - break; - case 12: - oldList6.TwelveHour = num - oldList6.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.UpdatedTime = DateTime.Now; - oldList6.MainId = 6; - oldList6.ProductLineCode = "CX_01"; - bfList.Add(oldList6); - //await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - else - { - BoxFoamData boxfoam6 = new BoxFoamData(); - boxfoam6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - boxfoam6.Fixturestatus = 1; - } - else - { - boxfoam6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam6.AnHour = num; - break; - case 2: - boxfoam6.TwoHour = num; - break; - case 3: - boxfoam6.ThreeHour = num; - break; - case 4: - boxfoam6.FourHour = num; - break; - case 5: - boxfoam6.FiveHour = num; - break; - case 6: - boxfoam6.SixHour = num; - break; - case 7: - boxfoam6.SevenHour = num; - break; - case 8: - boxfoam6.EightHour = num; - break; - case 9: - boxfoam6.NineHour = num; - break; - case 10: - boxfoam6.TenHour = num; - break; - case 11: - boxfoam6.ElevenHour = num; - break; - case 12: - boxfoam6.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.UpdatedTime = DateTime.Now; - boxfoam6.MainId = 6; - boxfoam6.ProductLineCode = "CX_01"; - addList.Add(boxfoam6); - //await _oldBoxFoamDataServices.AddAsync(boxfoam6); - } - if (bfList == null) - { - await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - if (addList == null) - { - await _oldBoxFoamDataServices.AddAsync(addList); - } - } - catch (Exception ex) - { - - throw; - } - - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - } - - public async void GetData3() - { - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - try - { - List bfList = new List(); - List addList = new List(); - //var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); - //if (obj2 == null) { return; } - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3")); - if (obj == null) { return; } - - byte[] arr1 = obj.plc.ReadByte("D3140", (ushort)48); - if (arr1 == null) return; - //var arr1 = ArrReverse(bt); - - byte[] arr3 = obj.plc.ReadByte("D182", (ushort)24); - if (arr3 == null) return; - //var arr3 = ArrReverse(bt3); - byte[] arr4 = obj.plc.ReadByte("D910", (ushort)24); - if (arr4 == null) return; - //var arr4 = ArrReverse(bt4); - byte[] arr5 = obj.plc.ReadByte("T3", (ushort)24); - if (arr5 == null) return; - //var arr5 = ArrReverse(bt5); - - - string productLineCode = Appsettings.app("StationInfo", "ProductLineCode"); - List fdList = _oldBoxFoamDataServices.QueryAsync(d => d.ProductLineCode == productLineCode).Result; - - var fixtureboxtype1 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList1 = fdList.SingleOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 1); - if (oldList1 != null) - { - //只更新小时数量 - oldList1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr(result1, result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr(result2, result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr(result3, result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - oldList1.Fixturestatus = 1; - } - else - { - oldList1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList1.AnHour = num - oldList1.AnHour; - break; - case 2: - oldList1.TwoHour = num - oldList1.TwoHour; - break; - case 3: - oldList1.ThreeHour = num - oldList1.ThreeHour; - break; - case 4: - oldList1.FourHour = num - oldList1.FourHour; - break; - case 5: - oldList1.FiveHour = num - oldList1.FiveHour; - break; - case 6: - oldList1.SixHour = num - oldList1.SixHour; - break; - case 7: - oldList1.SevenHour = num - oldList1.SevenHour; - break; - case 8: - oldList1.EightHour = num - oldList1.EightHour; ; - break; - case 9: - oldList1.NineHour = num - oldList1.NineHour; - break; - case 10: - oldList1.TenHour = num - oldList1.TenHour; - break; - case 11: - oldList1.ElevenHour = num - oldList1.ElevenHour; - break; - case 12: - oldList1.TwelveHour = num - oldList1.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList1.Production = obj.plc.ReadInt16("D182");//short.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.UpdatedTime = DateTime.Now; - oldList1.ProductLineCode = "CX_01"; - oldList1.MainId = 1; - bfList.Add(oldList1); - //await _oldBoxFoamDataServices.UpdateAsync(oldList1); - } - else - { - BoxFoamData boxfoam1 = new BoxFoamData(); - //新增 - boxfoam1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - boxfoam1.Fixturestatus = 1; - } - else - { - boxfoam1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam1.AnHour = num; - break; - case 2: - boxfoam1.TwoHour = num; - break; - case 3: - boxfoam1.ThreeHour = num; - break; - case 4: - boxfoam1.FourHour = num; - break; - case 5: - boxfoam1.FiveHour = num; - break; - case 6: - boxfoam1.SixHour = num; - break; - case 7: - boxfoam1.SevenHour = num; - break; - case 8: - boxfoam1.EightHour = num; - break; - case 9: - boxfoam1.NineHour = num; - break; - case 10: - boxfoam1.TenHour = num; - break; - case 11: - boxfoam1.ElevenHour = num; - break; - case 12: - boxfoam1.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam1.Production = obj.plc.ReadInt16("D182");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.UpdatedTime = DateTime.Now; - boxfoam1.ProductLineCode = "CX_01"; - boxfoam1.MainId = 1; - addList.Add(boxfoam1); - //await _oldBoxFoamDataServices.AddAsync(boxfoam1); - } - - var fixtureboxtype2 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList2 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 2); - if (oldList2 != null) - { - oldList2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList2.AnHour = num - oldList2.AnHour; - break; - case 2: - oldList2.TwoHour = num - oldList2.TwoHour; - break; - case 3: - oldList2.ThreeHour = num - oldList2.ThreeHour; - break; - case 4: - oldList2.FourHour = num - oldList2.FourHour; - break; - case 5: - oldList2.FiveHour = num - oldList2.FiveHour; - break; - case 6: - oldList2.SixHour = num - oldList2.SixHour; - break; - case 7: - oldList2.SevenHour = num - oldList2.SevenHour; - break; - case 8: - oldList2.EightHour = num - oldList2.EightHour; ; - break; - case 9: - oldList2.NineHour = num - oldList2.NineHour; - break; - case 10: - oldList2.TenHour = num - oldList2.TenHour; - break; - case 11: - oldList2.ElevenHour = num - oldList2.ElevenHour; - break; - case 12: - oldList2.TwelveHour = num - oldList2.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.UpdatedTime = DateTime.Now; - oldList2.ProductLineCode = "CX_01"; - oldList2.MainId = 2; - bfList.Add(oldList2); - //await _oldBoxFoamDataServices.UpdateAsync(oldList2); - } - else - { - BoxFoamData boxfoam2 = new BoxFoamData(); - boxfoam2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - boxfoam2.Fixturestatus = 1; - } - else - { - boxfoam2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D183");//int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam2.AnHour = num; - break; - case 2: - boxfoam2.TwoHour = num; - break; - case 3: - boxfoam2.ThreeHour = num; - break; - case 4: - boxfoam2.FourHour = num; - break; - case 5: - boxfoam2.FiveHour = num; - break; - case 6: - boxfoam2.SixHour = num; - break; - case 7: - boxfoam2.SevenHour = num; - break; - case 8: - boxfoam2.EightHour = num; - break; - case 9: - boxfoam2.NineHour = num; - break; - case 10: - boxfoam2.TenHour = num; - break; - case 11: - boxfoam2.ElevenHour = num; - break; - case 12: - boxfoam2.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.UpdatedTime = DateTime.Now; - boxfoam2.MainId = 2; - boxfoam2.ProductLineCode = "CX_01"; - addList.Add(boxfoam2); - //await _oldBoxFoamDataServices.AddAsync(boxfoam2); - } - - var fixtureboxtype3 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(8).Take(9).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList3 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype3 && d.MainId == 3); - if (oldList3 != null) - { - oldList3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList3.AnHour = num - oldList3.AnHour; - break; - case 2: - oldList3.TwoHour = num - oldList3.TwoHour; - break; - case 3: - oldList3.ThreeHour = num - oldList3.ThreeHour; - break; - case 4: - oldList3.FourHour = num - oldList3.FourHour; - break; - case 5: - oldList3.FiveHour = num - oldList3.FiveHour; - break; - case 6: - oldList3.SixHour = num - oldList3.SixHour; - break; - case 7: - oldList3.SevenHour = num - oldList3.SevenHour; - break; - case 8: - oldList3.EightHour = num - oldList3.EightHour; ; - break; - case 9: - oldList3.NineHour = num - oldList3.NineHour; - break; - case 10: - oldList3.TenHour = num - oldList3.TenHour; - break; - case 11: - oldList3.ElevenHour = num - oldList3.ElevenHour; - break; - case 12: - oldList3.TwelveHour = num - oldList3.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList3.Production = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 1), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.UpdatedTime = DateTime.Now; - oldList3.MainId = 3; - oldList3.ProductLineCode = "CX_01"; - bfList.Add(oldList3); - //await _oldBoxFoamDataServices.UpdateAsync(oldList3); - } - else - { - BoxFoamData boxfoam3 = new BoxFoamData(); - boxfoam3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - boxfoam3.Fixturestatus = 1; - } - else - { - boxfoam3.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam3.AnHour = num; - break; - case 2: - boxfoam3.TwoHour = num; - break; - case 3: - boxfoam3.ThreeHour = num; - break; - case 4: - boxfoam3.FourHour = num; - break; - case 5: - boxfoam3.FiveHour = num; - break; - case 6: - boxfoam3.SixHour = num; - break; - case 7: - boxfoam3.SevenHour = num; - break; - case 8: - boxfoam3.EightHour = num; - break; - case 9: - boxfoam3.NineHour = num; - break; - case 10: - boxfoam3.TenHour = num; - break; - case 11: - boxfoam3.ElevenHour = num; - break; - case 12: - boxfoam3.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam3.Production = obj.plc.ReadInt16("D184");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.UpdatedTime = DateTime.Now; - boxfoam3.MainId = 3; - boxfoam3.ProductLineCode = "CX_01"; - addList.Add(boxfoam3); - //await _oldBoxFoamDataServices.AddAsync(boxfoam3); - } - - - var fixtureboxtype4 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(12).Take(13).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList4 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype4 && d.MainId == 4); - if (oldList4 != null) - { - oldList4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList4.Fixturestatus = 1; - } - else - { - oldList4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D185"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList4.AnHour = num - oldList4.AnHour; - break; - case 2: - oldList4.TwoHour = num - oldList4.TwoHour; - break; - case 3: - oldList4.ThreeHour = num - oldList4.ThreeHour; - break; - case 4: - oldList4.FourHour = num - oldList4.FourHour; - break; - case 5: - oldList4.FiveHour = num - oldList4.FiveHour; - break; - case 6: - oldList4.SixHour = num - oldList4.SixHour; - break; - case 7: - oldList4.SevenHour = num - oldList4.SevenHour; - break; - case 8: - oldList4.EightHour = num - oldList4.EightHour; ; - break; - case 9: - oldList4.NineHour = num - oldList4.NineHour; - break; - case 10: - oldList4.TenHour = num - oldList4.TenHour; - break; - case 11: - oldList4.ElevenHour = num - oldList4.ElevenHour; - break; - case 12: - oldList4.TwelveHour = num - oldList4.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - oldList4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(12).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.UpdatedTime = DateTime.Now; - oldList4.MainId = 4; - oldList4.ProductLineCode = "CX_01"; - bfList.Add(oldList4); - //await _oldBoxFoamDataServices.UpdateAsync(oldList4); - } - else - { - BoxFoamData boxfoam4 = new BoxFoamData(); - boxfoam4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam4.Fixturestatus = 1; - } - else - { - boxfoam4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam4.AnHour = num; - break; - case 2: - boxfoam4.TwoHour = num; - break; - case 3: - boxfoam4.ThreeHour = num; - break; - case 4: - boxfoam4.FourHour = num; - break; - case 5: - boxfoam4.FiveHour = num; - break; - case 6: - boxfoam4.SixHour = num; - break; - case 7: - boxfoam4.SevenHour = num; - break; - case 8: - boxfoam4.EightHour = num; - break; - case 9: - boxfoam4.NineHour = num; - break; - case 10: - boxfoam4.TenHour = num; - break; - case 11: - boxfoam4.ElevenHour = num; - break; - case 12: - boxfoam4.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.UpdatedTime = DateTime.Now; - boxfoam4.MainId = 4; - boxfoam4.ProductLineCode = "CX_01"; - addList.Add(boxfoam4); - //await _oldBoxFoamDataServices.AddAsync(boxfoam4); - } - - var fixtureboxtype5 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(16).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList5 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype5 && d.MainId == 5); - if (oldList5 != null) - { - oldList5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList5.Fixturestatus = 1; - } - else - { - oldList5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList5.AnHour = num - oldList5.AnHour; - break; - case 2: - oldList5.TwoHour = num - oldList5.TwoHour; - break; - case 3: - oldList5.ThreeHour = num - oldList5.ThreeHour; - break; - case 4: - oldList5.FourHour = num - oldList5.FourHour; - break; - case 5: - oldList5.FiveHour = num - oldList5.FiveHour; - break; - case 6: - oldList5.SixHour = num - oldList5.SixHour; - break; - case 7: - oldList5.SevenHour = num - oldList5.SevenHour; - break; - case 8: - oldList5.EightHour = num - oldList5.EightHour; ; - break; - case 9: - oldList5.NineHour = num - oldList5.NineHour; - break; - case 10: - oldList5.TenHour = num - oldList5.TenHour; - break; - case 11: - oldList5.ElevenHour = num - oldList5.ElevenHour; - break; - case 12: - oldList5.TwelveHour = num - oldList5.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList5.Production = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - oldList5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.UpdatedTime = DateTime.Now; - oldList5.MainId = 5; - oldList5.ProductLineCode = "CX_01"; - bfList.Add(oldList5); - //await _oldBoxFoamDataServices.UpdateAsync(oldList5); - } - else - { - BoxFoamData boxfoam5 = new BoxFoamData(); - boxfoam5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam5.Fixturestatus = 1; - } - else - { - boxfoam5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam5.AnHour = num; - break; - case 2: - boxfoam5.TwoHour = num; - break; - case 3: - boxfoam5.ThreeHour = num; - break; - case 4: - boxfoam5.FourHour = num; - break; - case 5: - boxfoam5.FiveHour = num; - break; - case 6: - boxfoam5.SixHour = num; - break; - case 7: - boxfoam5.SevenHour = num; - break; - case 8: - boxfoam5.EightHour = num; - break; - case 9: - boxfoam5.NineHour = num; - break; - case 10: - boxfoam5.TenHour = num; - break; - case 11: - boxfoam5.ElevenHour = num; - break; - case 12: - boxfoam5.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam5.Production = obj.plc.ReadInt16("D186"); int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.UpdatedTime = DateTime.Now; - boxfoam5.MainId = 5; - boxfoam5.ProductLineCode = "CX_01"; - addList.Add(boxfoam5); - //await _oldBoxFoamDataServices.AddAsync(boxfoam5); - } - var fixtureboxtype6 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(20).Take(21).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList6 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype6 && d.MainId == 6); - if (oldList6 != null) - { - oldList6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - oldList6.Fixturestatus = 1; - } - else - { - oldList6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList6.AnHour = num - oldList6.AnHour; - break; - case 2: - oldList6.TwoHour = num - oldList6.TwoHour; - break; - case 3: - oldList6.ThreeHour = num - oldList6.ThreeHour; - break; - case 4: - oldList6.FourHour = num - oldList6.FourHour; - break; - case 5: - oldList6.FiveHour = num - oldList6.FiveHour; - break; - case 6: - oldList6.SixHour = num - oldList6.SixHour; - break; - case 7: - oldList6.SevenHour = num - oldList6.SevenHour; - break; - case 8: - oldList6.EightHour = num - oldList6.EightHour; ; - break; - case 9: - oldList6.NineHour = num - oldList6.NineHour; - break; - case 10: - oldList6.TenHour = num - oldList6.TenHour; - break; - case 11: - oldList6.ElevenHour = num - oldList6.ElevenHour; - break; - case 12: - oldList6.TwelveHour = num - oldList6.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.UpdatedTime = DateTime.Now; - oldList6.MainId = 6; - oldList6.ProductLineCode = "CX_01"; - bfList.Add(oldList6); - //await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - else - { - BoxFoamData boxfoam6 = new BoxFoamData(); - boxfoam6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - boxfoam6.Fixturestatus = 1; - } - else - { - boxfoam6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam6.AnHour = num; - break; - case 2: - boxfoam6.TwoHour = num; - break; - case 3: - boxfoam6.ThreeHour = num; - break; - case 4: - boxfoam6.FourHour = num; - break; - case 5: - boxfoam6.FiveHour = num; - break; - case 6: - boxfoam6.SixHour = num; - break; - case 7: - boxfoam6.SevenHour = num; - break; - case 8: - boxfoam6.EightHour = num; - break; - case 9: - boxfoam6.NineHour = num; - break; - case 10: - boxfoam6.TenHour = num; - break; - case 11: - boxfoam6.ElevenHour = num; - break; - case 12: - boxfoam6.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.UpdatedTime = DateTime.Now; - boxfoam6.MainId = 6; - boxfoam6.ProductLineCode = "CX_01"; - addList.Add(boxfoam6); - //await _oldBoxFoamDataServices.AddAsync(boxfoam6); - } - if (bfList == null) - { - await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - if (addList == null) - { - await _oldBoxFoamDataServices.AddAsync(addList); - } - } - catch (Exception ex) - { - - throw; - } - - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - } - - public async void GetData4() - { - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - try - { - List bfList = new List(); - List addList = new List(); - //var obj2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); - //if (obj2 == null) { return; } - var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4")); - if (obj == null) { return; } - - byte[] arr1 = obj.plc.ReadByte("D3140", (ushort)48); - if (arr1 == null) return; - //var arr1 = ArrReverse(bt); - - byte[] arr3 = obj.plc.ReadByte("D182", (ushort)24); - if (arr3 == null) return; - //var arr3 = ArrReverse(bt3); - byte[] arr4 = obj.plc.ReadByte("D910", (ushort)24); - if (arr4 == null) return; - //var arr4 = ArrReverse(bt4); - byte[] arr5 = obj.plc.ReadByte("T3", (ushort)24); - if (arr5 == null) return; - //var arr5 = ArrReverse(bt5); - - - string productLineCode = Appsettings.app("StationInfo", "ProductLineCode"); - List fdList = _oldBoxFoamDataServices.QueryAsync(d => d.ProductLineCode == productLineCode).Result; - - var fixtureboxtype1 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList1 = fdList.SingleOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 1); - if (oldList1 != null) - { - //只更新小时数量 - oldList1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr(result1, result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr(result2, result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr(result3, result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - oldList1.Fixturestatus = 1; - } - else - { - oldList1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList1.AnHour = num - oldList1.AnHour; - break; - case 2: - oldList1.TwoHour = num - oldList1.TwoHour; - break; - case 3: - oldList1.ThreeHour = num - oldList1.ThreeHour; - break; - case 4: - oldList1.FourHour = num - oldList1.FourHour; - break; - case 5: - oldList1.FiveHour = num - oldList1.FiveHour; - break; - case 6: - oldList1.SixHour = num - oldList1.SixHour; - break; - case 7: - oldList1.SevenHour = num - oldList1.SevenHour; - break; - case 8: - oldList1.EightHour = num - oldList1.EightHour; ; - break; - case 9: - oldList1.NineHour = num - oldList1.NineHour; - break; - case 10: - oldList1.TenHour = num - oldList1.TenHour; - break; - case 11: - oldList1.ElevenHour = num - oldList1.ElevenHour; - break; - case 12: - oldList1.TwelveHour = num - oldList1.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList1.Production = obj.plc.ReadInt16("D182");//short.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList1.UpdatedTime = DateTime.Now; - oldList1.ProductLineCode = "CX_01"; - oldList1.MainId = 1; - bfList.Add(oldList1); - //await _oldBoxFoamDataServices.UpdateAsync(oldList1); - } - else - { - BoxFoamData boxfoam1 = new BoxFoamData(); - //新增 - boxfoam1.Fixtureboxtype = fixtureboxtype1; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F0", 1); - //byte[] result2 = obj.plc.Read("Y0F1", 1); - //byte[] result3 = obj.plc.Read("Y110", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F0"); - bool status2 = obj.plc.ReadBool("Y0F1"); - bool status3 = obj.plc.ReadBool("Y110"); - if (status2) - { - boxfoam1.Fixturestatus = 1; - } - else - { - boxfoam1.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D182"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam1.AnHour = num; - break; - case 2: - boxfoam1.TwoHour = num; - break; - case 3: - boxfoam1.ThreeHour = num; - break; - case 4: - boxfoam1.FourHour = num; - break; - case 5: - boxfoam1.FiveHour = num; - break; - case 6: - boxfoam1.SixHour = num; - break; - case 7: - boxfoam1.SevenHour = num; - break; - case 8: - boxfoam1.EightHour = num; - break; - case 9: - boxfoam1.NineHour = num; - break; - case 10: - boxfoam1.TenHour = num; - break; - case 11: - boxfoam1.ElevenHour = num; - break; - case 12: - boxfoam1.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam1.Production = obj.plc.ReadInt16("D182");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(0).Take(3).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam1.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam1.UpdatedTime = DateTime.Now; - boxfoam1.ProductLineCode = "CX_01"; - boxfoam1.MainId = 1; - addList.Add(boxfoam1); - //await _oldBoxFoamDataServices.AddAsync(boxfoam1); - } - - var fixtureboxtype2 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList2 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype1 && d.MainId == 2); - if (oldList2 != null) - { - oldList2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList2.AnHour = num - oldList2.AnHour; - break; - case 2: - oldList2.TwoHour = num - oldList2.TwoHour; - break; - case 3: - oldList2.ThreeHour = num - oldList2.ThreeHour; - break; - case 4: - oldList2.FourHour = num - oldList2.FourHour; - break; - case 5: - oldList2.FiveHour = num - oldList2.FiveHour; - break; - case 6: - oldList2.SixHour = num - oldList2.SixHour; - break; - case 7: - oldList2.SevenHour = num - oldList2.SevenHour; - break; - case 8: - oldList2.EightHour = num - oldList2.EightHour; ; - break; - case 9: - oldList2.NineHour = num - oldList2.NineHour; - break; - case 10: - oldList2.TenHour = num - oldList2.TenHour; - break; - case 11: - oldList2.ElevenHour = num - oldList2.ElevenHour; - break; - case 12: - oldList2.TwelveHour = num - oldList2.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - oldList2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList2.UpdatedTime = DateTime.Now; - oldList2.ProductLineCode = "CX_01"; - oldList2.MainId = 2; - bfList.Add(oldList2); - //await _oldBoxFoamDataServices.UpdateAsync(oldList2); - } - else - { - BoxFoamData boxfoam2 = new BoxFoamData(); - boxfoam2.Fixtureboxtype = fixtureboxtype2; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0F5", 1); - //byte[] result2 = obj.plc.Read("Y0F6", 1); - //byte[] result3 = obj.plc.Read("Y111", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0F5"); - bool status2 = obj.plc.ReadBool("Y0F6"); - bool status3 = obj.plc.ReadBool("Y111"); - if (status2) - { - boxfoam2.Fixturestatus = 1; - } - else - { - boxfoam2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D183");//int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam2.AnHour = num; - break; - case 2: - boxfoam2.TwoHour = num; - break; - case 3: - boxfoam2.ThreeHour = num; - break; - case 4: - boxfoam2.FourHour = num; - break; - case 5: - boxfoam2.FiveHour = num; - break; - case 6: - boxfoam2.SixHour = num; - break; - case 7: - boxfoam2.SevenHour = num; - break; - case 8: - boxfoam2.EightHour = num; - break; - case 9: - boxfoam2.NineHour = num; - break; - case 10: - boxfoam2.TenHour = num; - break; - case 11: - boxfoam2.ElevenHour = num; - break; - case 12: - boxfoam2.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam2.Production = obj.plc.ReadInt16("D183"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(4).Take(7).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam2.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(3).Take(5).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam2.UpdatedTime = DateTime.Now; - boxfoam2.MainId = 2; - boxfoam2.ProductLineCode = "CX_01"; - addList.Add(boxfoam2); - //await _oldBoxFoamDataServices.AddAsync(boxfoam2); - } - - var fixtureboxtype3 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(8).Take(9).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList3 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype3 && d.MainId == 3); - if (oldList3 != null) - { - oldList3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - oldList2.Fixturestatus = 1; - } - else - { - oldList2.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList3.AnHour = num - oldList3.AnHour; - break; - case 2: - oldList3.TwoHour = num - oldList3.TwoHour; - break; - case 3: - oldList3.ThreeHour = num - oldList3.ThreeHour; - break; - case 4: - oldList3.FourHour = num - oldList3.FourHour; - break; - case 5: - oldList3.FiveHour = num - oldList3.FiveHour; - break; - case 6: - oldList3.SixHour = num - oldList3.SixHour; - break; - case 7: - oldList3.SevenHour = num - oldList3.SevenHour; - break; - case 8: - oldList3.EightHour = num - oldList3.EightHour; ; - break; - case 9: - oldList3.NineHour = num - oldList3.NineHour; - break; - case 10: - oldList3.TenHour = num - oldList3.TenHour; - break; - case 11: - oldList3.ElevenHour = num - oldList3.ElevenHour; - break; - case 12: - oldList3.TwelveHour = num - oldList3.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList3.Production = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 1), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList3.UpdatedTime = DateTime.Now; - oldList3.MainId = 3; - oldList3.ProductLineCode = "CX_01"; - bfList.Add(oldList3); - //await _oldBoxFoamDataServices.UpdateAsync(oldList3); - } - else - { - BoxFoamData boxfoam3 = new BoxFoamData(); - boxfoam3.Fixtureboxtype = fixtureboxtype3; - - #region 状态 - //byte[] result1 = obj.plc.Read("Y0FA", 1); - //byte[] result2 = obj.plc.Read("Y0FB", 1); - //byte[] result3 = obj.plc.Read("Y112", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y0FA"); - bool status2 = obj.plc.ReadBool("Y0FB"); - bool status3 = obj.plc.ReadBool("Y112"); - if (status2) - { - boxfoam3.Fixturestatus = 1; - } - else - { - boxfoam3.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D184"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam3.AnHour = num; - break; - case 2: - boxfoam3.TwoHour = num; - break; - case 3: - boxfoam3.ThreeHour = num; - break; - case 4: - boxfoam3.FourHour = num; - break; - case 5: - boxfoam3.FiveHour = num; - break; - case 6: - boxfoam3.SixHour = num; - break; - case 7: - boxfoam3.SevenHour = num; - break; - case 8: - boxfoam3.EightHour = num; - break; - case 9: - boxfoam3.NineHour = num; - break; - case 10: - boxfoam3.TenHour = num; - break; - case 11: - boxfoam3.ElevenHour = num; - break; - case 12: - boxfoam3.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam3.Production = obj.plc.ReadInt16("D184");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(8).Take(11).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - boxfoam3.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(6).Take(8).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam3.UpdatedTime = DateTime.Now; - boxfoam3.MainId = 3; - boxfoam3.ProductLineCode = "CX_01"; - addList.Add(boxfoam3); - //await _oldBoxFoamDataServices.AddAsync(boxfoam3); - } - - - var fixtureboxtype4 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(12).Take(13).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList4 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype4 && d.MainId == 4); - if (oldList4 != null) - { - oldList4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList4.Fixturestatus = 1; - } - else - { - oldList4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D185"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList4.AnHour = num - oldList4.AnHour; - break; - case 2: - oldList4.TwoHour = num - oldList4.TwoHour; - break; - case 3: - oldList4.ThreeHour = num - oldList4.ThreeHour; - break; - case 4: - oldList4.FourHour = num - oldList4.FourHour; - break; - case 5: - oldList4.FiveHour = num - oldList4.FiveHour; - break; - case 6: - oldList4.SixHour = num - oldList4.SixHour; - break; - case 7: - oldList4.SevenHour = num - oldList4.SevenHour; - break; - case 8: - oldList4.EightHour = num - oldList4.EightHour; ; - break; - case 9: - oldList4.NineHour = num - oldList4.NineHour; - break; - case 10: - oldList4.TenHour = num - oldList4.TenHour; - break; - case 11: - oldList4.ElevenHour = num - oldList4.ElevenHour; - break; - case 12: - oldList4.TwelveHour = num - oldList4.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - oldList4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(12).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList4.UpdatedTime = DateTime.Now; - oldList4.MainId = 4; - oldList4.ProductLineCode = "CX_01"; - bfList.Add(oldList4); - //await _oldBoxFoamDataServices.UpdateAsync(oldList4); - } - else - { - BoxFoamData boxfoam4 = new BoxFoamData(); - boxfoam4.Fixtureboxtype = fixtureboxtype4; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y100", 1); - //byte[] result2 = obj2.plc.Read("Y101", 1); - //byte[] result3 = obj2.plc.Read("Y113", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam4.Fixturestatus = 1; - } - else - { - boxfoam4.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam4.AnHour = num; - break; - case 2: - boxfoam4.TwoHour = num; - break; - case 3: - boxfoam4.ThreeHour = num; - break; - case 4: - boxfoam4.FourHour = num; - break; - case 5: - boxfoam4.FiveHour = num; - break; - case 6: - boxfoam4.SixHour = num; - break; - case 7: - boxfoam4.SevenHour = num; - break; - case 8: - boxfoam4.EightHour = num; - break; - case 9: - boxfoam4.NineHour = num; - break; - case 10: - boxfoam4.TenHour = num; - break; - case 11: - boxfoam4.ElevenHour = num; - break; - case 12: - boxfoam4.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam4.Production = obj.plc.ReadInt16("D185");// int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(15).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam4.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(9).Take(11).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam4.UpdatedTime = DateTime.Now; - boxfoam4.MainId = 4; - boxfoam4.ProductLineCode = "CX_01"; - addList.Add(boxfoam4); - //await _oldBoxFoamDataServices.AddAsync(boxfoam4); - } - - var fixtureboxtype5 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(16).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList5 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype5 && d.MainId == 5); - if (oldList5 != null) - { - oldList5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - oldList5.Fixturestatus = 1; - } - else - { - oldList5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(),1), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList5.AnHour = num - oldList5.AnHour; - break; - case 2: - oldList5.TwoHour = num - oldList5.TwoHour; - break; - case 3: - oldList5.ThreeHour = num - oldList5.ThreeHour; - break; - case 4: - oldList5.FourHour = num - oldList5.FourHour; - break; - case 5: - oldList5.FiveHour = num - oldList5.FiveHour; - break; - case 6: - oldList5.SixHour = num - oldList5.SixHour; - break; - case 7: - oldList5.SevenHour = num - oldList5.SevenHour; - break; - case 8: - oldList5.EightHour = num - oldList5.EightHour; ; - break; - case 9: - oldList5.NineHour = num - oldList5.NineHour; - break; - case 10: - oldList5.TenHour = num - oldList5.TenHour; - break; - case 11: - oldList5.ElevenHour = num - oldList5.ElevenHour; - break; - case 12: - oldList5.TwelveHour = num - oldList5.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList5.Production = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(16).Take(19).ToArray(), 1), System.Globalization.NumberStyles.HexNumber); - oldList5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList5.UpdatedTime = DateTime.Now; - oldList5.MainId = 5; - oldList5.ProductLineCode = "CX_01"; - bfList.Add(oldList5); - //await _oldBoxFoamDataServices.UpdateAsync(oldList5); - } - else - { - BoxFoamData boxfoam5 = new BoxFoamData(); - boxfoam5.Fixtureboxtype = fixtureboxtype5; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y105", 1); - //byte[] result2 = obj2.plc.Read("Y106", 1); - //byte[] result3 = obj2.plc.Read("Y114", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y100"); - bool status2 = obj.plc.ReadBool("Y101"); - bool status3 = obj.plc.ReadBool("Y113"); - if (status2) - { - boxfoam5.Fixturestatus = 1; - } - else - { - boxfoam5.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - - int num = obj.plc.ReadInt16("D186"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam5.AnHour = num; - break; - case 2: - boxfoam5.TwoHour = num; - break; - case 3: - boxfoam5.ThreeHour = num; - break; - case 4: - boxfoam5.FourHour = num; - break; - case 5: - boxfoam5.FiveHour = num; - break; - case 6: - boxfoam5.SixHour = num; - break; - case 7: - boxfoam5.SevenHour = num; - break; - case 8: - boxfoam5.EightHour = num; - break; - case 9: - boxfoam5.NineHour = num; - break; - case 10: - boxfoam5.TenHour = num; - break; - case 11: - boxfoam5.ElevenHour = num; - break; - case 12: - boxfoam5.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam5.Production = obj.plc.ReadInt16("D186"); int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam5.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(12).Take(14).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam5.UpdatedTime = DateTime.Now; - boxfoam5.MainId = 5; - boxfoam5.ProductLineCode = "CX_01"; - addList.Add(boxfoam5); - //await _oldBoxFoamDataServices.AddAsync(boxfoam5); - } - var fixtureboxtype6 = short.Parse(UnicodeHelper.BytesToHexStr(arr1.Skip(20).Take(21).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - var oldList6 = fdList.FirstOrDefault(d => d.Fixtureboxtype == fixtureboxtype6 && d.MainId == 6); - if (oldList6 != null) - { - oldList6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - oldList6.Fixturestatus = 1; - } - else - { - oldList6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(),2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - oldList6.AnHour = num - oldList6.AnHour; - break; - case 2: - oldList6.TwoHour = num - oldList6.TwoHour; - break; - case 3: - oldList6.ThreeHour = num - oldList6.ThreeHour; - break; - case 4: - oldList6.FourHour = num - oldList6.FourHour; - break; - case 5: - oldList6.FiveHour = num - oldList6.FiveHour; - break; - case 6: - oldList6.SixHour = num - oldList6.SixHour; - break; - case 7: - oldList6.SevenHour = num - oldList6.SevenHour; - break; - case 8: - oldList6.EightHour = num - oldList6.EightHour; ; - break; - case 9: - oldList6.NineHour = num - oldList6.NineHour; - break; - case 10: - oldList6.TenHour = num - oldList6.TenHour; - break; - case 11: - oldList6.ElevenHour = num - oldList6.ElevenHour; - break; - case 12: - oldList6.TwelveHour = num - oldList6.TwelveHour; - break; - default: - break; - } - - #endregion - - oldList6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - oldList6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 3), System.Globalization.NumberStyles.HexNumber).ToString(); - oldList6.UpdatedTime = DateTime.Now; - oldList6.MainId = 6; - oldList6.ProductLineCode = "CX_01"; - bfList.Add(oldList6); - //await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - else - { - BoxFoamData boxfoam6 = new BoxFoamData(); - boxfoam6.Fixtureboxtype = fixtureboxtype6; - - #region 状态 - //byte[] result1 = obj2.plc.Read("Y10A", 1); - //byte[] result2 = obj2.plc.Read("Y10B", 1); - //byte[] result3 = obj2.plc.Read("Y115", 1); - //int status1 = int.Parse(UnicodeHelper.BytesToHexStr((result1), result1.Length), System.Globalization.NumberStyles.HexNumber); - //int status2 = int.Parse(UnicodeHelper.BytesToHexStr((result2), result2.Length), System.Globalization.NumberStyles.HexNumber); - //int status3 = int.Parse(UnicodeHelper.BytesToHexStr((result3), result3.Length), System.Globalization.NumberStyles.HexNumber); - - bool status1 = obj.plc.ReadBool("Y10A"); - bool status2 = obj.plc.ReadBool("Y10B"); - bool status3 = obj.plc.ReadBool("Y115"); - if (status2) - { - boxfoam6.Fixturestatus = 1; - } - else - { - boxfoam6.Fixturestatus = 0; - } - #endregion - - #region 计算每小时产量 - int num = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - switch (GetTeamHour()) - { - case 1: - boxfoam6.AnHour = num; - break; - case 2: - boxfoam6.TwoHour = num; - break; - case 3: - boxfoam6.ThreeHour = num; - break; - case 4: - boxfoam6.FourHour = num; - break; - case 5: - boxfoam6.FiveHour = num; - break; - case 6: - boxfoam6.SixHour = num; - break; - case 7: - boxfoam6.SevenHour = num; - break; - case 8: - boxfoam6.EightHour = num; - break; - case 9: - boxfoam6.NineHour = num; - break; - case 10: - boxfoam6.TenHour = num; - break; - case 11: - boxfoam6.ElevenHour = num; - break; - case 12: - boxfoam6.TwelveHour = num; - break; - default: - break; - } - - #endregion - - boxfoam6.Production = obj.plc.ReadInt16("D187"); //int.Parse(UnicodeHelper.BytesToHexStr(arr3.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); - boxfoam6.CuringTimeSettingValue = short.Parse(UnicodeHelper.BytesToHexStr(arr4.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.ActualValue = short.Parse(UnicodeHelper.BytesToHexStr(arr5.Skip(15).Take(17).ToArray(), 2), System.Globalization.NumberStyles.HexNumber).ToString(); - boxfoam6.UpdatedTime = DateTime.Now; - boxfoam6.MainId = 6; - boxfoam6.ProductLineCode = "CX_01"; - addList.Add(boxfoam6); - //await _oldBoxFoamDataServices.AddAsync(boxfoam6); - } - if (bfList == null) - { - await _oldBoxFoamDataServices.UpdateAsync(oldList6); - } - if (addList == null) - { - await _oldBoxFoamDataServices.AddAsync(addList); - } - } - catch (Exception ex) - { - - throw; - } - - Console.WriteLine(DateTime.Now.ToString("hh:mm:ss")); - } - public int GetTeamHour() - { - DateTime now = DateTime.Now; - var obj = _sysUserInfoServices.GetTeamData(now).Result; - return obj.Seq; - } } }