using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Helper;
using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC;
using BPASmartClient.JXJFoodSmallStation.Model.Siemens;
using BPASmartClient.JXJFoodSmallStation.Model.WindSend;
using BPASmartClient.Modbus;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BPASmartClient.JXJFoodSmallStation.Model
{
public class ProcessControl
{
private volatile static ProcessControl _Instance;
public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
private ProcessControl() { }
///
/// 配方数据
///
public ObservableCollection RemoteRecipes = new ObservableCollection();
///
/// 原料的名称和料仓的位置对应
///
public Dictionary RawMaterialsNamePos = new Dictionary();
///
/// 配方队列
///
public ConcurrentQueue RecipeQueue = new ConcurrentQueue();
public ConcurrentQueue RecipeQueueTray2 = new ConcurrentQueue();
public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
public HKDeviceStatus HKDevice = new HKDeviceStatus();
public WindSendDeviceStatus WindSendDevice = new WindSendDeviceStatus();
XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
XL_WindSendData_DB WindSendData = new XL_WindSendData_DB();
///
/// 接收原料数据
///
public RecipeRawMaterial RawMaterial;
public void Init()
{
for (int i = 0; i < 16; i++)
{
if (DeviceInquire.GetInstance.GetDevice(i).DeviceName != null)
{
if (!RawMaterialsNamePos.ContainsKey(DeviceInquire.GetInstance.GetDevice(i).DeviceName))
{
RawMaterialsNamePos.Add(DeviceInquire.GetInstance.GetDevice(i).DeviceName, (short)DeviceInquire.GetInstance.GetDevice(i).deviceStatus.DeviceNum);
}
}
}
ActionManage.GetInstance.CancelRegister("SiemensRecipeRecive");
ActionManage.GetInstance.Register(new Action((res) =>
{
ObservableCollection RawMaterials = new ObservableCollection();
if (SiemensDevice.IsConnected)
{
if (res != null && res is XL_Start_DB recipe)
{
RawMaterials.Clear();
for (int i = 0; i < 15; i++)
{
if (RawMaterialsNamePos.ContainsKey(recipe.Material[i].Material_Name))
{
RawMaterials.Add(new RemoteRecipeRawMaterial()
{
RawMaterialName = recipe.Material[i].Material_Name,
RawMaterialBarrelNum = recipe.Material[i].Material_BarrelNum,
RawMaterialWeight = recipe.Material[i].Material_Weight,
RawMaterialLocation = (int)RawMaterialsNamePos[recipe.Material[i].Material_Name]
});
}
else
{
MessageLog.GetInstance.AlarmLog("配方名称与本地不符合");
}
}
Json.Data.Recipes.Add(new RemoteRecipeData()
{
RecipeName = recipe.RecipeName,
RecipeCode = recipe.RecipeCode,
RawMaterial = RawMaterials,
TrayCode = recipe.TrayCode
});
}
}
}), "SiemensRecipeRecive", true);
ActionManage.GetInstance.CancelRegister("WindSendDosingFinish");
ActionManage.GetInstance.Register(new Action(() =>
{
GVL_SmallStation.GetInstance.WindSendDosingFinish = true;
}),"WindSendDosingFinish",true);
ActionManage.GetInstance.CancelRegister("LocalSimulationRecipeIssue");
ActionManage.GetInstance.Register(new Action((res) =>
{
if (res != null && res is RemoteRecipeData recipe)
{
Json.Data.Recipes.Add(recipe);
}
}), "LocalSimulationRecipeIssue", true);
string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
string WindSend_PLC_IP = ConfigurationManager.AppSettings["WindSend_IP"];
try
{
//HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
//SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
//WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200,WindSend_PLC_IP);
if (HKDevice.IsConnected)
{
HKDevice.Init();
MessageLog.GetInstance.ShowUserLog("海科plc连接成功,并初始化完成");
}
if (SiemensDevice.IsConnected)
{
SiemensDevice.Init();
MessageLog.GetInstance.ShowUserLog("西门子plc连接成功,并初始化完成");
}
if (WindSendDevice.IsConnected)
{
WindSendDevice.Init();
MessageLog.GetInstance.ShowUserLog("风送plc连接成功,并初始化完成");
}
}
catch(Exception ex)
{
}
RecipeQueue.Clear();
//Json.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
ThreadManage.GetInstance().StartLong(new Action(() =>
{
ReceviceData();
RecipeInfoToHKPLC();
Thread.Sleep(10);
}), "西门子配发下发流程处理", true);
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (SiemensDevice.IsConnected && HKDevice.IsConnected)
{
/*AgvGetInDelivery();
AgvGetInPickUp();*/
}
Thread.Sleep(10);
}), "AGV进站送取货", true);
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (HKDevice.IsConnected)
{
GetStatus();
ManualOpen();
ManualClose();
}
Thread.Sleep(10);
}), "手动操作", true);
}
private void GetStatus()
{
for (int i = 0; i < 8; i++)
{
GVL_SmallStation.GetInstance.Cylinder_JackInfo[i] = HKDevice.HK_PLC_S7.Read("DB5.DBX0." + i);
}
for (int i = 0; i < 7; i++)
{
GVL_SmallStation.GetInstance.Cylinder_JackInfo[i + 8] = HKDevice.HK_PLC_S7.Read("DB5.DBX0." + i);
}
ActionManage.GetInstance.Register(new Action(() =>
{
HKDevice.HK_PLC_S7.Write("M10.0", true);
}), "ManualEStop", true);
ActionManage.GetInstance.Register(new Action(() =>
{
HKDevice.HK_PLC_S7.Write("M10.0", false);
}), "ManualEReset", true);
}
private void ManualOpen()
{
ActionManage.GetInstance.Register(new Action((o) =>
{
if (o != null)
{
if (o.ToString().Contains("升降气缸"))
{
int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
switch (index)
{
case 1:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.0", true);
break;
case 2:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.1", true);
break;
case 3:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.2", true);
break;
case 4:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.3", true);
break;
case 5:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.4", true);
break;
case 6:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.5", true);
break;
case 7:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.6", true);
break;
case 8:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.7", true);
break;
case 9:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.0", true);
break;
case 10:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.1", true);
break;
case 11:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.2", true);
break;
case 12:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.3", true);
break;
case 13:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.4", true);
break;
case 14:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.5", true);
break;
case 15:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.6", true);
break;
default:
break;
}
}
else if (o.ToString().Contains("阻挡气缸"))
{
int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
switch (index)
{
case 1:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.7", true);
break;
case 2:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.0", true);
break;
case 3:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.1", true);
break;
case 4:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.2", true);
break;
case 5:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.3", true);
break;
case 6:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.4", true);
break;
case 7:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.5", true);
break;
case 8:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.6", true);
break;
case 9:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.7", true);
break;
case 10:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.0", true);
break;
case 11:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.1", true);
break;
case 12:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.2", true);
break;
case 13:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.3", true);
break;
case 14:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.4", true);
break;
case 15:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.5", true);
break;
default:
break;
}
}
else if (o.ToString().Contains("进料桶顶升气缸"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", true);
}
else if (o.ToString().Contains("出料桶顶升气缸1"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", true);
}
else if (o.ToString().Contains("出料桶顶升气缸2"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", true);
}
else if (o.ToString().Contains("出料桶顶升气缸3"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", true);
}
else if (o.ToString().Contains("托盘气缸1_1"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", true);
}
else if (o.ToString().Contains("托盘气缸1_2"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", true);
}
else if (o.ToString().Contains("托盘气缸2_1"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", true);
}
else if (o.ToString().Contains("托盘气缸2_2"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", true);
}
}
}), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
}
private void ManualClose()
{
ActionManage.GetInstance.Register(new Action((o) =>
{
if (o != null)
{
if (o.ToString().Contains("升降气缸"))
{
int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
switch (index)
{
case 1:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.0", false);
break;
case 2:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.1", false);
break;
case 3:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.2", false);
break;
case 4:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.3", false);
break;
case 5:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.4", false);
break;
case 6:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.5", false);
break;
case 7:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.6", false);
break;
case 8:
HKDevice.HK_PLC_S7.Write("DB5.DBX0.7", false);
break;
case 9:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.0", false);
break;
case 10:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.1", false);
break;
case 11:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.2", false);
break;
case 12:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.3", false);
break;
case 13:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.4", false);
break;
case 14:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.5", false);
break;
case 15:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.6", false);
break;
default:
break;
}
}
else if (o.ToString().Contains("阻挡气缸"))
{
int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 1));
switch (index)
{
case 1:
HKDevice.HK_PLC_S7.Write("DB5.DBX1.7", false);
break;
case 2:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.0", false);
break;
case 3:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.1", false);
break;
case 4:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.2", false);
break;
case 5:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.3", false);
break;
case 6:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.4", false);
break;
case 7:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.5", false);
break;
case 8:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.6", false);
break;
case 9:
HKDevice.HK_PLC_S7.Write("DB5.DBX2.7", false);
break;
case 10:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.0", false);
break;
case 11:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.1", false);
break;
case 12:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.2", false);
break;
case 13:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.3", false);
break;
case 14:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.4", false);
break;
case 15:
HKDevice.HK_PLC_S7.Write("DB5.DBX3.5", false);
break;
default:
break;
}
}
else if (o.ToString().Contains("进料桶顶升气缸"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", false);
}
else if (o.ToString().Contains("出料桶顶升气缸1"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", false);
}
else if (o.ToString().Contains("出料桶顶升气缸2"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", false);
}
else if (o.ToString().Contains("出料桶顶升气缸3"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", false);
}
else if (o.ToString().Contains("托盘气缸1_1"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.2", false);
}
else if (o.ToString().Contains("托盘气缸1_2"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.3", false);
}
else if (o.ToString().Contains("托盘气缸2_1"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.4", false);
}
else if (o.ToString().Contains("托盘气缸2_2"))
{
HKDevice.HK_PLC_S7.Write("DB5.DBX4.5", false);
}
}
}), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
}
///
/// AGV进站送货
///
private void AgvGetInDelivery()
{
switch (GVL_SmallStation.GetInstance.AgvDeliveryPosition)
{
case 0:
if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApply) is bool))
{
GVL_SmallStation.GetInstance.AgvDeliveryPosition = 1;
HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApply, true);
}
break;
case 1:
if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApply)))
{
GVL_SmallStation.GetInstance.AgvDeliveryPosition = 2;
SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApply, true);
}
break;
case 2:
if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApplyJack) is bool))
{
GVL_SmallStation.GetInstance.AgvDeliveryPosition = 3;
HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApplyJack, true);
}
break;
case 3:
if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApplyJack)))
{
GVL_SmallStation.GetInstance.AgvDeliveryPosition = 4;
SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApplyJack, true);
}
break;
case 4:
if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVFinsih) is bool))
{
GVL_SmallStation.GetInstance.AgvDeliveryPosition = 5;
HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVFinsih, true);
}
break;
case 5:
if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationHaveCargo)))
{
GVL_SmallStation.GetInstance.AgvDeliveryPosition = 0;
SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationHaveCargo, true);
}
break;
default:
break;
}
//获取工位上是否有小车
SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationIsExistTray));
}
///
/// AGV进站取货
///
private void AgvGetInPickUp()
{
switch (GVL_SmallStation.GetInstance.AgvPickUpPosition)
{
case 0:
if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickAGVApply)))
{
GVL_SmallStation.GetInstance.AgvPickUpPosition = 1;
HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickAGVApply, true);
}
break;
case 1:
if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVIsApply)))
{
GVL_SmallStation.GetInstance.AgvPickUpPosition = 2;
SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVIsApply, true);
}
break;
case 2:
if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickCargoAGVFinish)))
{
GVL_SmallStation.GetInstance.AgvPickUpPosition = 3;
HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickCargoAGVFinish, true);
}
break;
case 3:
if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVFinish)))
{
GVL_SmallStation.GetInstance.AgvPickUpPosition = 0;
SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVFinish, true);
}
break;
default:
break;
}
}
///
/// 将配方添加到配方队列中
///
private void ReceviceData()
{
RemoteRecipes = Json.Data.Recipes;
if (RemoteRecipes.Count > 0)
{
foreach (var data in RemoteRecipes)
{
if (data.TrayCode == 1)
{
if (!(RecipeQueue.Contains(data.RecipeCode)))
{
RecipeQueue.Enqueue(data.RecipeCode);
}
}
else if(data.TrayCode == 2)
{
if (!(RecipeQueueTray2.Contains(data.RecipeCode)))
{
RecipeQueueTray2.Enqueue(data.RecipeCode);
}
}
}
}
else
{
RecipeQueue.Clear();
RecipeQueueTray2.Clear();
GVL_SmallStation.GetInstance.RecipeStatusID = 0;
GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
}
}
///
/// 执行配方队列中的第一个配方
///
private void RecipeInfoToHKPLC()
{
if (RecipeQueue.Count > 0)
{
int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueue.ElementAt(0));
if (index >= 0 && index < RemoteRecipes.Count)
{
string code = RemoteRecipes.ElementAt(index).RecipeCode;
int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
string windSend = RemoteRecipes.ElementAt(index).ToString();
if (trayCode == 1)
{
if (GVL_SmallStation.GetInstance.RecipeStatusID == 0)
{
if (GVL_SmallStation.GetInstance.IsUseWindSend)
{
GVL_SmallStation.GetInstance.IsUseWindSend = false;
WindSendData.TargetRecipeCode = code;
if (RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(0).RawMaterialName == DeviceName.原料1.ToString())
{
WindSendData.RawMaterial1_SetWeight = RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(0).RawMaterialWeight;
}
if (RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(1).RawMaterialName == DeviceName.原料2.ToString())
{
WindSendData.RawMaterial2_SetWeight = RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(1).RawMaterialWeight;
}
if (RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(2).RawMaterialName == DeviceName.原料3.ToString())
{
WindSendData.RawMaterial3_SetWeight = RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(2).RawMaterialWeight;
}
if (RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(3).RawMaterialName == DeviceName.原料4.ToString())
{
WindSendData.RawMaterial4_SetWeight = RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(3).RawMaterialWeight;
}
if (RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(4).RawMaterialName == DeviceName.原料5.ToString())
{
WindSendData.RawMaterial5_SetWeight = RemoteRecipes.ElementAt(index).WindSendRawMaterial.ElementAt(4).RawMaterialWeight;
}
WindSendDevice.Siemens_PLC_S7.WriteClass(WindSendData, 5);
}
foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
{
HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
}
HKDevice.HK_PLC_S7.Write("DB4.DBX1.3", true);
GVL_SmallStation.GetInstance.RecipeStatusID = 1;
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},下发完成");
HKDevice.HK_PLC_S7.Write("DB3.DBX1.3", true);
}
if (HKDevice.HK_PLC_S7.Read("DB3.DBX1.3") && GVL_SmallStation.GetInstance.RecipeStatusID == 1)
{
HKDevice.HK_PLC_S7.Write("DB3.DBX1.3", false);
GVL_SmallStation.GetInstance.RecipeStatusID = 2;
MessageLog.GetInstance.ShowRunLog($"托盘1,{ recipeName}plc端 配方接收完成");
}
if (GVL_SmallStation.GetInstance.RecipeStatusID == 2)
{
if (RTrig.GetInstance("DB3.DBX50.0").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.0")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD10");
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false);
}
GVL_SmallStation.GetInstance.DosingTray1 = true;
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
}
}
else if(RTrig.GetInstance("DB3.DBX50.1").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.1")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD14");
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.1", false);
}
GVL_SmallStation.GetInstance.DosingTray1 = true;
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
}
}
else if (RTrig.GetInstance("DB3.DBX50.2").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.2")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD18");
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.2", false);
}
GVL_SmallStation.GetInstance.DosingTray1 = true;
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
}
}
else if (RTrig.GetInstance("DB3.DBX50.3").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.3")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD22");
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.3", false);
}
GVL_SmallStation.GetInstance.DosingTray1 = true;
MessageLog.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
}
}
if (GVL_SmallStation.GetInstance.DosingTray1)
{
for (int i = 1; i < 16; i++)
{
if (RTrig.GetInstance("GetDeviceRunStatus").Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
{
MessageLog.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,配料完成");
int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback;
DeviceInquire.GetInstance.GetDevice(i).StatusReset();
if (i >= 1 && i <= 8)
{
HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true);
}
else if (i >= 9 && i <= 15)
{
HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true);
}
GVL_SmallStation.GetInstance.DosingTray1 = false;
}
}
}
if (RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX1.1")) && (GVL_SmallStation.GetInstance.WindSendDosingFinish || !GVL_SmallStation.GetInstance.IsUseWindSend))
{
var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
MessageLog.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成");
RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
{
RecipeFinishInfo.Material[i] = new UDT1();
RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight;
}
if (SiemensDevice.IsConnected)
{
RecipeFinishInfo.Ask_For_Finish = true;
SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 3);
}
App.Current.Dispatcher.Invoke(() =>
{
Json.Data.Recipes.Remove(res);
});
RecipeQueue.TryDequeue(out code);
HKDevice.HK_PLC_S7.Write("DB3.DBX1.1", false);
GVL_SmallStation.GetInstance.RecipeStatusID = 0;
}
}
}
}
}
if (RecipeQueueTray2.Count > 0)
{
int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueueTray2.ElementAt(0));
if (index >= 0 && index < RemoteRecipes.Count)
{
string code = RemoteRecipes.ElementAt(index).RecipeCode;
int trayCode = RemoteRecipes.ElementAt(index).TrayCode;
string recipeName = RemoteRecipes.ElementAt(index).RecipeName;
if (trayCode == 2)
{
if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 0)
{
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},初始化");
foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
{
HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation, 2);
}
HKDevice.HK_PLC_S7.Write("DB4.DBX1.4", true);
GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 1;
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},下发完成");
HKDevice.HK_PLC_S7.Write("DB3.DBX1.4", true);
}
if (HKDevice.HK_PLC_S7.Read("DB3.DBX1.4") && GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 1)
{
HKDevice.HK_PLC_S7.Write("DB3.DBX1.4", false);
GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 2;
MessageLog.GetInstance.ShowRunLog($"配方:{recipeName},plc端 配方接收完成");
}
if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 2)
{
if (RTrig.GetInstance("DB3.DBX50.4").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.4")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD26");
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
//int decimalNum = Convert.ToInt32(loc.ToString().Substring(loc.ToString().IndexOf(".") + 1));
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//根据料仓编号 启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.0", false);
}
GVL_SmallStation.GetInstance.DosingTray2 = true;
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
}
}
else if (RTrig.GetInstance("DB3.DBX50.5").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.5")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD30");
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.5", false);
}
GVL_SmallStation.GetInstance.DosingTray2 = true;
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
}
}
else if (RTrig.GetInstance("DB3.DBX50.6").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.6")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD34");
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.6", false);
}
GVL_SmallStation.GetInstance.DosingTray2 = true;
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
}
}
else if (RTrig.GetInstance("DB3.DBX50.7").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX50.7")))
{
var res = HKDevice.HK_PLC_S7.Read("DB3.DBD38");
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{res}料仓,允许配料");
if (res > 0 && res is float loc)
{
int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == loc);
double weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight;
if (loc_index >= 0)
{
DeviceInquire.GetInstance.GetDevice((int)loc)?.Start((uint)weight);//启动并写入每个原料重量
GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
//HKDevice.HK_PLC_S7.Write("DB3.DBX50.7", false);
}
GVL_SmallStation.GetInstance.DosingTray2 = true;
MessageLog.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
}
}
if (GVL_SmallStation.GetInstance.DosingTray2 == true)
{
for (int i = 1; i < 16; i++)
{
if (RTrig.GetInstance("柔性味魔方配料完成").Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
{
MessageLog.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{recipeName},{i}号仓,配料完成");
int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(i).deviceStatus.CutWeightFeedback;
DeviceInquire.GetInstance.GetDevice(i).StatusReset();
if (i >= 1 && i <= 8)
{
HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true);
}
else if (i >= 9 && i <= 15)
{
HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true);
}
GVL_SmallStation.GetInstance.DosingTray2 = false;
}
}
}
if (RTrig.GetInstance("DB3.DBX1.2").Start(HKDevice.HK_PLC_S7.Read("DB3.DBX1.2")))
{
var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
MessageLog.GetInstance.ShowRunLog($"托盘2配方{res.RecipeName}配料完成");
RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
{
RecipeFinishInfo.Material[i] = new UDT1();
RecipeFinishInfo.Material[i].Material_Name = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialName;
RecipeFinishInfo.Material[i].Material_BarrelNum = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).RawMaterialBarrelNum;
RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(i).Laying_Off_Weight;
}
if (SiemensDevice.IsConnected)
{
RecipeFinishInfo.Ask_For_Finish = true;
SiemensDevice.Siemens_PLC_S7.WriteClass(RecipeFinishInfo, 3);
}
App.Current.Dispatcher.Invoke(() =>
{
Json.Data.Recipes.Remove(res);
});
RecipeQueueTray2.TryDequeue(out code);
HKDevice.HK_PLC_S7.Write("DB3.DBX1.2", false);
GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
}
}
}
}
}
}
}
}