using HslCommunication;
using HslCommunication.Profinet.Delta;
using Module.Common;
using Module.DB.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Module.Plc.Profinet.Tool
{
public class PlcArmRecipeFunc
{
static OperateResult connect = null;
///
/// 胶臂配方下发
///
///
public static bool ArmRecipeToPlc(List rpArmInfoList)
{
bool result = false;
if (rpArmInfoList != null)
{
int armCount = rpArmInfoList.Count;
if (armCount > 0)
{
int addrRpArm = 260;
int addrLoc1 = 500;
int addrLoc2 = 502;
int addrSpeed = 504;
int addrInjectGlueNum = 506;
int addrHeadPressDown = 508;
for (int i = 0; i < armCount; i++)
{
connect = PlcCommon.DeltaTcpNetClient01.Write("D" + (addrRpArm + i * 10), (short)rpArmInfoList[i].f_arm_plc_no);
connect = PlcCommon.DeltaTcpNetClient01.Write("D" + (addrLoc1 + i * 10), Convert.ToInt32(rpArmInfoList[i].f_loc01 * 100));
connect = PlcCommon.DeltaTcpNetClient01.Write("D" + (addrLoc2 + i * 10), Convert.ToInt32(rpArmInfoList[i].f_loc02 * 100));
connect = PlcCommon.DeltaTcpNetClient01.Write("D" + (addrSpeed + i * 10), Convert.ToInt32(rpArmInfoList[i].f_speed * 10));
connect = PlcCommon.DeltaTcpNetClient01.Write("D" + (addrInjectGlueNum + i * 10), (short)rpArmInfoList[i].f_inject_glue_num);
short value = PlcCommon.DeltaTcpNetClient01.ReadInt16("D" + (addrHeadPressDown + i * 10)).Content;
char[] chResults = BitConvert.ToFullBinaryChars(value);
chResults[15] = Convert.ToChar(rpArmInfoList[i].f_head_press_down + '0');
// 涂胶
if (rpArmInfoList[i].f_coating == 1)
{
chResults[14] = '1';
}
connect = PlcCommon.DeltaTcpNetClient01.Write("D" + (addrHeadPressDown + i * 10), BitConvert.CharsToShort(chResults));
}
}
}
if (connect.IsSuccess)
{
result = true;
}
else
{
result = false;
}
return result;
}
///
/// 通道胶臂配方下发
///
/// 通道号。1:通道1;2:通道2
/// 胶臂信息列表
///
public static bool ArmRecipeToPlc(int trackNo,List rpArmInfoList)
{
bool result = false;
DeltaTcpNet client = null;
if (trackNo == 1)
{
client = PlcCommon.DeltaTcpNetClient01;
}
else if (trackNo == 2)
{
client = PlcCommon.DeltaTcpNetClient02;
}
if (client != null)
{
if (rpArmInfoList != null)
{
int armCount = rpArmInfoList.Count;
if (armCount > 0)
{
//int addrRpArm = 260;
int addrLoc1 = 500;
int addrLoc2 = 502;
int addrSpeed = 504;
int addrInjectGlueNum = 506;
int addrHeadPressDown = 508;
for (int i = 0; i < armCount; i++)
{
//OperateResult connect01 = client.Write("D" + (addrRpArm + i * 10), (short)rpArmInfoList[i].f_arm_plc_no);
OperateResult connect02 = client.Write("D" + (addrLoc1 + i * 10), Convert.ToInt32(Convert.ToDouble(rpArmInfoList[i].f_loc01 * 100) / 0.6));
OperateResult connect03 = client.Write("D" + (addrLoc2 + i * 10), Convert.ToInt32(rpArmInfoList[i].f_loc02 * 100));
OperateResult connect04 = client.Write("D" + (addrSpeed + i * 10), Convert.ToInt32(rpArmInfoList[i].f_speed));
OperateResult connect05 = client.Write("D" + (addrInjectGlueNum + i * 10), (short)rpArmInfoList[i].f_inject_glue_num);
short value = client.ReadInt16("D" + (addrHeadPressDown + i * 10)).Content;
char[] chResults = BitConvert.ToFullBinaryChars(value);
chResults[15] = Convert.ToChar(rpArmInfoList[i].f_head_press_down + '0');
// 涂胶
if (rpArmInfoList[i].f_coating == 1)
{
chResults[14] = '1';
}
OperateResult connect06 = client.Write("D" + (addrHeadPressDown + i * 10), BitConvert.CharsToShort(chResults));
result = /*connect01.IsSuccess &&*/ connect02.IsSuccess && connect03.IsSuccess && connect04.IsSuccess && connect05.IsSuccess && connect06.IsSuccess;
}
}
}
}
return result;
}
}
}