using BPASmartClient.Helper;
using BPASmartClient.Modbus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPASmartClient.S7Net;
using BPASmartClient.CustomResource.Pages.Model;
using System.Threading;
namespace BPASmartClient.JXJFoodSmallStation.Model.HK_PLC
{
public class HKDeviceStatus
{
public SiemensHelper HK_PLC_S7 = new SiemensHelper();
public bool IsConnected => HK_PLC_S7.IsConnected;
public void Init()
{
if (IsConnected)
{
/*ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (!IsConnected)
{
MessageLog.GetInstance.ShowRunLog("海科PLC断开连接");
}
Thread.Sleep(10);
}),"信号收发处理");*/
}
}
///
/// 单个配料机配料完成
///
///
public void SingleDosing(uint value)
{
if (IsConnected)
{
HK_PLC_S7.Write(HKPlcCommAddress.SingleStockBinLocationToPLC, value);
HK_PLC_S7.Write(HKPlcCommAddress.SingleDosingFinishToPLC, (ushort)1);
}
}
///
/// 复位plc允许接料信号
///
public void AllowDosingSignReset()
{
HK_PLC_S7.Write(HKPlcCommAddress.IsAllowDosing,(ushort)0);
}
///
/// 复位plc到达某料仓信号
///
public void StockStateSignReset()
{
HK_PLC_S7.Write(HKPlcCommAddress.StockState, (ushort)0);
}
///
/// 复位一个配方配料完成信号
///
public void RecipeDosingFinishReset()
{
HK_PLC_S7.Write(HKPlcCommAddress.RecipeDosingFinish, (ushort)0);
}
///
/// 下发配方数据
///
/// 单个桶的编号
/// 单个桶对应的料仓位置
public void StockBinPar(uint BarrelNum, ushort StockBinLocation, int TrayNum = 1)
{
if (IsConnected)
{
if (TrayNum == 1)
{
if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
{
if (BarrelNum == 1)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX10." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX11." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘1—1号桶在料仓{StockBinLocation}配料");
}
else if (BarrelNum == 2)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX12." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX13." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘1—2号桶在料仓{StockBinLocation}配料");
}
else if (BarrelNum == 3)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX14." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX15." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘1—3号桶在料仓{StockBinLocation}配料");
}
else if (BarrelNum == 4)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX16." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX17." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘1—4号桶在料仓{StockBinLocation}配料");
}
}
}
else if (TrayNum == 2)
{
if (BarrelNum >= 1 && BarrelNum <= 4 && StockBinLocation >= 1 && StockBinLocation <= 15)
{
if (BarrelNum == 1)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX18." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX19." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘2—1号桶在料仓{StockBinLocation}配料");
}
else if (BarrelNum == 2)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX20." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX21." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘2—2号桶在料仓{StockBinLocation}配料");
}
else if (BarrelNum == 3)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX22." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX23." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘2—3号桶在料仓{StockBinLocation}配料");
}
else if (BarrelNum == 4)
{
if (StockBinLocation >= 1 && StockBinLocation <= 8)
{
HK_PLC_S7.Write("DB4.DBX24." + (StockBinLocation - 1), true);
}
else if (StockBinLocation >= 9 && StockBinLocation <= 15)
{
HK_PLC_S7.Write("DB4.DBX25." + (StockBinLocation - 9), true);
}
MessageNotify.GetInstance.ShowRunLog($"托盘2—4号桶在料仓{StockBinLocation}配料");
}
}
}
}
}
}
}