using Admin.Core.Common.Helper; using Aucma.Core.HwPLc; using NetTaste; using NPOI.Util; using System; using System.Collections.Generic; using System.DirectoryServices.Protocols; using System.Linq; using System.Security.RightsManagement; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Documents; namespace Aucma.Core.DoorFoam.Business { /// /// 采集发泡线数据 /// public class DoorCollection { // public delegate Task RefreshBoxFoamDataDelegate(List list); private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); // public static List listFixtureStatus = 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 ActualTimeList = new List(); public static List MoldTemperatureList = new List(); public static List ProductionCycleList = new List(); Semaphore semaphore = new Semaphore(1, 1); public DoorCollection() { startCollect(); } public void startCollect() { Task.Run(() => { while (true) { semaphore.WaitOne(); try { Thread.Sleep(3000); var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("门体发泡Plc")); if (obj != null) { //BoxTypeList.Clear(); ReadModeStatus(obj, BoxTypeList); // 1-5 6-10 11-15 16-20 21-25 25-30 ReadModeType(obj, "DB4.142", BoxTypeList); ReadModeType(obj, "DB4.342", BoxTypeList); ReadModeType(obj, "DB4.542", BoxTypeList); ReadModeType(obj, "DB4.742", BoxTypeList); ReadModeType(obj, "DB4.942", BoxTypeList); ReadModeType(obj, "DB4.1142", BoxTypeList); // 31-34 ReadModeTypeLast(obj, "DB4.1342", BoxTypeList); ReadModeProduct(obj, "DB4.1542", BoxTypeList); ReadModeProduct(obj, "DB4.1702", BoxTypeList); ReadModeProduct(obj, "DB4.1862", BoxTypeList); // 31-34 ReadModeProductLast(obj, "DB4.2022", BoxTypeList); ReadEquipStatusAndCycle(obj,BoxTypeList); ReadWarnInfo(obj, BoxTypeList); } } catch (Exception) { throw; } finally { semaphore.Release(); } } }); } /// /// 读取模位状态 /// static void ReadModeStatus(HwPLc.PlcModel obj, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read("DB4.0", 142); if (info == null) return; ///出模工位台车号,上料工位台车号,注料工位台车号 short tempNo1 = short.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short tempNo2 = short.Parse(StringChange.bytesToHexStr(info.Skip(2).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short tempNo3 = short.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); //模位状态,台车1#枪模式:0,不工作;1,A门工作;2,B门工作;3,AB门工作 short temp1 = short.Parse(StringChange.bytesToHexStr(info.Skip(6).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp2 = short.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp3 = short.Parse(StringChange.bytesToHexStr(info.Skip(10).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp4 = short.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp5 = short.Parse(StringChange.bytesToHexStr(info.Skip(14).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp6 = short.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp7 = short.Parse(StringChange.bytesToHexStr(info.Skip(18).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp8 = short.Parse(StringChange.bytesToHexStr(info.Skip(20).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp9 = short.Parse(StringChange.bytesToHexStr(info.Skip(22).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp10 = short.Parse(StringChange.bytesToHexStr(info.Skip(24).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp11 = short.Parse(StringChange.bytesToHexStr(info.Skip(26).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp12 = short.Parse(StringChange.bytesToHexStr(info.Skip(28).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp13 = short.Parse(StringChange.bytesToHexStr(info.Skip(30).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp14 = short.Parse(StringChange.bytesToHexStr(info.Skip(32).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp15 = short.Parse(StringChange.bytesToHexStr(info.Skip(34).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp16 = short.Parse(StringChange.bytesToHexStr(info.Skip(36).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp17 = short.Parse(StringChange.bytesToHexStr(info.Skip(38).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp18 = short.Parse(StringChange.bytesToHexStr(info.Skip(40).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp19 = short.Parse(StringChange.bytesToHexStr(info.Skip(42).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp20 = short.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp21 = short.Parse(StringChange.bytesToHexStr(info.Skip(46).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp22 = short.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp23 = short.Parse(StringChange.bytesToHexStr(info.Skip(50).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp24 = short.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp25 = short.Parse(StringChange.bytesToHexStr(info.Skip(54).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp26 = short.Parse(StringChange.bytesToHexStr(info.Skip(56).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp27 = short.Parse(StringChange.bytesToHexStr(info.Skip(58).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp28 = short.Parse(StringChange.bytesToHexStr(info.Skip(60).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp29 = short.Parse(StringChange.bytesToHexStr(info.Skip(62).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp30 = short.Parse(StringChange.bytesToHexStr(info.Skip(64).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp31 = short.Parse(StringChange.bytesToHexStr(info.Skip(66).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp32 = short.Parse(StringChange.bytesToHexStr(info.Skip(68).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp33 = short.Parse(StringChange.bytesToHexStr(info.Skip(70).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp34 = short.Parse(StringChange.bytesToHexStr(info.Skip(72).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp35 = short.Parse(StringChange.bytesToHexStr(info.Skip(74).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp36 = short.Parse(StringChange.bytesToHexStr(info.Skip(76).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp37 = short.Parse(StringChange.bytesToHexStr(info.Skip(78).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp38 = short.Parse(StringChange.bytesToHexStr(info.Skip(80).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp39 = short.Parse(StringChange.bytesToHexStr(info.Skip(82).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp40 = short.Parse(StringChange.bytesToHexStr(info.Skip(84).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp41 = short.Parse(StringChange.bytesToHexStr(info.Skip(86).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp42 = short.Parse(StringChange.bytesToHexStr(info.Skip(88).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp43 = short.Parse(StringChange.bytesToHexStr(info.Skip(90).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp44 = short.Parse(StringChange.bytesToHexStr(info.Skip(92).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp45 = short.Parse(StringChange.bytesToHexStr(info.Skip(94).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp46 = short.Parse(StringChange.bytesToHexStr(info.Skip(96).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp47 = short.Parse(StringChange.bytesToHexStr(info.Skip(98).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp48 = short.Parse(StringChange.bytesToHexStr(info.Skip(100).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp49 = short.Parse(StringChange.bytesToHexStr(info.Skip(102).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp50 = short.Parse(StringChange.bytesToHexStr(info.Skip(104).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp51 = short.Parse(StringChange.bytesToHexStr(info.Skip(106).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp52 = short.Parse(StringChange.bytesToHexStr(info.Skip(108).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp53 = short.Parse(StringChange.bytesToHexStr(info.Skip(110).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp54 = short.Parse(StringChange.bytesToHexStr(info.Skip(112).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp55 = short.Parse(StringChange.bytesToHexStr(info.Skip(114).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp56 = short.Parse(StringChange.bytesToHexStr(info.Skip(116).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp57 = short.Parse(StringChange.bytesToHexStr(info.Skip(118).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp58 = short.Parse(StringChange.bytesToHexStr(info.Skip(120).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp59 = short.Parse(StringChange.bytesToHexStr(info.Skip(122).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp60 = short.Parse(StringChange.bytesToHexStr(info.Skip(124).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp61 = short.Parse(StringChange.bytesToHexStr(info.Skip(126).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp62 = short.Parse(StringChange.bytesToHexStr(info.Skip(128).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp63 = short.Parse(StringChange.bytesToHexStr(info.Skip(130).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp64 = short.Parse(StringChange.bytesToHexStr(info.Skip(132).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp65 = short.Parse(StringChange.bytesToHexStr(info.Skip(134).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp66 = short.Parse(StringChange.bytesToHexStr(info.Skip(136).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp67 = short.Parse(StringChange.bytesToHexStr(info.Skip(138).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); short temp68 = short.Parse(StringChange.bytesToHexStr(info.Skip(140).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber); Console.WriteLine(temp68); } } } /// /// 读取模位型号,读5台,1-5,6-10... /// static void ReadModeType(HwPLc.PlcModel obj, string startStr, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read(startStr, 200); if (info == null) return; //1#台车1#枪A门,1#台车1#枪B门,1#台车2#枪A门,1#台车2#枪B门 string temp1 = asciiEncoding.GetString(info.Skip(0).Take(10).ToArray()).Trim('\n'); string temp2 = asciiEncoding.GetString(info.Skip(10).Take(10).ToArray()).Trim('\n'); string temp3 = asciiEncoding.GetString(info.Skip(20).Take(10).ToArray()).Trim('\n'); string temp4 = asciiEncoding.GetString(info.Skip(30).Take(10).ToArray()).Trim('\n'); string temp5 = asciiEncoding.GetString(info.Skip(40).Take(10).ToArray()).Trim('\n'); string temp6 = asciiEncoding.GetString(info.Skip(50).Take(10).ToArray()).Trim('\n'); string temp7 = asciiEncoding.GetString(info.Skip(60).Take(10).ToArray()).Trim('\n'); string temp8 = asciiEncoding.GetString(info.Skip(70).Take(10).ToArray()).Trim('\n'); string temp9 = asciiEncoding.GetString(info.Skip(80).Take(10).ToArray()).Trim('\n'); string temp10 = asciiEncoding.GetString(info.Skip(90).Take(10).ToArray()).Trim('\n'); string temp11 = asciiEncoding.GetString(info.Skip(100).Take(10).ToArray()).Trim('\n'); string temp12 = asciiEncoding.GetString(info.Skip(110).Take(10).ToArray()).Trim('\n'); string temp13 = asciiEncoding.GetString(info.Skip(120).Take(10).ToArray()).Trim('\n'); string temp14 = asciiEncoding.GetString(info.Skip(130).Take(10).ToArray()).Trim('\n'); string temp15 = asciiEncoding.GetString(info.Skip(140).Take(10).ToArray()).Trim('\n'); string temp16 = asciiEncoding.GetString(info.Skip(150).Take(10).ToArray()).Trim('\n'); string temp17 = asciiEncoding.GetString(info.Skip(160).Take(10).ToArray()).Trim('\n'); string temp18 = asciiEncoding.GetString(info.Skip(170).Take(10).ToArray()).Trim('\n'); string temp19 = asciiEncoding.GetString(info.Skip(180).Take(10).ToArray()).Trim('\n'); string temp20 = asciiEncoding.GetString(info.Skip(190).Take(10).ToArray()).Trim('\n'); Console.WriteLine(temp20); } } } /// /// 读取模位型号,读4台,31-34 /// static void ReadModeTypeLast(HwPLc.PlcModel obj, string startStr, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read(startStr, 160); if (info == null) return; //1#台车1#枪A门,1#台车1#枪B门,1#台车2#枪A门,1#台车2#枪B门 string temp1 = asciiEncoding.GetString(info.Skip(0).Take(10).ToArray()).Trim('\n'); string temp2 = asciiEncoding.GetString(info.Skip(10).Take(10).ToArray()).Trim('\n'); string temp3 = asciiEncoding.GetString(info.Skip(20).Take(10).ToArray()).Trim('\n'); string temp4 = asciiEncoding.GetString(info.Skip(30).Take(10).ToArray()).Trim('\n'); string temp5 = asciiEncoding.GetString(info.Skip(40).Take(10).ToArray()).Trim('\n'); string temp6 = asciiEncoding.GetString(info.Skip(50).Take(10).ToArray()).Trim('\n'); string temp7 = asciiEncoding.GetString(info.Skip(60).Take(10).ToArray()).Trim('\n'); string temp8 = asciiEncoding.GetString(info.Skip(70).Take(10).ToArray()).Trim('\n'); string temp9 = asciiEncoding.GetString(info.Skip(80).Take(10).ToArray()).Trim('\n'); string temp10 = asciiEncoding.GetString(info.Skip(90).Take(10).ToArray()).Trim('\n'); string temp11 = asciiEncoding.GetString(info.Skip(100).Take(10).ToArray()).Trim('\n'); string temp12 = asciiEncoding.GetString(info.Skip(110).Take(10).ToArray()).Trim('\n'); string temp13 = asciiEncoding.GetString(info.Skip(120).Take(10).ToArray()).Trim('\n'); string temp14 = asciiEncoding.GetString(info.Skip(130).Take(10).ToArray()).Trim('\n'); string temp15 = asciiEncoding.GetString(info.Skip(140).Take(10).ToArray()).Trim('\n'); string temp16 = asciiEncoding.GetString(info.Skip(150).Take(10).ToArray()).Trim('\n'); Console.WriteLine(temp16); } } } /// /// 读取模位产量1-10 ,10-20,20-30 /// static void ReadModeProduct(HwPLc.PlcModel obj, string startStr, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read(startStr, 160); if (info == null) return; //1#台车1#枪A门,1#台车1#枪B门,1#台车2#枪A门,1#台车2#枪B门 int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp3 = int.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp4 = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp5 = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp6 = int.Parse(StringChange.bytesToHexStr(info.Skip(20).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp7 = int.Parse(StringChange.bytesToHexStr(info.Skip(24).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp8 = int.Parse(StringChange.bytesToHexStr(info.Skip(28).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp9 = int.Parse(StringChange.bytesToHexStr(info.Skip(32).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp10 = int.Parse(StringChange.bytesToHexStr(info.Skip(36).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp11 = int.Parse(StringChange.bytesToHexStr(info.Skip(40).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp12 = int.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp13 = int.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp14 = int.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp15 = int.Parse(StringChange.bytesToHexStr(info.Skip(56).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp16 = int.Parse(StringChange.bytesToHexStr(info.Skip(60).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp17 = int.Parse(StringChange.bytesToHexStr(info.Skip(64).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp18 = int.Parse(StringChange.bytesToHexStr(info.Skip(68).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp19 = int.Parse(StringChange.bytesToHexStr(info.Skip(72).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp20 = int.Parse(StringChange.bytesToHexStr(info.Skip(76).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp21 = int.Parse(StringChange.bytesToHexStr(info.Skip(80).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp22 = int.Parse(StringChange.bytesToHexStr(info.Skip(84).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp23 = int.Parse(StringChange.bytesToHexStr(info.Skip(88).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp24 = int.Parse(StringChange.bytesToHexStr(info.Skip(92).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp25 = int.Parse(StringChange.bytesToHexStr(info.Skip(96).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp26 = int.Parse(StringChange.bytesToHexStr(info.Skip(100).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp27 = int.Parse(StringChange.bytesToHexStr(info.Skip(104).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp28 = int.Parse(StringChange.bytesToHexStr(info.Skip(108).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp29 = int.Parse(StringChange.bytesToHexStr(info.Skip(112).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp30 = int.Parse(StringChange.bytesToHexStr(info.Skip(116).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp31 = int.Parse(StringChange.bytesToHexStr(info.Skip(120).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp32 = int.Parse(StringChange.bytesToHexStr(info.Skip(124).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp33 = int.Parse(StringChange.bytesToHexStr(info.Skip(128).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp34 = int.Parse(StringChange.bytesToHexStr(info.Skip(132).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp35 = int.Parse(StringChange.bytesToHexStr(info.Skip(136).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp36 = int.Parse(StringChange.bytesToHexStr(info.Skip(140).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp37 = int.Parse(StringChange.bytesToHexStr(info.Skip(144).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp38 = int.Parse(StringChange.bytesToHexStr(info.Skip(148).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp39 = int.Parse(StringChange.bytesToHexStr(info.Skip(152).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp40 = int.Parse(StringChange.bytesToHexStr(info.Skip(156).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); Console.WriteLine(temp16); } } } /// /// 读取模位产量1-10 ,10-20,20-30 /// static void ReadModeProductLast(HwPLc.PlcModel obj, string startStr, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read(startStr, 64); if (info == null) return; //1#台车1#枪A门,1#台车1#枪B门,1#台车2#枪A门,1#台车2#枪B门 int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp3 = int.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp4 = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp5 = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp6 = int.Parse(StringChange.bytesToHexStr(info.Skip(20).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp7 = int.Parse(StringChange.bytesToHexStr(info.Skip(24).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp8 = int.Parse(StringChange.bytesToHexStr(info.Skip(28).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp9 = int.Parse(StringChange.bytesToHexStr(info.Skip(32).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp10 = int.Parse(StringChange.bytesToHexStr(info.Skip(36).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp11 = int.Parse(StringChange.bytesToHexStr(info.Skip(40).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp12 = int.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp13 = int.Parse(StringChange.bytesToHexStr(info.Skip(48).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp14 = int.Parse(StringChange.bytesToHexStr(info.Skip(52).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp15 = int.Parse(StringChange.bytesToHexStr(info.Skip(56).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); int temp16 = int.Parse(StringChange.bytesToHexStr(info.Skip(60).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber); Console.WriteLine(temp16); } } } /// /// 读取设备状态及生产节拍 /// static void ReadEquipStatusAndCycle(HwPLc.PlcModel obj, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read("DB4.2086", 10); if (info == null) return; //设备状态1运行 2停机 3故障 int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray())); // 生产节拍 float temp2 = byteToFloat(info.Skip(2).Take(4).ToArray()); //节拍 float temp3 = byteToFloat(info.Skip(6).Take(4).ToArray()); Console.WriteLine(temp1); } } } /// /// 读取设备报警信息 /// static void ReadWarnInfo(HwPLc.PlcModel obj, List boxTypeList) { if (obj == null) return; else { if (obj.plc.IsConnected) { byte[] info = obj.plc.Read("DB4.2136", 4); if (info == null) return; //1-主驱动报警 2-枪1X轴伺服异常 3-枪2X轴伺服异常 4-换模位门打开 5-枪1急停被激活 6-枪2急停被激活 7-枪1发泡机报警 8-枪2发泡机报警 int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray())); Console.WriteLine(temp1); } } } #region 字符工具转换方法 /// /// byte数组转换为float /// static float byteToFloat(byte[] list) { float result = 0.00f; Array.Reverse(list); result = BitConverter.ToSingle(list, 0); return result; } /// /// byte[]转二进制,读两字节,截取1字节 00000000 (00100000) /// /// 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; } /// /// 根据二进制字符串确定夹具状态 1正常生产 2暂停生产 /// static int judgeStatus(string str1) { int item1 = 0; if (str1.Substring(0, 1) == "1") { item1 = 1; // } else if (str1.Substring(1, 1) == "1") { item1 = 2; // } else if (str1.Substring(2, 1) == "1") { item1 = 3; // } else if (str1.Substring(3, 1) == "1") { item1 = 4; // } else if (str1.Substring(4, 1) == "1") { item1 = 5; // } else if (str1.Substring(5, 1) == "1") { item1 = 6; // } else if (str1.Substring(6, 1) == "1") { item1 = 7; // } else if (str1.Substring(7, 1) == "1") { item1 = 8; // } return item1; } } #endregion }