add - 新发泡线数据采集

dev
liuwf 1 year ago
parent af1a8e25fe
commit 04cfd447d4

@ -1,4 +1,6 @@
using System;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Utilities.Encoders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -20,5 +22,25 @@ namespace Admin.Core.Common.Helper
}
return returnStr;
}
public static string BytesToDecimalStr(byte[] bytes, int iLen)
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < iLen; i++)
{
string temp = bytes[i].ToString("X2");
int aa = int.Parse(temp, System.Globalization.NumberStyles.HexNumber);
returnStr += temp;
}
}
return returnStr;
}
}
}

@ -1,383 +0,0 @@
//using Admin.Core.Common.Helper;
//using Aucma.Core.HwPLc;
//using Aucma.Core.OldBoxFoam.Models;
//using NetTaste;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//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 List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
// public List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
// public List<int> BoxTypeList = new List<int>();
// public List<int> HolderStatusList = new List<int>();
// public List<int> HolderOutPutList = new List<int>();
// public List<int> SolidifyTimeList = new List<int>();
// public List<string> StoreTypeList = new List<string>();
// public List<string> StoreAmountList = new List<string>();
// public Collection() {
// }
// public void startCollect()
// {
// try
// {
// ///Task.Run(() =>
// //{
// // Thread.Sleep(3000);
// 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"));
// //while (true)
// //{
// BoxTypeList.Clear();
// HolderStatusList.Clear();
// HolderOutPutList.Clear();
// SolidifyTimeList.Clear();
// listFixtureStatus.Clear();//夹具集合
// spaceDetailModel.Clear();//货道集合
// //夹具箱型
// ReadBoxType(plc1, BoxTypeList);
// ReadBoxType(plc2, BoxTypeList);
// ReadBoxType(plc3, BoxTypeList);
// ReadBoxType(plc4, BoxTypeList);
// ReadHolderStatus(plc1, HolderStatusList);
// ReadHolderStatus(plc2, HolderStatusList);
// ReadHolderStatus(plc3, HolderStatusList);
// ReadHolderStatus(plc4, HolderStatusList);
// ReadHolderOutPut(plc1, HolderOutPutList);
// ReadHolderOutPut(plc2, HolderOutPutList);
// ReadHolderOutPut(plc3, HolderOutPutList);
// ReadHolderOutPut(plc4, HolderOutPutList);
// ReadSolidifyTime(plc1, SolidifyTimeList);
// ReadSolidifyTime(plc2, SolidifyTimeList);
// ReadSolidifyTime(plc3, SolidifyTimeList);
// ReadSolidifyTime(plc4, SolidifyTimeList);
// ReadStoreType(plc1, StoreTypeList);
// ReadStoreType(plc2, StoreTypeList);
// ReadStoreType(plc3, StoreTypeList);
// ReadStoreType(plc4, StoreTypeList);
// ReadStoreAmount(plc1, StoreAmountList);
// ReadStoreAmount(plc2, StoreAmountList);
// ReadStoreAmount(plc3, StoreAmountList);
// ReadStoreAmount(plc4, StoreAmountList);
// for (int i = 0; i < 24; i++)
// {
// //if (listFixtureStatus.Count > 0)
// //{
// FixtureStatus model = new FixtureStatus();
// model.ObjId = i + 1;
// if (BoxTypeList!=null &&BoxTypeList.Count > 0) model.FixtureBoxType = BoxTypeList[i].ToString();
// if (HolderStatusList!=null &&HolderStatusList.Count > 0) model.Status = HolderStatusList[i];
// if (HolderOutPutList!=null && HolderOutPutList.Count > 0) model.Yield = HolderOutPutList[i];
// if (SolidifyTimeList!=null &&SolidifyTimeList.Count > 0) model.PlanCuringTime = SolidifyTimeList[i];
// listFixtureStatus.Add(model);
// }
// for (int i = 0; i < 8; i++)
// {
// SpaceDetailModel model = new SpaceDetailModel();
// model.ObjId = i + 1;
// if (StoreTypeList.Count > 0) model.StoreType = StoreTypeList[i].ToString();
// if (StoreAmountList.Count > 0) model.StoreAmount = Convert.ToInt32(StoreAmountList[i]);
// spaceDetailModel.Add(model);
// }
// // Thread.Sleep(10000);
// //}
// //});
// }catch(Exception ex)
// {
// Console.WriteLine(ex.Message);
// }
// }
// /// <summary>
// /// 读取夹具箱型
// /// </summary>
// static void ReadBoxType(HwPLc.PlcModel obj, List<int> BoxTypeList)
// {
// if (obj == null) return;
// if (obj.plc.IsConnected)
// {
// byte[] result = obj.plc.Read("D3140", 48);
// if (result == null) 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(4).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
// int temp3 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(8).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
// int temp4 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(12).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
// int temp5 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(16).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
// int temp6 = short.Parse(StringChange.bytesToHexStr(array(info.Skip(18).Take(2).ToArray()), 2), System.Globalization.NumberStyles.HexNumber);
// BoxTypeList.Add(temp1);
// BoxTypeList.Add(temp2);
// BoxTypeList.Add(temp3);
// BoxTypeList.Add(temp4);
// BoxTypeList.Add(temp5);
// BoxTypeList.Add(temp6);
// Console.WriteLine($"读取夹具箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
// }
// }
// /// <summary>
// /// 读取夹具状态
// /// </summary>
// static void ReadHolderStatus(PlcModel obj1, List<int> HolderStatusList)
// {
// if (obj1 == null) return;
// byte[] result = obj1.plc.Read("YF0", 1);
// if (result == null) return;
// //输出二进制字符串,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;
// }
// HolderStatusList.Add(item1);
// HolderStatusList.Add(item2);
// HolderStatusList.Add(item3);
// HolderStatusList.Add(item4);
// HolderStatusList.Add(item5);
// HolderStatusList.Add(item6);
// Console.WriteLine($"读取夹具状态,1#:{item1};2#:{item2};3#:{item3};4#:{item4};5#:{item5};6#:{item6}");
// }
// /// <summary>
// /// 读取夹具产量
// /// </summary>
// static void ReadHolderOutPut(PlcModel obj,List<int> HolderOutPutList)
// {
// if (obj == null) return;
// byte[] result = obj.plc.Read("D182", 24);
// if (result == null) 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);
// 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);
// HolderOutPutList.Add(temp1);
// HolderOutPutList.Add(temp2);
// HolderOutPutList.Add(temp3);
// HolderOutPutList.Add(temp4);
// HolderOutPutList.Add(temp5);
// HolderOutPutList.Add(temp6);
// Console.WriteLine($"读取夹具产量,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
// }
// /// <summary>
// /// 读取固化时间
// /// </summary>
// static void ReadSolidifyTime(PlcModel obj,List<int> SolidifyTimeList)
// {
// if (obj == null) return;
// byte[] result = obj.plc.Read("D910", 24);
// if (result == null) 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);
// 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);
// SolidifyTimeList.Add(temp1);
// SolidifyTimeList.Add(temp2);
// SolidifyTimeList.Add(temp3);
// SolidifyTimeList.Add(temp4);
// SolidifyTimeList.Add(temp5);
// SolidifyTimeList.Add(temp6);
// Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
// }
// /// <summary>
// /// 读取泡前库箱型
// /// </summary>
// static void ReadStoreType(PlcModel obj, List<string> storeType)
// {
// if (obj == null) return;
// //夹具箱型
// byte[] result = obj.plc.Read("D2010", 40);
// if (result == null) 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);
// 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);
// storeType.Add(temp1.ToString());
// storeType.Add(temp2.ToString());
// storeType.Add(temp2.ToString());
// storeType.Add(temp2.ToString());
// Console.WriteLine($"读取泡前库箱型,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4}");
// }
// /// <summary>
// /// 读取泡前库库存
// /// </summary>
// static void ReadStoreAmount(PlcModel obj, List<string> storeAmount)
// {
// if (obj == null) return;
// byte[] result = obj.plc.Read("L101", 1);
// if (result == null) return;
// 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;
// Console.WriteLine($"读取泡前库库存,1#:{item1};2#{item2};3#:{item3};4#:{item4}");
// }
// /// <param name="data"></param>
// /// <returns></returns>
// 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;
// }
// /// <summary>
// /// byte[]转二进制
// /// </summary>
// /// <param name="bytes"></param>
// 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,8 +1,14 @@
using System;
using Admin.Core.Common.Helper;
using Aucma.Core.HwPLc;
using NetTaste;
using NPOI.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Documents;
namespace Aucma.Core.BoxFoam.Business
{
@ -11,6 +17,270 @@ namespace Aucma.Core.BoxFoam.Business
/// </summary>
public class CollectionFoamLine
{
private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
public CollectionFoamLine()
{
}
public async void startCollect()
{
Task.Run(() =>
{
Thread.Sleep(6000);
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine1Plc"));
ReadBoxType(obj); // ok
// ReadFixtureStatus(obj); //ok
// ReadFixtureProduction(obj); //ok
// ReadPlanCuringTime(obj); //ok
// ReadDisplayCuringTime(obj); //ok
// ReadMoldTemperature(obj);
// ReadLineStatus(obj); //ok
});
}
/// <summary>
/// 读取夹具箱型
/// </summary>
static void ReadBoxType(HwPLc.PlcModel obj)
{
if (obj == null) return;
if (obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("DB8.0", 124);
byte[] info = result;
if (result == null) return;
int str0 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
string str1 = asciiEncoding.GetString(result.Skip(4).Take(10).ToArray()).Trim('\n');
string str2 = asciiEncoding.GetString(result.Skip(14).Take(10).ToArray()).Trim('\n');
string str3 = asciiEncoding.GetString(result.Skip(24).Take(10).ToArray()).Trim('\n');
string str4 = asciiEncoding.GetString(result.Skip(34).Take(10).ToArray()).Trim('\n');
string str5 = asciiEncoding.GetString(result.Skip(44).Take(10).ToArray()).Trim('\n');
string str6 = asciiEncoding.GetString(result.Skip(54).Take(10).ToArray()).Trim('\n');
string str7 = asciiEncoding.GetString(result.Skip(64).Take(10).ToArray()).Trim('\n');
string str8 = asciiEncoding.GetString(result.Skip(74).Take(10).ToArray()).Trim('\n');
string str9 = asciiEncoding.GetString(result.Skip(84).Take(10).ToArray()).Trim('\n');
string str10 = asciiEncoding.GetString(result.Skip(94).Take(10).ToArray()).Trim('\n');
string str11 = asciiEncoding.GetString(result.Skip(104).Take(10).ToArray()).Trim('\n');
string str12 = asciiEncoding.GetString(result.Skip(114).Take(10).ToArray()).Trim('\n');
}
}
/// <summary>
/// 读取夹具状态
/// </summary>
static void ReadFixtureStatus(HwPLc.PlcModel obj)
{
byte[] result = obj.plc.Read("DB8.122", 23);
byte[] info = result;
int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray()));
int temp2 = judgeStatus(ByteArrayToBinary(info.Skip(2).Take(1).ToArray()));
int temp3 = judgeStatus(ByteArrayToBinary(info.Skip(4).Take(1).ToArray()));
int temp4 = judgeStatus(ByteArrayToBinary(info.Skip(6).Take(1).ToArray()));
int temp5 = judgeStatus(ByteArrayToBinary(info.Skip(8).Take(1).ToArray()));
int temp6 = judgeStatus(ByteArrayToBinary(info.Skip(10).Take(1).ToArray()));
int temp7 = judgeStatus(ByteArrayToBinary(info.Skip(12).Take(1).ToArray()));
int temp8 = judgeStatus(ByteArrayToBinary(info.Skip(14).Take(1).ToArray()));
int temp9 = judgeStatus(ByteArrayToBinary(info.Skip(16).Take(1).ToArray()));
int temp10 = judgeStatus(ByteArrayToBinary(info.Skip(18).Take(1).ToArray()));
int temp11 = judgeStatus(ByteArrayToBinary(info.Skip(20).Take(1).ToArray()));
int temp12 = judgeStatus(ByteArrayToBinary(info.Skip(22).Take(1).ToArray()));
Console.WriteLine($"读取夹具状态,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
Console.WriteLine($"读取夹具状态,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
}
/// <summary>
/// 读取夹具产量
/// </summary>
static void ReadFixtureProduction(HwPLc.PlcModel obj)
{
if (obj == null) return;
if (obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("DB8.146", 48);
byte[] info = result;
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);
Console.WriteLine($"读取夹具产量,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
Console.WriteLine($"读取夹具产量,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
}
}
/// <summary>
/// 固化时间设定值
/// </summary>
static void ReadPlanCuringTime(HwPLc.PlcModel obj)
{
if (obj == null) return;
if (obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("DB8.194", 48);
byte[] info = result;
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);
Console.WriteLine($"读取固化时间设定值,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
Console.WriteLine($"读取固化时间设定值,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
}
}
/// <summary>
/// 固化时间显示值
/// </summary>
static void ReadDisplayCuringTime(HwPLc.PlcModel obj)
{
if (obj == null) return;
if (obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("DB8.242", 48);
byte[] info = result;
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);
Console.WriteLine($"读取固化时间显示值,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
Console.WriteLine($"读取固化时间显示值,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
}
}
/// <summary>
/// 模具内外温度
/// </summary>
static void ReadMoldTemperature(HwPLc.PlcModel obj)
{
if (obj == null) return;
if (obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("DB8.294", 96);
byte[] info = result;
// float temp1 = BitConverter.ToSingle(BitConverter.GetBytes(Convert.ToInt32(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 16)), 0);
//if (BitConverter.IsLittleEndian)
//{
// Array.Reverse(info.Skip(0).Take(4).ToArray()); // 如果系统是小端字节序,则反转字节数组的顺序
//}
float temp1 = float.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);
Console.WriteLine($"读取固化时间显示值,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
Console.WriteLine($"读取固化时间显示值,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
}
}
/// <summary>
/// 发泡线状态
/// </summary>
static void ReadLineStatus(HwPLc.PlcModel obj)
{
byte[] result = obj.plc.Read("DB8.630", 1);
byte[] info = result;
int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray()));
Console.WriteLine($"发泡线状态:{temp1}");
}
#region 字符工具转换方法
/// byte[]转十进制ascii码
/// </summary>
/// <param name="bytes"></param>
static string ByteArrayToString(byte[] bytes)
{
string result = string.Empty;
foreach (byte b in bytes)
{
int decimalValue = Convert.ToInt32(b); // 将字节转换为十进制值
result += decimalValue;
}
return result;
}
/// <summary>
/// byte[]转二进制
/// </summary>
/// <param name="bytes"></param>
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;
}
/// <summary>
/// 根据二进制字符串确定夹具状态 1正常生产 2暂停生产
/// </summary>
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; //
}
return item1;
}
}
#endregion
}
}

@ -21,6 +21,7 @@ using System.Windows.Documents;
using System.Timers;
using NetTaste;
using Org.BouncyCastle.Asn1.Tsp;
using System.Printing;
namespace Aucma.Core.BoxFoam.Business
{
@ -106,11 +107,11 @@ namespace Aucma.Core.BoxFoam.Business
private List<SpaceAddress> spaceAddresses = new List<SpaceAddress>();
private SemaphoreSlim _lock = new SemaphoreSlim(1);
private static int AAA = 1;
public CollectionFoamLine coll = new CollectionFoamLine();
public void init()
{
allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
coll.startCollect();
allSpaces = _baseSpaceInfoServices.Query(x => x.StoreCode == storeCode);
foreach (var space in allSpaces)
{
spaceAddresses.Add(spaceConfig.GetSpaceAddress(storeCode, space.SpaceCode));

Loading…
Cancel
Save