|
- 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() { }
-
- /// <summary>
- /// 配方数据
- /// </summary>
- public ObservableCollection<RemoteRecipeData> RemoteRecipes = new ObservableCollection<RemoteRecipeData>();
- /// <summary>
- /// 原料的名称和料仓的位置对应
- /// </summary>
- public Dictionary<string, short> RawMaterialsNamePos = new Dictionary<string, short>();
- /// <summary>
- /// 配方队列
- /// </summary>
- public ConcurrentQueue<string> RecipeQueue = new ConcurrentQueue<string>();
- public ConcurrentQueue<string> RecipeQueueTray2 = new ConcurrentQueue<string>();
-
- public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
- public HKDeviceStatus HKDevice = new HKDeviceStatus();
- public WindSendDeviceStatus WindSendDevice = new WindSendDeviceStatus();
- XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
- /// <summary>
- /// 风送PLC的DB块
- /// </summary>
- WindSend_Write WindSendData = new WindSend_Write();
- /// <summary>
- /// 接收原料数据
- /// </summary>
- public RecipeRawMaterial RawMaterial;
- public void Init()
- {
- testData();
- //Json<RemoteRecipeDataColl>.Data.Recipes = Json<LocalRecipeDataColl>.Data.Recipes;
- 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<object>((res) =>
- {
- ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
- ObservableCollection<WindSendRawMaterial> WindSendData = new ObservableCollection<WindSendRawMaterial>();
- if (SiemensDevice.IsConnected)
- {
- if (res != null && res is XL_Start_DB recipe)
- {
- if (!string.IsNullOrEmpty(recipe.RecipeCode)) {
- RawMaterials.Clear();
- for (int i = 0; i < GVL_SmallStation.Max_DosingSotckBinNum; i++)
- {
- if (!string.IsNullOrEmpty(recipe.Material[i].Material_Name))
- {
- 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
- {
- //MessageNotify.GetInstance.AlarmLog("配方名称与本地不符合");
- }
- }
- else
- {
- break;
- }
- }
- for (int i = 0; i < GVL_SmallStation.Max_PowderSotckBinNum; i++)
- {
- if (!string.IsNullOrEmpty(recipe.Powder[i].Powder_Name))
- {
- WindSendData.Add(new WindSendRawMaterial()
- {
- RawMaterialName = recipe.Powder[i].Powder_Name,
- RawMaterialWeight = recipe.Powder[i].Powder_Weight
- });
- }
- else
- {
- break;
- }
- }
- App.Current.Dispatcher.Invoke(() => {
- Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
- {
- RecipeName = recipe.RecipeName,
- RecipeCode = recipe.RecipeCode,
- RawMaterial = RawMaterials,
- TrayCode = recipe.StockCode,
- WindSend = WindSendData
- });
- });
- }
- }
- }
- }), "SiemensRecipeRecive", true);
- ActionManage.GetInstance.CancelRegister("SiemensRecipeFinish");
- ActionManage.GetInstance.Register(new Action<object>((res) =>
- {
- if (SiemensDevice.IsConnected)
- {
- if (res != null && res is RemoteRecipeData recipe)
- {
- RecipeFinishInfo.Order_No = recipe.RecipeCode;
- RecipeFinishInfo.Product_Code = recipe.RecipeName;
- RecipeFinishInfo.Job_No = (short)recipe.TrayCode;
- for (int i = 0; i < recipe.RawMaterial.Count; i++)
- {
- RecipeFinishInfo.Material[i] = new UDT1();
- RecipeFinishInfo.Material[i].Material_Name = recipe.RawMaterial.ElementAt(i).RawMaterialName;
- RecipeFinishInfo.Material[i].Material_BarrelNum = recipe.RawMaterial.ElementAt(i).RawMaterialBarrelNum;
- RecipeFinishInfo.Material[i].Material_Laying_Off_Weight = recipe.RawMaterial.ElementAt(i).Laying_Off_Weight;
- }
- for (int i = 0; i < recipe.WindSend.Count; i++)
- {
- RecipeFinishInfo.Powder[i] = new UDT2();
- RecipeFinishInfo.Powder[i].Powder_Name = recipe.RawMaterial.ElementAt(i).RawMaterialName;
- RecipeFinishInfo.Powder[i].Powder_Weight = recipe.RawMaterial.ElementAt(i).Laying_Off_Weight;
- }
- if (GVL_SmallStation.SiemensSendRecipeStatus == 6)
- {
- GVL_SmallStation.SiemensSendRecipeStatus = 7;
- RecipeFinishInfo.Ask_For_Finish = true;
- SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
- }
- }
- }
- }), "SiemensRecipeFinish", true);
- ActionManage.GetInstance.CancelRegister("LocalSimulationRecipeIssue");
- ActionManage.GetInstance.Register(new Action<Object>((res) =>
- {
- if (res != null && res is RemoteRecipeData recipe)
- {
- Json<RemoteRecipeDataColl>.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
- {
- if (Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
- {
- HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
- }
- if (Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
- {
- SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- }
- if (Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
- {
- WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
- }
- if (HKDevice.IsConnected)
- {
- HKDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("海科plc连接成功,并初始化完成");
- }
- if (SiemensDevice.IsConnected)
- {
- SiemensDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功,并初始化完成");
- }
- if (WindSendDevice.IsConnected)
- {
- WindSendDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("风送plc连接成功,并初始化完成");
- }
- }
- catch (Exception ex)
- {
- }
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- if (!HKDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
- {
- HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
- MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接");
- if (HKDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
- }
- if (!SiemensDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
- {
- SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接");
- if (SiemensDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
- }
- if (!WindSendDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
- {
- WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
- MessageNotify.GetInstance.ShowRunLog("风送plc重新连接成功");
- }
- Thread.Sleep(50);
- }), "设备连接", true);
- RecipeQueue.Clear();
- //手动控制系统模式
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", true); }), "SystemStart", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.0", false); }), "SystemStop", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", true); }), "SystemPause", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.2", false); }), "SystemReset", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", false); }), "SystemAutoMode", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.1", true); }), "SystemDebugMode", true);
- //流程控制
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.3", true); }), "ManualSystemReset", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB44.DBX0.4", true); }), "CLearRecipeInfo", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX0.7", true); }), "AGVPutTrayFinish", true);
- //手动控制电机轴
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", true); }), "StartAxisLoadCommand", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.6", false); }), "StopAxisLoadCommand", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", true); }), "StartAxisMidCommand", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX4.7", false); }), "StopAxisMidCommand", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", true); }), "StartAxisUnLoadCommand", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.0", false); }), "StopAxisUnLoadCommand", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", true); }), "StartAxis1Command", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.1", false); }), "StopAxis1Command", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", true); }), "StartAxis2Command", true);
- ActionManage.GetInstance.Register(new Action(() => { HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX5.2", false); }), "StopAxis2Command", true);
- //电机速度
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBD8", value);
- }
- }), "AxisLoadSpeedSet", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBD10", value);
- }
- }), "AxisMidSpeedSet", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBD12", value);
- }
- }), "AxisUnLoadSpeedSet", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is float value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBD0", value);
- }
- }), "Axis1SpeedSet", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is float value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBD4", value);
- }
- }), "Axis2SpeedSet", true);
- RecipeQueue.Clear();
- //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- if (HKDevice.IsConnected)
- {
- GVL_SmallStation.GetInstance.HeartBeatToPlc = !GVL_SmallStation.GetInstance.HeartBeatToPlc;
- HKDevice.HK_PLC_S7.Write("DB4.DBX0.0", GVL_SmallStation.GetInstance.HeartBeatToPlc);
- GVL_SmallStation.GetInstance.HeartBeatFromPlc = HKDevice.HK_PLC_S7.Read<bool>("DB45.DBX0.0");
- //获取系统状态
- GVL_SmallStation.SystemStatus = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.0");//系统启停
- GVL_SmallStation.SystemMode = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.1");//系统模式
- GVL_SmallStation.SystemRunStatus = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.2");//系统暂停
- }
- Thread.Sleep(200);
- }), "通信心跳", true);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- DeviceStatusDispose();
- ReceviceData();
- RecipeInfoToHKPLC();
- Thread.Sleep(10);
- }), "西门子配发下发流程处理", true);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- if (HKDevice.IsConnected)
- {
- 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<bool>("DB5.DBX0." + i);
- }
- for (int i = 0; i < 7; i++)
- {
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[i + 8] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX0." + i);
- }
- }
- private void ManualOpen()
- {
- ActionManage.GetInstance.Register(new Action<object>((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<bool>("DB5.DBX0.0", true);
- break;
- case 2:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.1", true);
- break;
- case 3:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.2", true);
- break;
- case 4:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.3", true);
- break;
- case 5:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.4", true);
- break;
- case 6:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.5", true);
- break;
- case 7:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.6", true);
- break;
- case 8:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX0.7", true);
- break;
- case 9:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.0", true);
- break;
- case 10:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.1", true);
- break;
- case 11:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.2", true);
- break;
- case 12:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.3", true);
- break;
- case 13:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.4", true);
- break;
- case 14:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX1.5", true);
- break;
- case 15:
- HKDevice.HK_PLC_S7.Write<bool>("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<bool>("DB5.DBX1.7", true);
- break;
- case 2:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.0", true);
- break;
- case 3:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.1", true);
- break;
- case 4:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.2", true);
- break;
- case 5:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.3", true);
- break;
- case 6:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.4", true);
- break;
- case 7:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.5", true);
- break;
- case 8:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.6", true);
- break;
- case 9:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX2.7", true);
- break;
- case 10:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.0", true);
- break;
- case 11:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.1", true);
- break;
- case 12:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.2", true);
- break;
- case 13:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.3", true);
- break;
- case 14:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.4", true);
- break;
- case 15:
- HKDevice.HK_PLC_S7.Write<bool>("DB5.DBX3.5", true);
- 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", 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", 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);
- }
- }
- }), "ManualOpen", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
- }
- private void ManualClose()
- {
- ActionManage.GetInstance.Register(new Action<object>((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", true);
- }
- 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", 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);
- }
-
- }
- }), "ManualClose", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
- }
- /// <summary>
- ///
- /// </summary>
- private void DeviceStatusDispose()
- {
- if (HKDevice.IsConnected)
- {
- GVL_SmallStation.Station1HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX0.7");//工站1 有货架
- GVL_SmallStation.Station2HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.0");//工站1 有货架
- if (RTrig.GetInstance("WindSendDosingCompleToHKPLC").Start(GVL_SmallStation.WindSendDosingComple))
- {
- GVL_SmallStation.WindSendDosingComple = false;
- HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", true);
- MessageNotify.GetInstance.ShowRunLog("风送配料完成信号,发给产线plc信号");
- }
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1"))
- {
- HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", false);
- }
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.7"))//允许下配方1或者允许下配方2
- {
- GVL_SmallStation.IsAllowSiemensSendRecipe = true;
- //MessageNotify.GetInstance.ShowRunLog("Plc允许下发配方");
- }
-
- GVL_SmallStation.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1");
- GVL_SmallStation.Station2Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2");
- GVL_SmallStation.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3");
- GVL_SmallStation.Station2Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4");
- if (!GVL_SmallStation.TrayLogicFinish)
- {
- if (GVL_SmallStation.AGV_PutTray1Finish)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX0.7", true);
- GVL_SmallStation.AGV_PutTray1Finish = false;
- MessageNotify.GetInstance.ShowRunLog("AGV到位 发送到位信号给plc");
- }
- if (GVL_SmallStation.Station1HaveTray)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX0.7", false);
- GVL_SmallStation.TrayLogicFinish = true;
- MessageNotify.GetInstance.ShowRunLog("托盘1有货架");
- }
- else
- {
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.5") == true)
- {
- if (GVL_SmallStation.CylinderReset)
- {
- HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.5", true);
- }
- MessageNotify.GetInstance.ShowRunLog("气缸收紧错位");
- }
- else
- {
- HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.5", false);
- }
- }
- }
- else
- {
- if (GVL_SmallStation.AGV_GetTray1Finish)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX1.1", true);
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.7") == true)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX1.1", false);
- GVL_SmallStation.TrayLogicFinish = false;
- GVL_SmallStation.AGV_GetTray1Finish = false;
- }
- }
-
- }
- }
- if (SiemensDevice.IsConnected)
- {
- ushort TrayCylinder = 0;
- ushort TraySensor = 0;
- if (GVL_SmallStation.Station1Sensor)
- {
- TraySensor = TraySensor.SetBitValue(1, true);
- }
- else
- {
- TraySensor = TraySensor.SetBitValue(0, false);
- }
- if (!GVL_SmallStation.Station1Cylinder)
- {
- TrayCylinder = TrayCylinder.SetBitValue(1, true);
- }
- else
- {
- TrayCylinder = TrayCylinder.SetBitValue(0, false);
- }
- this.SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2231.DBX28.4", GVL_SmallStation.WindSendAllowAGVPutGet);
- this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW190", TraySensor);//添加工位传感器的信号
- this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW192", TrayCylinder);//添加工位气缸的信号
-
- if (RTrig.GetInstance("AGV_PutTray1Finish1111").Start(SiemensDevice.XL_Status.AgvFinishPut == 1))
- {
- GVL_SmallStation.AGV_PutTray1Finish = true;
- }
- if (RTrig.GetInstance("AGV_GetTray1Finish111").Start(SiemensDevice.XL_Status.AgvFinishGet == 1))
- {
- GVL_SmallStation.AGV_GetTray1Finish = true;
- }
- }
- }
- /// <summary>
- /// 将配方添加到配方队列中
- /// </summary>
- private void ReceviceData()
- {
- if (!GVL_SmallStation.GetInstance.IsUseLocalRecipe)
- {
- RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
- if (RemoteRecipes.Count > 0)
- {
- foreach (var data in RemoteRecipes)
- {
- if (data.TrayCode == 1)
- {
- if (!(RecipeQueue.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.XL_Status is XL_Status_DB status)
- {
- if (GVL_SmallStation.SiemensSendRecipeStatus == 3)
- {
- GVL_SmallStation.SiemensSendRecipeStatus = 4;
- SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true);
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},请求配料");
- }
- if (GVL_SmallStation.SiemensSendRecipeStatus == 4)
- {
- if (SiemensDevice.XL_Status.Dosing_Confirm)
- {
- GVL_SmallStation.SiemensSendRecipeStatus = 5;
- SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false);
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},配料信号复位");
- }
- }
- if (GVL_SmallStation.SiemensSendRecipeStatus == 5)
- {
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},西门子确认配料");
- if (SiemensDevice.XL_Status.Dosing_Confirm == false)
- {
- RecipeQueue.Enqueue(data.RecipeCode);
- GVL_SmallStation.SiemensSendRecipeStatus = 6;
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},加入队列");
- }
- }
- }
- }
- }
- else if (data.TrayCode == 2)
- {
- if (!(RecipeQueueTray2.Contains(data.RecipeCode)))
- {
- if (SiemensDevice.XL_Status is XL_Status_DB status)
- {
- if (GVL_SmallStation.SiemensSendRecipeStatus == 3)
- {
- GVL_SmallStation.SiemensSendRecipeStatus = 4;
- SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true);
- }
- if (GVL_SmallStation.SiemensSendRecipeStatus == 4)
- {
- if (SiemensDevice.XL_Status.Dosing_Confirm)
- {
- GVL_SmallStation.SiemensSendRecipeStatus = 5;
- SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false);
- }
- }
- if (GVL_SmallStation.SiemensSendRecipeStatus == 5)
- {
- if (SiemensDevice.XL_Status.Dosing_Confirm == false)
- {
- GVL_SmallStation.SiemensSendRecipeStatus = 0;
- RecipeQueueTray2.Enqueue(data.RecipeCode);
- }
- }
- }
- }
- }
- }
- }
- else
- {
- RecipeQueue.Clear();
- RecipeQueueTray2.Clear();
- GVL_SmallStation.GetInstance.RecipeStatusID = 0;
- GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
- }
- }
- else
- {
- RemoteRecipes = Json<RemoteRecipeDataColl>.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.DosingTray1 = false;
- GVL_SmallStation.GetInstance.DosingTray1Loc = 0;
-
- GVL_SmallStation.GetInstance.DosingTray2 = false;
- GVL_SmallStation.GetInstance.DosingTray2Loc = 0;
-
- GVL_SmallStation.GetInstance.RecipeStatusID = 0;
- GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
- }
- }
- }
- /// <summary>
- /// 执行配方队列中的第一个配方
- /// </summary>
- private void RecipeInfoToHKPLC()
- {
- if (RecipeQueue.Count > 0 && GVL_SmallStation.TrayLogicFinish)
- {
- 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)
- {
- WindSendData.TargetRecipeCode = code;
- WindSendData.IsAllowDosing = true;
- foreach (var item in RemoteRecipes.ElementAt(index).WindSend)
- {
- if (item.RawMaterialName == "0037")
- {
- WindSendData.RawMaterial1_SetWeight = item.RawMaterialWeight;
- }
- if (item.RawMaterialName == "0038")
- {
- WindSendData.RawMaterial2_SetWeight = item.RawMaterialWeight;
- }
- if (item.RawMaterialName == "")
- {
- WindSendData.RawMaterial3_SetWeight = item.RawMaterialWeight;
- }
- if (item.RawMaterialName == "")
- {
- WindSendData.RawMaterial4_SetWeight = item.RawMaterialWeight;
- }
- if (item.RawMaterialName == "0036")
- {
- WindSendData.RawMaterial5_SetWeight = item.RawMaterialWeight;
- }
- }
- WindSendDevice.Siemens_PLC_S7.WriteClass<WindSend_Write>(WindSendData, 95);
- }
- 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;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},下发完成");
- GVL_SmallStation.GetInstance.time1 = DateTime.Now;
- }
-
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.3") && GVL_SmallStation.GetInstance.RecipeStatusID == 1)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX1.3", false);
- GVL_SmallStation.GetInstance.RecipeStatusID = 2;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,{ recipeName}plc端 配方接收完成");
- }
- if (GVL_SmallStation.GetInstance.RecipeStatusID == 2)
- {
- if (GVL_SmallStation.GetInstance.DosingTray1 == false && GVL_SmallStation.GetInstance.DosingTray1Loc == 0)
- {
- if (RTrig.GetInstance("DB3.DBX50.0").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.0")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD10");
- MessageNotify.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 * 1000;//单位g转换kg
- if (loc_index >= 0)
- {
- DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
- GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
- }
- GVL_SmallStation.GetInstance.DosingTray1 = true;
- GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
- }
- }
- else if (RTrig.GetInstance("DB3.DBX50.1").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.1")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD14");
- MessageNotify.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 * 1000;
- if (loc_index >= 0)
- {
- DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
- GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
- }
- GVL_SmallStation.GetInstance.DosingTray1 = true;
- GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
- }
- }
- else if (RTrig.GetInstance("DB3.DBX50.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.2")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD18");
- MessageNotify.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*1000;
- if (loc_index >= 0)
- {
- DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
- GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
- }
- GVL_SmallStation.GetInstance.DosingTray1 = true;
- GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
- }
- }
- else if (RTrig.GetInstance("DB3.DBX50.3").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.3")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD22");
- MessageNotify.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*1000;
- if (loc_index >= 0)
- {
- DeviceInquire.GetInstance.GetDevice((int)loc)?.Start(weight);//启动并写入每个原料重量
- GVL_SmallStation.GetInstance.StockInIsWork = (int)loc;
- }
- GVL_SmallStation.GetInstance.DosingTray1 = true;
- GVL_SmallStation.GetInstance.DosingTray1Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
- }
- }
- }
- if (GVL_SmallStation.GetInstance.DosingTray1 && GVL_SmallStation.GetInstance.DosingTray1Loc > 0 && GVL_SmallStation.GetInstance.DosingTray1Loc < 16)
- {
- int i = GVL_SmallStation.GetInstance.DosingTray1Loc;
- if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
- {
- MessageNotify.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.NowWeightFeedback;
- bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
- MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘1,配方:{recipeName},{i}号仓,下料完成重量:{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}");
- if (info)
- {
- MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送成功");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送失败");
- }
- if (i >= 1 && i <= 8)
- {
- string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true, 4);
- MessageNotify.GetInstance.ShowRunLog(commInfo);
- }
- else if (i >= 9 && i <= 15)
- {
- string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true, 4);
- MessageNotify.GetInstance.ShowRunLog(commInfo1);
- }
- GVL_SmallStation.GetInstance.DosingTray1 = false;
- GVL_SmallStation.GetInstance.DosingTray1Loc = 0;
- }
- }
- if ((RTrig.GetInstance("配方配料完成").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.1"))))
- {
- var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成");
- foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
- {
- MessageNotify.GetInstance.ShowRunLog($"{item.RawMaterialName},下料重量:{item.Laying_Off_Weight}g");
- }
- if (SiemensDevice.IsConnected)
- {
- RecipeFinishInfo.Order_No = RemoteRecipes.ElementAt(index).RecipeCode;
- RecipeFinishInfo.Product_Code = RemoteRecipes.ElementAt(index).RecipeName;
- RecipeFinishInfo.Job_No = (short)trayCode;
- for (int i = 0; i < 20; i++)
- {
- RecipeFinishInfo.Material[i] = new UDT1();
- }
- for (int i = 0; i < 10; i++)
- {
- RecipeFinishInfo.Powder[i] = new UDT2();
- }
- for (int i = 0; i < RemoteRecipes.ElementAt(index).RawMaterial.Count; i++)
- {
- 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 * (float)0.001;
- }
- for (int i = 0; i < RemoteRecipes.ElementAt(index).WindSend.Count; i++)
- {
- RecipeFinishInfo.Powder[i].Powder_Weight = RemoteRecipes.ElementAt(index).WindSend.ElementAt(i).DosingCompleWeight;
- }
- if (GVL_SmallStation.SiemensSendRecipeStatus == 6)
- {
- double a = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.time1).TotalSeconds;
- GVL_SmallStation.SiemensSendRecipeStatus = 7;
- RecipeFinishInfo.Ask_For_Finish = true;
- RecipeFinishInfo.DosingTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
- }
- }
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipeDataColl>.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 && GVL_SmallStation.Station2HaveTray)
- {
- 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)
- {
- MessageNotify.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;
- MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},下发完成");
- }
-
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.4") && GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 1)
- {
- HKDevice.HK_PLC_S7.Write("DB3.DBX1.4", false);
- GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 2;
- MessageNotify.GetInstance.ShowRunLog($"配方:{recipeName},plc端 配方接收完成");
- }
- if (GVL_SmallStation.GetInstance.RecipeStatusIDTray2 == 2)
- {
- if (RTrig.GetInstance("DB3.DBX50.4").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.4")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD26");
- MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{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;
- }
- GVL_SmallStation.GetInstance.DosingTray2 = true;
- GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},1号桶,{(int)loc}号仓,配料完成");
- }
- }
- else if (RTrig.GetInstance("DB3.DBX50.5").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.5")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD30");
- MessageNotify.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;
- }
- GVL_SmallStation.GetInstance.DosingTray2 = true;
- GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},2号桶,{(int)loc}号仓,配料完成");
- }
- }
- else if (RTrig.GetInstance("DB3.DBX50.6").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.6")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD34");
- MessageNotify.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;
- }
- GVL_SmallStation.GetInstance.DosingTray2 = true;
- GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},3号桶,{(int)loc}号仓,配料完成");
- }
- }
- else if (RTrig.GetInstance("DB3.DBX50.7").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX50.7")))
- {
- var res = HKDevice.HK_PLC_S7.Read<float>("DB3.DBD38");
- MessageNotify.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;
- }
- GVL_SmallStation.GetInstance.DosingTray2 = true;
- GVL_SmallStation.GetInstance.DosingTray2Loc = (int)loc;
- MessageNotify.GetInstance.ShowRunLog($"托盘2,配方:{recipeName},4号桶,{(int)loc}号仓,配料完成");
- }
- }
- if (GVL_SmallStation.GetInstance.DosingTray2 == true && GVL_SmallStation.GetInstance.DosingTray1 == false && GVL_SmallStation.GetInstance.DosingTray2Loc > 0 && GVL_SmallStation.GetInstance.DosingTray2Loc < 16)
- {
- int i = GVL_SmallStation.GetInstance.DosingTray2Loc;
- if (RTrig.GetInstance("Tray2StatusDevice" + i).Start(DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3))
- {
- MessageNotify.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.NowWeightFeedback;
- bool info = DeviceInquire.GetInstance.GetDevice(i).StatusReset();
- if (info)
- {
- MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送成功");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"柔性味魔方配料完成后复位 发送失败");
- }
- if (i >= 1 && i <= 8)
- {
- string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (i - 1), true, 4);
- MessageNotify.GetInstance.ShowRunLog(commInfo);
- }
- else if (i >= 9 && i <= 15)
- {
- string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (i - 9), true, 4);
- MessageNotify.GetInstance.ShowRunLog(commInfo1);
- }
- GVL_SmallStation.GetInstance.DosingTray2 = false;
- GVL_SmallStation.GetInstance.DosingTray2Loc = 0;
- }
- }
- if (RTrig.GetInstance("DB3.DBX1.2").Start(HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX1.2")))
- {
- var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
- MessageNotify.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<XL_Finish_DB>(RecipeFinishInfo, 2261);
- }
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
- });
- RecipeQueueTray2.TryDequeue(out code);
- HKDevice.HK_PLC_S7.Write("DB3.DBX1.2", false);
- GVL_SmallStation.GetInstance.RecipeStatusIDTray2 = 0;
- }
- }
- }
- }
- }
- }
- private void StockBinInit()
- {
- for (int i = 1; i < 16; i++)
- {
- if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
- {
- DeviceInquire.GetInstance.GetDevice(i).StatusReset();
- }
- }
- }
- private void DosingDevice(int Index,int DeviceID)
- {
- if (RTrig.GetInstance("Tray2StatusDevice" + DeviceID).Start(DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.RunStatus == 3))
- {
- MessageNotify.GetInstance.ShowRunLog($"柔性味魔方,托盘2,配方:{RemoteRecipes.ElementAt(Index).RecipeName},{DeviceID}号仓,配料完成");
- int res = Array.FindIndex(RemoteRecipes.ElementAt(Index).RawMaterial.ToArray(), p => p.RawMaterialLocation == DeviceID);
- RemoteRecipes.ElementAt(Index).RawMaterial.ElementAt(res).Laying_Off_Weight = DeviceInquire.GetInstance.GetDevice(DeviceID).deviceStatus.CutWeightFeedback;
- DeviceInquire.GetInstance.GetDevice(DeviceID).StatusReset();
- if (DeviceID >= 1 && DeviceID <= 8)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX30." + (DeviceID - 1), true);
- }
- else if (DeviceID >= 9 && DeviceID <= 15)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX31." + (DeviceID - 9), true);
- }
- }
- }
- private void testData()
- {
- RawMaterialsNamePos.Add("0051", 3);
- RawMaterialsNamePos.Add("0052", 4);
- RawMaterialsNamePos.Add("0054", 5);
- RawMaterialsNamePos.Add("0057", 6);
- RawMaterialsNamePos.Add("0050", 8);
- RawMaterialsNamePos.Add("0048", 13);
-
- RawMaterialsNamePos.Add("0036", 13);//I+G
- RawMaterialsNamePos.Add("0037", 13);//味精
- RawMaterialsNamePos.Add("0038", 13);//白糖
-
-
- }
-
- public short SetBitValue(short data, byte offset, bool val)
- {
- if (offset > 16 || offset < 1)
- {
- return data;
- }
-
- short num = (short)(1 << offset - 1);
- return (short)(val ? (data | num) : (data & ~num));
- }
- }
- }
|