You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
14 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Module.DB.Model;
using Module.Common;
namespace Module.Plc.Profinet.Tool
{
/// <summary>
/// 主页数据采集
/// </summary>
public class PlcHomeUtils
{
/// <summary>
/// 保留一位小数
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
private string FormatDataOne(double number)
{
return Math.Round(Convert.ToDecimal(number), 1).ToString("#0.0");
}
/// <summary>
/// 读取通道1中主页实时数值
/// </summary>
/// <returns></returns>
public HomeModel ReadT1HomeData()
{
try
{
HomeModel t1HomeModelInfo = null;
if (PublicParams.T1ConnectPlc)
{
t1HomeModelInfo = new HomeModel();
byte[] read_spots = PlcCommon.DeltaTcpNetClient01.Read("C8", 16).Content;
t1HomeModelInfo.f_glue_nums = ByteConvert.ToInt16(read_spots, 0);
t1HomeModelInfo.f_cot_spot = ByteConvert.ToInt16(read_spots, 8);
t1HomeModelInfo.f_hp1_spot = ByteConvert.ToInt16(read_spots, 10);
t1HomeModelInfo.f_hp2_spot = ByteConvert.ToInt16(read_spots, 12);
byte[] read_times = PlcCommon.DeltaTcpNetClient01.Read("D206", 64).Content;
t1HomeModelInfo.f_cot_time = FormatDataOne(ByteConvert.ToInt32(read_times, 0) * 1 / 10.0);
t1HomeModelInfo.f_hp1_time = FormatDataOne(ByteConvert.ToInt32(read_times, 16) * 1 / 10.0);
t1HomeModelInfo.f_hp2_time = FormatDataOne(ByteConvert.ToInt32(read_times, 36) * 1 / 10.0);
t1HomeModelInfo.f_cp_time = FormatDataOne(ByteConvert.ToInt32(read_times, 56) * 1 / 10.0);
bool[] bArm01s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1000.0", 3).Content;
if (bArm01s != null)
{
t1HomeModelInfo.f_arm01_ready = bArm01s[0];
t1HomeModelInfo.f_arm01_alarm = bArm01s[1];
t1HomeModelInfo.f_arm01_wafer = bArm01s[2];
}
bool[] bArm02s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1100.0", 3).Content;
t1HomeModelInfo.f_arm02_ready = bArm02s[0];
t1HomeModelInfo.f_arm02_alarm = bArm02s[1];
t1HomeModelInfo.f_arm02_wafer = bArm02s[2];
bool[] bArm03s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1200.0", 3).Content;
t1HomeModelInfo.f_arm03_ready = bArm03s[0];
t1HomeModelInfo.f_arm03_alarm = bArm03s[1];
t1HomeModelInfo.f_arm03_wafer = bArm03s[2];
bool[] bArm04s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1300.0", 3).Content;
t1HomeModelInfo.f_arm04_ready = bArm04s[0];
t1HomeModelInfo.f_arm04_alarm = bArm04s[1];
t1HomeModelInfo.f_arm04_wafer = bArm04s[2];
bool[] bArm05s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1400.0", 3).Content;
t1HomeModelInfo.f_arm05_ready = bArm05s[0];
t1HomeModelInfo.f_arm05_alarm = bArm05s[1];
t1HomeModelInfo.f_arm05_wafer = bArm05s[2];
bool[] bSends = PlcCommon.DeltaTcpNetClient01.ReadBool("D1500.0", 2).Content;
t1HomeModelInfo.f_send_ready = bSends[0];
t1HomeModelInfo.f_send_alarm = bSends[1];
t1HomeModelInfo.f_send_flower = PlcCommon.DeltaTcpNetClient01.ReadBool("D1508.4").Content;
t1HomeModelInfo.f_send_nums = PlcCommon.DeltaTcpNetClient01.ReadInt16("D1552").Content;
bool[] bReceiveFlowers = PlcCommon.DeltaTcpNetClient01.ReadBool("D1608.3", 2).Content;
t1HomeModelInfo.f_receive_flower_Finished = bReceiveFlowers[0];
t1HomeModelInfo.f_receive_flower = bReceiveFlowers[1];
t1HomeModelInfo.f_receive_ready = PlcCommon.DeltaTcpNetClient01.ReadBool("D1600.0").Content;
t1HomeModelInfo.f_receive_alarm = PlcCommon.DeltaTcpNetClient01.ReadBool("D1600.1").Content;
t1HomeModelInfo.f_receive_nums = PlcCommon.DeltaTcpNetClient01.ReadInt16("D1652").Content;
bool[] bCots = PlcCommon.DeltaTcpNetClient01.ReadBool("D1700.0", 3).Content;
t1HomeModelInfo.f_cot_ready = bCots[0];
t1HomeModelInfo.f_cot_alarm = bCots[1];
t1HomeModelInfo.f_cot_wafer = bCots[2];
bool[] bHp1s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1800.0", 3).Content;
t1HomeModelInfo.f_hp1_ready = bHp1s[0];
t1HomeModelInfo.f_hp1_alarm = bHp1s[1];
t1HomeModelInfo.f_hp1_wafer = bHp1s[2];
bool[] bHp2s = PlcCommon.DeltaTcpNetClient01.ReadBool("D1900.0", 3).Content;
t1HomeModelInfo.f_hp2_ready = bHp2s[0];
t1HomeModelInfo.f_hp2_alarm = bHp2s[1];
t1HomeModelInfo.f_hp2_wafer = bHp2s[2];
bool[] bCps = PlcCommon.DeltaTcpNetClient01.ReadBool("D2000.0", 3).Content;
t1HomeModelInfo.f_cp_ready = bCps[0];
t1HomeModelInfo.f_cp_alarm = bCps[1];
t1HomeModelInfo.f_cp_wafer = bCps[2];
byte[] read_nums = PlcCommon.DeltaTcpNetClient01.Read("D2800", 64).Content;
t1HomeModelInfo.f_prod_nums = PlcCommon.DeltaTcpNetClient01.ReadUInt16("C9").Content;
t1HomeModelInfo.f_glue_num = ByteConvert.ToInt16(read_nums, 52);
t1HomeModelInfo.f_no_start_alarm= PlcCommon.DeltaTcpNetClient01.ReadBool("D999.5").Content;
}
return t1HomeModelInfo;
}
catch (Exception ex)
{
ex.ToString();
return null;
}
}
/// <summary>
/// 读取通道2中主页实时数值
/// </summary>
/// <returns></returns>
public HomeModel ReadT2HomeData()
{
try
{
HomeModel t2HomeModelInfo = null;
if (PublicParams.T2ConnectPlc)
{
t2HomeModelInfo = new HomeModel();
t2HomeModelInfo.f_glue_nums = PlcCommon.DeltaTcpNetClient02.ReadUInt16("C8").Content;
t2HomeModelInfo.f_prod_nums = PlcCommon.DeltaTcpNetClient02.ReadUInt16("C9").Content;
t2HomeModelInfo.f_cot_spot = PlcCommon.DeltaTcpNetClient02.ReadUInt16("C12").Content;
t2HomeModelInfo.f_hp1_spot = PlcCommon.DeltaTcpNetClient02.ReadUInt16("C13").Content;
t2HomeModelInfo.f_hp2_spot = PlcCommon.DeltaTcpNetClient02.ReadUInt16("C14").Content;
t2HomeModelInfo.f_send_flower = PlcCommon.DeltaTcpNetClient02.ReadBool("D1508.4").Content;
t2HomeModelInfo.f_send_nums = PlcCommon.DeltaTcpNetClient02.ReadUInt16("D1552").Content;
t2HomeModelInfo.f_receive_flower_Finished = PlcCommon.DeltaTcpNetClient02.ReadBool("D1608.3").Content;
t2HomeModelInfo.f_receive_flower = PlcCommon.DeltaTcpNetClient02.ReadBool("D1608.4").Content;
t2HomeModelInfo.f_receive_nums = PlcCommon.DeltaTcpNetClient02.ReadUInt16("D1652").Content;
t2HomeModelInfo.f_glue_num = PlcCommon.DeltaTcpNetClient02.ReadInt16("D2826").Content;
t2HomeModelInfo.f_cot_time = FormatDataOne(PlcCommon.DeltaTcpNetClient02.ReadInt32("D206").Content * 1 / 10.0);
t2HomeModelInfo.f_hp1_time = FormatDataOne(PlcCommon.DeltaTcpNetClient02.ReadInt32("D214").Content * 1 / 10.0);
t2HomeModelInfo.f_hp2_time = FormatDataOne(PlcCommon.DeltaTcpNetClient02.ReadInt32("D224").Content * 1 / 10.0);
t2HomeModelInfo.f_cp_time = FormatDataOne(PlcCommon.DeltaTcpNetClient02.ReadInt32("D234").Content * 1 / 10.0);
t2HomeModelInfo.f_send_ready = PlcCommon.DeltaTcpNetClient02.ReadBool("D1500.0").Content;
t2HomeModelInfo.f_send_alarm = PlcCommon.DeltaTcpNetClient02.ReadBool("D1500.1").Content;
bool[] bArm01s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1000.0", 3).Content;
if (bArm01s != null)
{
t2HomeModelInfo.f_arm01_ready = bArm01s[0];
t2HomeModelInfo.f_arm01_alarm = bArm01s[1];
t2HomeModelInfo.f_arm01_wafer = bArm01s[2];
}
bool[] bArm02s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1100.0", 3).Content;
t2HomeModelInfo.f_arm02_ready = bArm02s[0];
t2HomeModelInfo.f_arm02_alarm = bArm02s[1];
t2HomeModelInfo.f_arm02_wafer = bArm02s[2];
bool[] bArm03s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1200.0", 3).Content;
t2HomeModelInfo.f_arm03_ready = bArm03s[0];
t2HomeModelInfo.f_arm03_alarm = bArm03s[1];
t2HomeModelInfo.f_arm03_wafer = bArm03s[2];
bool[] bArm04s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1300.0", 3).Content;
t2HomeModelInfo.f_arm04_ready = bArm04s[0];
t2HomeModelInfo.f_arm04_alarm = bArm04s[1];
t2HomeModelInfo.f_arm04_wafer = bArm04s[2];
bool[] bArm05s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1400.0", 3).Content;
t2HomeModelInfo.f_arm05_ready = bArm05s[0];
t2HomeModelInfo.f_arm05_alarm = bArm05s[1];
t2HomeModelInfo.f_arm05_wafer = bArm05s[2];
bool[] bCots = PlcCommon.DeltaTcpNetClient02.ReadBool("D1700.0", 3).Content;
t2HomeModelInfo.f_cot_ready = bCots[0];
t2HomeModelInfo.f_cot_alarm = bCots[1];
t2HomeModelInfo.f_cot_wafer = bCots[2];
bool[] bHp1s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1800.0", 3).Content;
t2HomeModelInfo.f_hp1_ready = bHp1s[0];
t2HomeModelInfo.f_hp1_alarm = bHp1s[1];
t2HomeModelInfo.f_hp1_wafer = bHp1s[2];
bool[] bHp2s = PlcCommon.DeltaTcpNetClient02.ReadBool("D1900.0", 3).Content;
t2HomeModelInfo.f_hp2_ready = bHp2s[0];
t2HomeModelInfo.f_hp2_alarm = bHp2s[1];
t2HomeModelInfo.f_hp2_wafer = bHp2s[2];
bool[] bCps = PlcCommon.DeltaTcpNetClient02.ReadBool("D2000.0", 3).Content;
t2HomeModelInfo.f_cp_ready = bCps[0];
t2HomeModelInfo.f_cp_alarm = bCps[1];
t2HomeModelInfo.f_cp_wafer = bCps[2];
t2HomeModelInfo.f_receive_ready = PlcCommon.DeltaTcpNetClient02.ReadBool("D1600.0").Content;
t2HomeModelInfo.f_receive_alarm = PlcCommon.DeltaTcpNetClient02.ReadBool("D1600.1").Content;
}
return t2HomeModelInfo;
}
catch (Exception ex)
{
ex.ToString();
return null;
}
}
#region 主页需要展示的信息
/// <summary>
/// 展示的通道1匀胶参数信息
/// </summary>
/// <returns></returns>
public MCotModelInfo ReadT1PrintCotModel()
{
try
{
MCotModelInfo cotModelResult = null;
if (PublicParams.T1ConnectPlc)
{
HslCommunication.OperateResult<byte[]> dResult = PlcCommon.DeltaTcpNetClient01.Read("D1750", 8);
if (dResult.IsSuccess)
{
cotModelResult = new MCotModelInfo();
cotModelResult.spindleCurrSpeed = ByteConvert.ToInt32(dResult.Content, 0).ToString("0.0");
cotModelResult.glueArmCurrPosition = Math.Round(Convert.ToDecimal(ByteConvert.ToInt32(dResult.Content, 4) * 0.6 / 100.00), 2).ToString("#0.00");
}
}
return cotModelResult;
}
catch (Exception ex)
{
ex.ToString();
return null;
}
}
/// <summary>
/// 展示的通道2匀胶参数信息
/// </summary>
/// <returns></returns>
public MCotModelInfo ReadT2PrintCotModel()
{
try
{
MCotModelInfo cotModelResult = null;
if (PublicParams.T2ConnectPlc)
{
HslCommunication.OperateResult<byte[]> dResult = PlcCommon.DeltaTcpNetClient02.Read("D1750", 8);
if (dResult.IsSuccess)
{
cotModelResult = new MCotModelInfo();
cotModelResult.spindleCurrSpeed = ByteConvert.ToInt32(dResult.Content, 0).ToString("0.0");
cotModelResult.glueArmCurrPosition = Math.Round(Convert.ToDecimal(ByteConvert.ToInt32(dResult.Content, 4) * 0.6 / 100.00), 2).ToString("#0.00");
}
}
return cotModelResult;
}
catch (Exception ex)
{
ex.ToString();
return null;
}
}
#endregion 主页需要展示的信息
}
}