You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
539 lines
26 KiB
C#
539 lines
26 KiB
C#
using Admin.Core.Common.Helper;
|
|
using Aucma.Core.BoxFoam.Models;
|
|
using Aucma.Core.HwPLc;
|
|
using NetTaste;
|
|
using NPOI.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.RightsManagement;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Documents;
|
|
|
|
namespace Aucma.Core.BoxFoam.Business
|
|
{
|
|
/// <summary>
|
|
/// 采集发泡线数据
|
|
/// </summary>
|
|
public class CollectionFoamLine
|
|
{
|
|
public delegate Task RefreshBoxFoamDataDelegate(List<FixtureStatus> list);
|
|
public static event RefreshBoxFoamDataDelegate RefreshBoxFoamDataDelegateEvent;
|
|
|
|
private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
|
|
|
|
public static List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
|
|
|
|
public static List<string> BoxTypeList = new List<string>();
|
|
public static List<int> HolderStatusList = new List<int>();
|
|
public static List<int> HolderOutPutList = new List<int>();
|
|
public static List<int> SolidifyTimeList = new List<int>();
|
|
public static List<int> ActualTimeList = new List<int>();
|
|
public static List<float> MoldTemperatureList = new List<float>();
|
|
public static List<float> ProductionCycleList = new List<float>();
|
|
Semaphore semaphore = new Semaphore(1, 1);
|
|
public CollectionFoamLine()
|
|
{
|
|
startCollect();
|
|
}
|
|
|
|
public void startCollect()
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
while (true)
|
|
{
|
|
semaphore.WaitOne();
|
|
try
|
|
{
|
|
Thread.Sleep(3000);
|
|
|
|
|
|
var obj = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine1Plc"));
|
|
|
|
if (obj != null)
|
|
{
|
|
BoxTypeList.Clear();
|
|
HolderStatusList.Clear();
|
|
HolderOutPutList.Clear();
|
|
SolidifyTimeList.Clear();
|
|
ActualTimeList.Clear();
|
|
listFixtureStatus.Clear();
|
|
MoldTemperatureList.Clear();
|
|
ProductionCycleList.Clear();
|
|
ReadProductionCycle(obj, ProductionCycleList);
|
|
ReadMoldTemperature(obj, MoldTemperatureList);
|
|
ReadBoxType(obj, BoxTypeList);
|
|
ReadFixtureStatus(obj, HolderStatusList);
|
|
ReadFixtureProduction(obj, HolderOutPutList);
|
|
ReadPlanCuringTime(obj, SolidifyTimeList);
|
|
ReadDisplayCuringTime(obj, ActualTimeList);
|
|
|
|
|
|
for (int i = 0; i < 12; i++)
|
|
{
|
|
FixtureStatus model = new FixtureStatus();
|
|
model.ObjId = i + 1;
|
|
if (BoxTypeList.Count > 0 && BoxTypeList != null)
|
|
{
|
|
model.FixtureBoxType = BoxTypeList[i].ToString();
|
|
}
|
|
else
|
|
{
|
|
model.FixtureBoxType = "";
|
|
}
|
|
if (HolderStatusList.Count > 0 && HolderStatusList != null)
|
|
{
|
|
model.Status = HolderStatusList[i];
|
|
}
|
|
else
|
|
{
|
|
model.Status = HolderStatusList[i];
|
|
}
|
|
if (HolderOutPutList.Count > 0 && HolderOutPutList != null)
|
|
{
|
|
model.Yield = HolderOutPutList[i];
|
|
}
|
|
else
|
|
{
|
|
model.Yield = 0;
|
|
}
|
|
if (SolidifyTimeList.Count > 0 && HolderOutPutList != null)
|
|
{
|
|
model.PlanCuringTime = SolidifyTimeList[i];
|
|
}
|
|
else
|
|
{
|
|
model.PlanCuringTime = 0;
|
|
}
|
|
if (MoldTemperatureList.Count > 0 && MoldTemperatureList != null)
|
|
{
|
|
model.InternalTemperature = MoldTemperatureList[i].ToString();
|
|
model.OutsideTemperature = MoldTemperatureList[i + 12].ToString();
|
|
}
|
|
else
|
|
{
|
|
model.InternalTemperature = "";
|
|
model.OutsideTemperature = "";
|
|
}
|
|
if (ProductionCycleList.Count > 0 && ProductionCycleList != null)
|
|
{
|
|
model.ProductionCycle = ProductionCycleList[i];
|
|
}
|
|
else
|
|
{
|
|
model.ProductionCycle = 0;
|
|
}
|
|
|
|
listFixtureStatus.Add(model);
|
|
}
|
|
RefreshBoxFoamDataDelegateEvent?.Invoke(listFixtureStatus);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
semaphore.Release();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 读取夹具箱型
|
|
/// </summary>
|
|
static void ReadBoxType(HwPLc.PlcModel obj, List<string> boxTypeList)
|
|
{
|
|
if (obj == null) return;
|
|
else
|
|
{
|
|
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');
|
|
boxTypeList.Add(str1);
|
|
boxTypeList.Add(str2);
|
|
boxTypeList.Add(str3);
|
|
boxTypeList.Add(str4);
|
|
boxTypeList.Add(str5);
|
|
boxTypeList.Add(str6);
|
|
boxTypeList.Add(str7);
|
|
boxTypeList.Add(str8);
|
|
boxTypeList.Add(str9);
|
|
boxTypeList.Add(str10);
|
|
boxTypeList.Add(str11);
|
|
boxTypeList.Add(str12);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取夹具状态
|
|
/// </summary>
|
|
static void ReadFixtureStatus(HwPLc.PlcModel obj, List<int> HolderStatusList)
|
|
{
|
|
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()));
|
|
|
|
HolderStatusList.Add(temp1);
|
|
HolderStatusList.Add(temp2);
|
|
HolderStatusList.Add(temp3);
|
|
HolderStatusList.Add(temp4);
|
|
HolderStatusList.Add(temp5);
|
|
HolderStatusList.Add(temp6);
|
|
HolderStatusList.Add(temp7);
|
|
HolderStatusList.Add(temp8);
|
|
HolderStatusList.Add(temp9);
|
|
HolderStatusList.Add(temp10);
|
|
HolderStatusList.Add(temp11);
|
|
HolderStatusList.Add(temp11);
|
|
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, List<int> HolderOutPutList)
|
|
{
|
|
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);
|
|
|
|
HolderOutPutList.Add(temp1);
|
|
HolderOutPutList.Add(temp2);
|
|
HolderOutPutList.Add(temp3);
|
|
HolderOutPutList.Add(temp4);
|
|
HolderOutPutList.Add(temp5);
|
|
HolderOutPutList.Add(temp6);
|
|
HolderOutPutList.Add(temp7);
|
|
HolderOutPutList.Add(temp8);
|
|
HolderOutPutList.Add(temp9);
|
|
HolderOutPutList.Add(temp10);
|
|
HolderOutPutList.Add(temp11);
|
|
HolderOutPutList.Add(temp12);
|
|
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, List<int> SolidifyTimeList)
|
|
{
|
|
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);
|
|
|
|
|
|
SolidifyTimeList.Add(temp1);
|
|
SolidifyTimeList.Add(temp2);
|
|
SolidifyTimeList.Add(temp3);
|
|
SolidifyTimeList.Add(temp4);
|
|
SolidifyTimeList.Add(temp5);
|
|
SolidifyTimeList.Add(temp6);
|
|
SolidifyTimeList.Add(temp7);
|
|
SolidifyTimeList.Add(temp8);
|
|
SolidifyTimeList.Add(temp9);
|
|
SolidifyTimeList.Add(temp10);
|
|
SolidifyTimeList.Add(temp11);
|
|
SolidifyTimeList.Add(temp12);
|
|
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, List<int> ActualTimeList)
|
|
{
|
|
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);
|
|
|
|
ActualTimeList.Add(temp1);
|
|
ActualTimeList.Add(temp2);
|
|
ActualTimeList.Add(temp3);
|
|
ActualTimeList.Add(temp4);
|
|
ActualTimeList.Add(temp5);
|
|
ActualTimeList.Add(temp6);
|
|
ActualTimeList.Add(temp7);
|
|
ActualTimeList.Add(temp8);
|
|
ActualTimeList.Add(temp9);
|
|
ActualTimeList.Add(temp10);
|
|
ActualTimeList.Add(temp11);
|
|
ActualTimeList.Add(temp12);
|
|
|
|
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, List<float> MoldTemperatureList)
|
|
{
|
|
if (obj == null) return;
|
|
if (obj.plc.IsConnected)
|
|
{
|
|
byte[] info = obj.plc.Read("DB8.294", 284);
|
|
float temp1 = byteToFloat(info.Skip(0).Take(4).ToArray());
|
|
float temp2 = byteToFloat(info.Skip(16).Take(4).ToArray());
|
|
float temp3 = byteToFloat(info.Skip(24).Take(4).ToArray());
|
|
float temp4 = byteToFloat(info.Skip(40).Take(4).ToArray());
|
|
float temp5 = byteToFloat(info.Skip(48).Take(4).ToArray());
|
|
float temp6 = byteToFloat(info.Skip(64).Take(4).ToArray());
|
|
float temp7 = byteToFloat(info.Skip(72).Take(4).ToArray());
|
|
float temp8 = byteToFloat(info.Skip(88).Take(4).ToArray());
|
|
|
|
float temp9 = byteToFloat(info.Skip(96).Take(4).ToArray());
|
|
float temp10 = byteToFloat(info.Skip(112).Take(4).ToArray());
|
|
float temp11 = byteToFloat(info.Skip(120).Take(4).ToArray());
|
|
float temp12 = byteToFloat(info.Skip(136).Take(4).ToArray());
|
|
float temp13 = byteToFloat(info.Skip(144).Take(4).ToArray());
|
|
float temp14 = byteToFloat(info.Skip(160).Take(4).ToArray());
|
|
|
|
float temp15 = byteToFloat(info.Skip(168).Take(4).ToArray());
|
|
float temp16 = byteToFloat(info.Skip(184).Take(4).ToArray());
|
|
|
|
float temp17 = byteToFloat(info.Skip(192).Take(4).ToArray());
|
|
float temp18 = byteToFloat(info.Skip(208).Take(4).ToArray());
|
|
|
|
float temp19 = byteToFloat(info.Skip(216).Take(4).ToArray());
|
|
float temp20 = byteToFloat(info.Skip(232).Take(4).ToArray());
|
|
|
|
float temp21 = byteToFloat(info.Skip(240).Take(4).ToArray());
|
|
float temp22 = byteToFloat(info.Skip(256).Take(4).ToArray());
|
|
float temp23 = byteToFloat(info.Skip(264).Take(4).ToArray());
|
|
float temp24 = byteToFloat(info.Skip(280).Take(4).ToArray());
|
|
|
|
|
|
|
|
MoldTemperatureList.Add(temp1);
|
|
MoldTemperatureList.Add(temp3);
|
|
MoldTemperatureList.Add(temp5);
|
|
MoldTemperatureList.Add(temp7);
|
|
MoldTemperatureList.Add(temp9);
|
|
MoldTemperatureList.Add(temp11);
|
|
MoldTemperatureList.Add(temp13);
|
|
MoldTemperatureList.Add(temp15);
|
|
MoldTemperatureList.Add(temp17);
|
|
MoldTemperatureList.Add(temp19);
|
|
MoldTemperatureList.Add(temp21);
|
|
MoldTemperatureList.Add(temp23);
|
|
MoldTemperatureList.Add(temp2);
|
|
MoldTemperatureList.Add(temp4);
|
|
MoldTemperatureList.Add(temp6);
|
|
MoldTemperatureList.Add(temp8);
|
|
MoldTemperatureList.Add(temp10);
|
|
MoldTemperatureList.Add(temp12);
|
|
MoldTemperatureList.Add(temp14);
|
|
MoldTemperatureList.Add(temp16);
|
|
MoldTemperatureList.Add(temp18);
|
|
MoldTemperatureList.Add(temp20);
|
|
MoldTemperatureList.Add(temp22);
|
|
MoldTemperatureList.Add(temp24);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 生产节拍
|
|
/// </summary>
|
|
static void ReadProductionCycle(HwPLc.PlcModel obj, List<float> ProductionCycleList)
|
|
{
|
|
if (obj == null) return;
|
|
if (obj.plc.IsConnected)
|
|
{
|
|
|
|
byte[] info = obj.plc.Read("DB8.578", 52);
|
|
float temp1 = byteToFloat(info.Skip(0).Take(4).ToArray());
|
|
float temp2 = byteToFloat(info.Skip(4).Take(4).ToArray());
|
|
float temp3 = byteToFloat(info.Skip(8).Take(4).ToArray());
|
|
float temp4 = byteToFloat(info.Skip(12).Take(4).ToArray());
|
|
float temp5 = byteToFloat(info.Skip(16).Take(4).ToArray());
|
|
float temp6 = byteToFloat(info.Skip(20).Take(4).ToArray());
|
|
float temp7 = byteToFloat(info.Skip(24).Take(4).ToArray());
|
|
float temp8 = byteToFloat(info.Skip(28).Take(4).ToArray());
|
|
float temp9 = byteToFloat(info.Skip(32).Take(4).ToArray());
|
|
float temp10 = byteToFloat(info.Skip(36).Take(4).ToArray());
|
|
float temp11 = byteToFloat(info.Skip(40).Take(4).ToArray());
|
|
float temp12 = byteToFloat(info.Skip(44).Take(4).ToArray());
|
|
// 平均节拍
|
|
float temp13 = byteToFloat(info.Skip(48).Take(4).ToArray());
|
|
ProductionCycleList.Add(temp1);
|
|
ProductionCycleList.Add(temp2);
|
|
ProductionCycleList.Add(temp3);
|
|
ProductionCycleList.Add(temp4);
|
|
ProductionCycleList.Add(temp5);
|
|
ProductionCycleList.Add(temp6);
|
|
ProductionCycleList.Add(temp7);
|
|
ProductionCycleList.Add(temp8);
|
|
ProductionCycleList.Add(temp9);
|
|
ProductionCycleList.Add(temp10);
|
|
ProductionCycleList.Add(temp11);
|
|
ProductionCycleList.Add(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 字符工具转换方法
|
|
/// <summary>
|
|
/// byte数组转换为float
|
|
/// </summary>
|
|
static float byteToFloat(byte[] list)
|
|
{
|
|
float result = 0.00f;
|
|
Array.Reverse(list);
|
|
result = BitConverter.ToSingle(list, 0);
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|