using Admin.Core.Common.Helper; using Admin.Core.IService; using Admin.Core.IService.IService_New; using Admin.Core.Model; using Admin.Core.Model.Model_New; using Admin.Core.Service; using Aucma.Core.HwPLc; using Aucma.Core.OldBoxFoam.Models; using Consul; using Microsoft.Extensions.DependencyInjection; using NetTaste; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; namespace Aucma.Core.OldBoxFoam.Business { public class Collection { public HwPLc.PlcModel plc1 = null; public HwPLc.PlcModel plc2 = null; public HwPLc.PlcModel plc3 = null; public HwPLc.PlcModel plc4 = null; public static List listFixtureStatus = new List(); public static List spaceDetailModel = new List(); private readonly IRecordBoxFoamFixtureComplateServices _fixtureComplateServices; /// /// 刷新货道 /// /// public delegate void RefreshSpace(List spaceDetailModel); public static event RefreshSpace RefreshSpaceEvent; /// /// 刷新设备数据 /// /// public delegate void RefreshFoamMachine(List fixtureStatus); public event RefreshFoamMachine RefreshFoamMachineEvent; public Collection() { _fixtureComplateServices = App.ServiceProvider.GetService(); } public void startCollect() { Thread.Sleep(3000); ExecTaskMethod(); } private void ExecTaskMethod() { listFixtureStatus = new List(); try { plc1 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1")); plc2 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc2")); plc3 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3")); plc4 = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc4")); List spaceTypeList = ReadStoreType(plc1, plc3); List spaceAmountList = ReadStoreAmount(plc1, plc3); var spaceCollection = from spaceType in spaceTypeList join spaceAmount in spaceAmountList on new { spaceType.ObjId } equals new { spaceAmount.ObjId } select new SpaceDetailModel { ObjId = spaceType.ObjId, StoreType = spaceType.StoreType, StoreAmount = spaceAmount.StoreAmount }; spaceDetailModel = spaceCollection.ToList(); RefreshSpaceEvent?.Invoke(spaceDetailModel); List boxTypeList = ReadBoxType(plc1, plc2, plc3, plc4); List holderStatusList = ReadHolderStatus(plc1, plc2, plc3, plc4); List holderOutPutList = ReadHolderOutPut(plc1, plc2, plc3, plc4); List planCuringTimeList = ReadSolidifyTime(plc1, plc2, plc3, plc4); var mergedCollection = from boxType in boxTypeList join holderStatus in holderStatusList on new { boxType.ObjId } equals new { holderStatus.ObjId } join holderOutPut in holderOutPutList on new { boxType.ObjId } equals new { holderOutPut.ObjId } join planCuringTime in planCuringTimeList on new { boxType.ObjId } equals new { planCuringTime.ObjId } select new FixtureStatus { ObjId = boxType.ObjId, FixtureBoxType = boxType.FixtureBoxType, Status = holderStatus.Status, Yield = holderOutPut.Yield, PlanCuringTime = planCuringTime.PlanCuringTime }; listFixtureStatus = mergedCollection.ToList(); if(listFixtureStatus != null) { RefreshFoamMachineEvent?.Invoke(listFixtureStatus); List fixtureComplates = new List(); listFixtureStatus.ForEach(x => { fixtureComplates.Add(new RecordBoxFoamFixtureComplate() { ProductionLine = "CX_01", StationCode = "1002", FixtureCode = x.ObjId, FixtureBoxType = x.FixtureBoxType, FixtureStatus = x.Status, FixtureOutPut = x.Yield, PlanCuringTime = x.PlanCuringTime, RealCuringTime = x.RealCuringTime, RecordTime = DateTime.Now, }); }); var info = _fixtureComplateServices.SaveFixtureComplate(fixtureComplates); } } catch (Exception) { throw; } } /// /// 读取夹具箱型 /// public List ReadBoxType(HwPLc.PlcModel obj, HwPLc.PlcModel obj2, HwPLc.PlcModel obj3, HwPLc.PlcModel obj4) { List fixtureStatuses = new List(); if (obj != null) { byte[] info = obj.plc.Read("D3140", 48); #region 1-6夹具 if (info != null) { int temp1 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 1, FixtureBoxType = temp1.ToString() }); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 2, FixtureBoxType = temp2.ToString() }); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 3, FixtureBoxType = temp3.ToString() }); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(12).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 4, FixtureBoxType = temp4.ToString() }); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(16).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 5, FixtureBoxType = temp5.ToString() }); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(18).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 6, FixtureBoxType = temp6.ToString() }); Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); } #endregion } if(obj2 != null) { byte[] info2 = obj2.plc.Read("D3140", 48); #region 7-12夹具 if (info2 != null) { int temp1 = short.Parse(StringChange.bytesToHexStr(array(info2.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 7, FixtureBoxType = temp1.ToString() }); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info2.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 8, FixtureBoxType = temp2.ToString() }); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info2.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 9, FixtureBoxType = temp3.ToString() }); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info2.Skip(12).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 10, FixtureBoxType = temp4.ToString() }); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info2.Skip(16).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 11, FixtureBoxType = temp5.ToString() }); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info2.Skip(18).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 12, FixtureBoxType = temp6.ToString() }); Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); } #endregion } if (obj3 != null) { byte[] info3 = obj3.plc.Read("D3140", 48); #region 13-18 夹具 if (info3 != null) { int temp1 = short.Parse(StringChange.bytesToHexStr(array(info3.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 13, FixtureBoxType = temp1.ToString() }); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info3.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 14, FixtureBoxType = temp2.ToString() }); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info3.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 15, FixtureBoxType = temp3.ToString() }); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info3.Skip(12).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 16, FixtureBoxType = temp4.ToString() }); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info3.Skip(16).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 17, FixtureBoxType = temp5.ToString() }); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info3.Skip(18).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 18, FixtureBoxType = temp6.ToString() }); Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); } #endregion } if(obj4 != null) { byte[] info4 = obj4.plc.Read("D3140", 48); #region 19-24 夹具 if (info4 != null) { int temp1 = short.Parse(StringChange.bytesToHexStr(array(info4.Skip(0).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 19, FixtureBoxType = temp1.ToString() }); int temp2 = short.Parse(StringChange.bytesToHexStr(array(info4.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 20, FixtureBoxType = temp2.ToString() }); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info4.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 21, FixtureBoxType = temp3.ToString() }); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info4.Skip(12).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 22, FixtureBoxType = temp4.ToString() }); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info4.Skip(16).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 23, FixtureBoxType = temp5.ToString() }); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info4.Skip(18).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); fixtureStatuses.Add(new FixtureStatus() { ObjId = 24, FixtureBoxType = temp6.ToString() }); Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); } #endregion } return fixtureStatuses; } /// /// 读取夹具状态 /// public List ReadHolderStatus(PlcModel obj1,PlcModel obj2,PlcModel obj3,PlcModel obj4) { List fixtureStatuses = new List(); if(obj1 != null) { #region 1-6 #region 按块读取 /*//输出二进制字符串,1#-3#手动、自动数据 string str1 = ByteArrayToBinary(array(result)); byte[] result2 = obj1.plc.Read("Y110", 1); string str2 = ByteArrayToBinary(array(result2)); //1# int item1 = 0; if (str1.Substring(0, 1) == "1") { item1 = 1; } else if (str1.Substring(1, 1) == "1") { item1 = 2; } else if (str2.Substring(0, 1) == "1") { item1 = 3; } //2# int item2 = 0; if (str1.Substring(5, 1) == "1") { item2 = 1; } else if (str1.Substring(6, 1) == "1") { item2 = 2; } else if (str2.Substring(1, 1) == "1") { item2 = 3; } //3# int item3 = 0; if (str1.Substring(10, 1) == "1") { item3 = 1; } else if (str1.Substring(11, 1) == "1") { item3 = 2; } else if (str2.Substring(2, 1) == "1") { item3 = 3; } byte[] result3 = obj1.plc.Read("Y100", 1); string str3 = ByteArrayToBinary(array(result3)); int item4 = 0; if (str3.Substring(0, 1) == "1") { item4 = 1; } else if (str3.Substring(1, 1) == "1") { item4 = 2; } else if (str2.Substring(3, 1) == "1") { item4 = 3; } int item5 = 0; if (str3.Substring(5, 1) == "1") { item5 = 1; } else if (str3.Substring(6, 1) == "1") { item5 = 2; } else if (str2.Substring(4, 1) == "1") { item5 = 3; } int item6 = 0; if (str3.Substring(10, 1) == "1") { item6 = 1; } else if (str3.Substring(11, 1) == "1") { item6 = 2; } else if (str2.Substring(5, 1) == "1") { item6 = 3; }*/ #endregion int item1 = 0; if (obj1.plc.ReadBool("YF0")) item1 = 1; if (obj1.plc.ReadBool("YF1")) item1 = 2; if (obj1.plc.ReadBool("Y110")) item1 = 3; int item2 = 0; if (obj1.plc.ReadBool("YF5")) item2 = 1; if (obj1.plc.ReadBool("YF6")) item2 = 2; if (obj1.plc.ReadBool("Y111")) item2 = 3; int item3 = 0; if (obj1.plc.ReadBool("YFA")) item3 = 1; if (obj1.plc.ReadBool("YFB")) item3 = 2; if (obj1.plc.ReadBool("Y112")) item3 = 3; int item4 = 0; if (obj1.plc.ReadBool("Y100")) item4 = 1; if (obj1.plc.ReadBool("Y101")) item4 = 2; if (obj1.plc.ReadBool("Y113")) item4 = 3; int item5 = 0; if (obj1.plc.ReadBool("Y105")) item5 = 1; if (obj1.plc.ReadBool("Y106")) item5 = 2; if (obj1.plc.ReadBool("Y114")) item5 = 3; int item6 = 0; if (obj1.plc.ReadBool("Y10A")) item6 = 1; if (obj1.plc.ReadBool("Y10B")) item6 = 2; if (obj1.plc.ReadBool("Y115")) item6 = 3; Console.WriteLine($"读取夹具状态,1#:{item1};2#:{item2};3#:{item3};4#:{item4};5#:{item5};6#:{item6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 1, Status = item1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 2, Status = item2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 3, Status = item3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 4, Status = item4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 5, Status = item5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 6, Status = item6, }); #endregion } if (obj2 != null) { #region 7-12 夹具 int item1 = 0; if (obj2.plc.ReadBool("YF0")) item1 = 1; if (obj2.plc.ReadBool("YF1")) item1 = 2; if (obj2.plc.ReadBool("Y110")) item1 = 3; int item2 = 0; if (obj2.plc.ReadBool("YF5")) item2 = 1; if (obj2.plc.ReadBool("YF6")) item2 = 2; if (obj2.plc.ReadBool("Y111")) item2 = 3; int item3 = 0; if (obj2.plc.ReadBool("YFA")) item3 = 1; if (obj2.plc.ReadBool("YFB")) item3 = 2; if (obj2.plc.ReadBool("Y112")) item3 = 3; int item4 = 0; if (obj2.plc.ReadBool("Y100")) item4 = 1; if (obj2.plc.ReadBool("Y101")) item4 = 2; if (obj2.plc.ReadBool("Y113")) item4 = 3; int item5 = 0; if (obj2.plc.ReadBool("Y105")) item5 = 1; if (obj2.plc.ReadBool("Y106")) item5 = 2; if (obj2.plc.ReadBool("Y114")) item5 = 3; int item6 = 0; if (obj2.plc.ReadBool("Y10A")) item6 = 1; if (obj2.plc.ReadBool("Y10B")) item6 = 2; if (obj2.plc.ReadBool("Y115")) item6 = 3; Console.WriteLine($"读取夹具状态,1#:{item1};2#:{item2};3#:{item3};4#:{item4};5#:{item5};6#:{item6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 7, Status = item1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 8, Status = item2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 9, Status = item3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 10, Status = item4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 11, Status = item5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 12, Status = item6, }); #endregion } if (obj3 != null) { #region 13-18 夹具 int item1 = 0; if (obj3.plc.ReadBool("YF0")) item1 = 1; if (obj3.plc.ReadBool("YF1")) item1 = 2; if (obj3.plc.ReadBool("Y110")) item1 = 3; int item2 = 0; if (obj3.plc.ReadBool("YF5")) item2 = 1; if (obj3.plc.ReadBool("YF6")) item2 = 2; if (obj3.plc.ReadBool("Y111")) item2 = 3; int item3 = 0; if (obj3.plc.ReadBool("YFA")) item3 = 1; if (obj3.plc.ReadBool("YFB")) item3 = 2; if (obj3.plc.ReadBool("Y112")) item3 = 3; int item4 = 0; if (obj3.plc.ReadBool("Y100")) item4 = 1; if (obj3.plc.ReadBool("Y101")) item4 = 2; if (obj3.plc.ReadBool("Y113")) item4 = 3; int item5 = 0; if (obj3.plc.ReadBool("Y105")) item5 = 1; if (obj3.plc.ReadBool("Y106")) item5 = 2; if (obj3.plc.ReadBool("Y114")) item5 = 3; int item6 = 0; if (obj3.plc.ReadBool("Y10A")) item6 = 1; if (obj3.plc.ReadBool("Y10B")) item6 = 2; if (obj3.plc.ReadBool("Y115")) item6 = 3; Console.WriteLine($"读取夹具状态,1#:{item1};2#:{item2};3#:{item3};4#:{item4};5#:{item5};6#:{item6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 13, Status = item1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 14, Status = item2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 15, Status = item3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 16, Status = item4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 17, Status = item5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 18, Status = item6, }); #endregion } if (obj4 != null) { #region 19-24 夹具 int item1 = 0; if (obj4.plc.ReadBool("YF0")) item1 = 1; if (obj4.plc.ReadBool("YF1")) item1 = 2; if (obj4.plc.ReadBool("Y110")) item1 = 3; int item2 = 0; if (obj4.plc.ReadBool("YF5")) item2 = 1; if (obj4.plc.ReadBool("YF6")) item2 = 2; if (obj4.plc.ReadBool("Y111")) item2 = 3; int item3 = 0; if (obj4.plc.ReadBool("YFA")) item3 = 1; if (obj4.plc.ReadBool("YFB")) item3 = 2; if (obj4.plc.ReadBool("Y112")) item3 = 3; int item4 = 0; if (obj4.plc.ReadBool("Y100")) item4 = 1; if (obj4.plc.ReadBool("Y101")) item4 = 2; if (obj4.plc.ReadBool("Y113")) item4 = 3; int item5 = 0; if (obj4.plc.ReadBool("Y105")) item5 = 1; if (obj4.plc.ReadBool("Y106")) item5 = 2; if (obj4.plc.ReadBool("Y114")) item5 = 3; int item6 = 0; if (obj4.plc.ReadBool("Y10A")) item6 = 1; if (obj4.plc.ReadBool("Y10B")) item6 = 2; if (obj4.plc.ReadBool("Y115")) item6 = 3; Console.WriteLine($"读取夹具状态,1#:{item1};2#:{item2};3#:{item3};4#:{item4};5#:{item5};6#:{item6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 19, Status = item1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 20, Status = item2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 21, Status = item3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 22, Status = item4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 23, Status = item5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 24, Status = item6, }); #endregion } return fixtureStatuses; } /// /// 读取夹具产量 /// public List ReadHolderOutPut(PlcModel obj1, PlcModel obj2, PlcModel obj3, PlcModel obj4) { List fixtureStatuses = new List(); if (obj1 != null) { byte[] info = obj1.plc.Read("D182", 24); #region 1-6 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取夹具产量,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 1, Yield = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 2, Yield = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 3, Yield = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 4, Yield = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 5, Yield = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 6, Yield = temp6, }); } #endregion } if (obj2 != null) { byte[] info = obj2.plc.Read("D182", 24); #region 7-12 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取夹具产量,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 7, Yield = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 8, Yield = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 9, Yield = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 10, Yield = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 11, Yield = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 12, Yield = temp6, }); } #endregion } if (obj3 != null) { byte[] info = obj3.plc.Read("D182", 24); #region 13-18 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取夹具产量,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 13, Yield = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 14, Yield = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 15, Yield = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 16, Yield = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 17, Yield = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 18, Yield = temp6, }); } #endregion } if (obj4 != null) { byte[] info = obj4.plc.Read("D182", 24); #region 19-24 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取夹具产量,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 19, Yield = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 20, Yield = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 21, Yield = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 22, Yield = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 23, Yield = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 24, Yield = temp6, }); } #endregion } return fixtureStatuses; } /// /// 读取固化时间 /// public List ReadSolidifyTime(PlcModel obj1, PlcModel obj2, PlcModel obj3, PlcModel obj4) { List fixtureStatuses = new List(); if (obj1 != null) { byte[] info = obj1.plc.Read("D910", 24); #region 1-6 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 1, PlanCuringTime = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 2, PlanCuringTime = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 3, PlanCuringTime = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 4, PlanCuringTime = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 5, PlanCuringTime = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 6, PlanCuringTime = temp6, }); } #endregion } if (obj2 != null) { byte[] info = obj2.plc.Read("D910", 24); #region 7-12 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 7, PlanCuringTime = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 8, PlanCuringTime = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 9, PlanCuringTime = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 10, PlanCuringTime = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 11, PlanCuringTime = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 12, PlanCuringTime = temp6, }); } #endregion } if (obj3 != null) { byte[] info = obj3.plc.Read("D910", 24); #region 13-18 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 13, PlanCuringTime = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 14, PlanCuringTime = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 15, PlanCuringTime = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 16, PlanCuringTime = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 17, PlanCuringTime = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 18, PlanCuringTime = temp6, }); } #endregion } if (obj4 != null) { byte[] info = obj4.plc.Read("D910", 24); #region 19-24 if (info != null) { 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(6).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(10).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}"); fixtureStatuses.Add(new FixtureStatus() { ObjId = 19, PlanCuringTime = temp1, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 20, PlanCuringTime = temp2, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 21, PlanCuringTime = temp3, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 22, PlanCuringTime = temp4, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 23, PlanCuringTime = temp5, }); fixtureStatuses.Add(new FixtureStatus() { ObjId = 24, PlanCuringTime = temp6, }); } #endregion } return fixtureStatuses; } /// /// 读取泡前库箱型 /// static List ReadStoreType(PlcModel obj, PlcModel obj2) { List spaceDetailModels = new List(); try { if (obj != null) { //夹具箱型 byte[] info = obj.plc.Read("D2010", 40); 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(40).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(60).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 1, StoreType = temp1.ToString(), }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 2, StoreType = temp2.ToString(), }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 3, StoreType = temp3.ToString(), }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 4, StoreType = temp4.ToString(), }); Console.WriteLine($"读取泡前库东线货道箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4}"); } if (obj2 != null) { //夹具箱型 byte[] info = obj2.plc.Read("D2010", 40); 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); int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(40).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(60).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 5, StoreType = temp1.ToString(), }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 6, StoreType = temp2.ToString(), }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 7, StoreType = temp3.ToString(), }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 8, StoreType = temp4.ToString(), }); Console.WriteLine($"读取泡前库西线货道箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4}"); } }catch(Exception ex) { Console.WriteLine($"读取泡前库货道箱型异常:{ex.Message}"); } return spaceDetailModels; } /// /// 读取泡前库库存 /// static List ReadStoreAmount(PlcModel obj, PlcModel obj2) { List spaceDetailModels = new List(); try { if (obj != null) { byte[] result = obj.plc.Read("L101", 1); string str1 = ByteArrayToBinary(array(result)).Substring(0, 3); int item1 = Regex.Matches(str1, "1").Count; byte[] result2 = obj.plc.Read("L201", 1); string str2 = ByteArrayToBinary(array(result2)).Substring(0, 3); int item2 = Regex.Matches(str2, "1").Count; byte[] result3 = obj.plc.Read("L301", 1); string str3 = ByteArrayToBinary(array(result3)).Substring(0, 3); int item3 = Regex.Matches(str3, "1").Count; byte[] result4 = obj.plc.Read("L401", 1); string str4 = ByteArrayToBinary(array(result4)).Substring(0, 3); int item4 = Regex.Matches(str4, "1").Count; spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 1, StoreAmount = item1, }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 2, StoreAmount = item2, }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 3, StoreAmount = item3, }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 4, StoreAmount = item4, }); Console.WriteLine($"读取泡前库东线库存,1#:{item1};2#{item2};3#:{item3};4#:{item4}"); } if (obj2 != null) { byte[] result = obj2.plc.Read("L101", 1); string str1 = ByteArrayToBinary(array(result)).Substring(0, 3); int item1 = Regex.Matches(str1, "1").Count; byte[] result2 = obj2.plc.Read("L201", 1); string str2 = ByteArrayToBinary(array(result2)).Substring(0, 3); int item2 = Regex.Matches(str2, "1").Count; byte[] result3 = obj2.plc.Read("L301", 1); string str3 = ByteArrayToBinary(array(result3)).Substring(0, 3); int item3 = Regex.Matches(str3, "1").Count; byte[] result4 = obj2.plc.Read("L401", 1); string str4 = ByteArrayToBinary(array(result4)).Substring(0, 3); int item4 = Regex.Matches(str4, "1").Count; spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 5, StoreAmount = item1, }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 6, StoreAmount = item2, }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 7, StoreAmount = item3, }); spaceDetailModels.Add(new SpaceDetailModel() { ObjId = 8, StoreAmount = item4, }); Console.WriteLine($"读取泡前库西线库存,1#:{item1};2#{item2};3#:{item3};4#:{item4}"); } } catch (Exception ex) { Console.WriteLine($"读取泡前库货道库存异常:{ex.Message}"); } return spaceDetailModels; } /// /// static byte[] array(byte[] data) { for (int i = 0; i < data.Length; i += 2) { byte temp = data[i]; data[i] = data[i + 1]; data[i + 1] = temp; } return data; } /// /// byte[]转二进制 /// /// static string ByteArrayToBinary(byte[] bytes) { StringBuilder binaryString = new StringBuilder(); foreach (byte b in bytes) { binaryString.Append(Convert.ToString(b, 2).PadLeft(8, '0')); } // Console.WriteLine(binaryString); string reversedStr = new string(binaryString.ToString().Reverse().ToArray()); // Console.WriteLine(reversedStr); return reversedStr; } } }