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;
namespace BPASmartClient.JXJFoodBigStation.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(() =>
{
}),"信号收发处理");
}
}
///
/// 下发配方数据
///
public void StockBinPar(RecipeData recipe)
{
if (IsConnected)
{
if (recipe != null)
{
for (int barrel = 1; barrel < 6; barrel++)
{
for (int loc = 1; loc < 13; loc++)
{
int index = Array.FindIndex(recipe.RawMaterial.ToArray(), p => p.RawMaterialBarrelNum == barrel && p.RawMaterialLocation == loc);
if (barrel >= 3)//PLC没有3号桶的重量位置,故4,5号桶地址向前偏移48个位置
{
if (index != -1)
{
HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48, recipe.RawMaterial.ElementAt(index).RawMaterialWeight);
}
else//不存在的原料信息,重量写0
{
HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1 - 1) * 48, 0);
}
}
else
{
if (index != -1)
{
HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1) * 48, recipe.RawMaterial.ElementAt(index).RawMaterialWeight);
}
else//不存在的原料信息,重量写0
{
HK_PLC_S7.Write("MD" + 4120 + (loc - 1) * 4 + (barrel - 1) * 48, 0);
}
}
}
}
}
}
}
}
}