|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Helper;
- using BPASmartClient.JXJFoodSmallStation.Model.GVL;
- using BPASmartClient.JXJFoodSmallStation.Model.HK_PLC;
- using BPASmartClient.JXJFoodSmallStation.Model.RawMaterial;
- 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.Reflection;
- 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>();
- public ObservableCollection<RawMaterialStockBin> RawMaterialsInfo => Json<DevicePar>.Data.rawMaterialStockBin;
- /// <summary>
- /// 配方队列
- /// </summary>
- public ConcurrentQueue<string> RecipeQueueTray1 = new ConcurrentQueue<string>();
-
-
- /// <summary>
- /// 物料集合
- /// </summary>
- public Dictionary<int, ConcurrentQueue<string>> RecipeQueueTray { get; set; } = new Dictionary<int, ConcurrentQueue<string>>();
-
- public ConcurrentQueue<string> RecipeQueueTray2 = new ConcurrentQueue<string>();
-
-
-
- public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
- public HKDeviceStatus HKDevice = new HKDeviceStatus();
- public WindSendDeviceStatus WindSendDevice = new WindSendDeviceStatus();
-
- public ObservableCollection<PlcInfos> CommData { get; set; } = new ObservableCollection<PlcInfos>();
- public ObservableCollection<PlcInfos> ProcessVar { get; set; } = new ObservableCollection<PlcInfos>();
- XL_Finish_DB RecipeFinishInfo = new XL_Finish_DB();
- /// <summary>
- /// 风送PLC的DB块
- /// </summary>
- WindSend_Write WindSendData = new WindSend_Write();
- /// <summary>
- /// 接收原料数据
- /// </summary>
- public RecipeRawMaterial RawMaterial;
- public DateTime StockBinAlarmTime = DateTime.Now;
-
- public string? HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
- public string? Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
- public string? WindSend_PLC_IP = ConfigurationManager.AppSettings["WindSend_IP"];
-
- public void Init()
- {
- RecipeQueueTray.TryAdd(0, new ConcurrentQueue<string>());
- RecipeQueueTray.TryAdd(1, new ConcurrentQueue<string>());
- RecipeQueueTray.TryAdd(2, new ConcurrentQueue<string>());
- RecipeQueueTray.TryAdd(3, new ConcurrentQueue<string>());
- RecipeQueueTray.TryAdd(4, new ConcurrentQueue<string>());
- PlcVarMonitor();
- StockBinNameWithPos();
- RawMaterialNameWithCode();
- RegisterInit();
- DeviceConnect();
- //Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- GVL_SmallStation.GetInstance.DisEnableStockAlarm = Json<DevicePar>.Data.deviceConnectPar.ShieldStockbinAlarm;
- 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");
- if (DeviceInquire.GetInstance.devices.Count < 15 && HKDevice.IsConnected && Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0 && GVL_SmallStation.GetInstance.DisEnableStockBinAlarm == false && DateTime.Now.Subtract(StockBinAlarmTime).TotalSeconds >= 60 & !GVL_SmallStation.GetInstance.DisEnableStockAlarm)
- {
- HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", true);
- App.Current.Dispatcher.Invoke(() =>
- {
- MessageNotify.GetInstance.ShowDialog($"未读取到15个柔性味魔方料仓", DialogType.Error);
- StockBinAlarmTime = DateTime.Now;
- });
- HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", false);
- }
- }
- Thread.Sleep(200);
- }), "海科plc通信心跳", true);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- if (GVL_SmallStation.GetInstance.Order_Cancel)
- {
- CancelOrder();//订单取消,不执行配方流程
- }
- else
- {
- ReceviceData();//配方请求
- RecipeInfoToHKPLC();//配方配料
- }
- Thread.Sleep(10);
- }), "小料站流程控制", true);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- RealTimeData();
- foreach (var item in Json<DevicePar>.Data.windSendRawMaterial)
- {
- if (GVL_SmallStation.GetInstance.RawMaterialsNameCode.ContainsKey(item.RawMaterialName))
- {
- item.RawMaterialChineseName = GVL_SmallStation.GetInstance.RawMaterialsNameCode[item.RawMaterialName];
- }
- else
- {
- item.RawMaterialChineseName = "";
- }
- }
- Thread.Sleep(10);
- }), "西门子PLC和小料站PLC的实时数据交互流程", true);
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- HKPlcRead();
- GetStatus();
- Thread.Sleep(10);
- }), "海科PLC实时数据", true);
- }
- /// <summary>
- /// 气缸的传感器值
- /// </summary>
- 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.DBX1." + i);
- }
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[20] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX3.6");//进料桶气缸
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[21] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX3.7");//出料筒气缸1
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[22] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.0");//出料筒气缸2
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[23] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.1");//出料筒气缸3
-
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[24] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.2");//托盘1_1气缸
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[25] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.3");//托盘1_2气缸
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[26] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.4");//托盘2_1气缸
- GVL_SmallStation.GetInstance.Cylinder_JackInfo[27] = HKDevice.HK_PLC_S7.Read<bool>("DB5.DBX4.5");//托盘2_2气缸
- }
- /// <summary>
- /// DB块的变量实时值
- /// </summary>
- private void HKPlcRead()
- {
- if (HKDevice.IsConnected)
- {
- foreach (PropertyInfo item in typeof(PlcReadAddressDB3).GetProperties())
- {
- int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
- if (index >= 0)
- {
- if (item.PropertyType.IsArray)
- {
- CommData.ElementAt(index).Value = "";
- Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
- foreach (var values in array)
- {
- string data = values.ToString();
- if (data.ToLower() == "false")
- data = "0";
- if (data.ToLower() == "true")
- data = "1";
- CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
- }
- }
- else
- {
- CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.plcReadDataDB3.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null).ToString();
- }
- }
- }
- }
- if (WindSendDevice.IsConnected)
- {
- foreach (PropertyInfo item in typeof(WindSend_Write).GetProperties())
- {
- int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
- if (index >= 0)
- {
- if (item.PropertyType.IsArray)
- {
- CommData.ElementAt(index).Value = "";
- Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
- foreach (var values in array)
- {
- string data = values.ToString();
- if (data.ToLower() == "false")
- data = "0";
- if (data.ToLower() == "true")
- data = "1";
- CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
- }
- }
- else
- {
- CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.WindSendDB95.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.WindSendDB95, null).ToString();
- }
- }
- }
- foreach (PropertyInfo item in typeof(WindSend_Read).GetProperties())
- {
- int index = Array.FindIndex(CommData.ToArray(), p => p.Name == item.Name);
- if (index >= 0)
- {
- if (item.PropertyType.IsArray)
- {
- CommData.ElementAt(index).Value = "";
- Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3, null);
- foreach (var values in array)
- {
- string data = values.ToString();
- if (data.ToLower() == "false")
- data = "0";
- if (data.ToLower() == "true")
- data = "1";
- CommData.ElementAt(index).Value = CommData.ElementAt(index).Value + data + ",";
- }
- }
- else
- {
- CommData.ElementAt(index).Value = GVL_SmallStation.GetInstance.WindSendDB94.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance.WindSendDB94, null).ToString();
- }
- }
- }
- }
- foreach (PropertyInfo item in typeof(GVL_SmallStation).GetProperties())
- {
- int index = Array.FindIndex(ProcessVar.ToArray(), p => p.Name == item.Name);
- if (index >= 0)
- {
- if (item.PropertyType.IsArray)
- {
- ProcessVar.ElementAt(index).Value = "";
- Array array = (Array)item.GetValue(GVL_SmallStation.GetInstance, null);
- foreach (var values in array)
- {
- string data = values.ToString();
- if (data.ToLower() == "false")
- data = "0";
- if (data.ToLower() == "true")
- data = "1";
- ProcessVar.ElementAt(index).Value = ProcessVar.ElementAt(index).Value + data + ",";
- }
- }
- else
- {
- ProcessVar.ElementAt(index).Value = GVL_SmallStation.GetInstance.GetType().GetProperty(item.Name).GetValue(GVL_SmallStation.GetInstance, null).ToString();
- }
- }
- }
- }
- /// <summary>
- /// 小料站和西门子PLC之间的实时数据
- /// </summary>
- private void RealTimeData()
- {
- if (HKDevice.IsConnected)
- {
- //获取系统状态
- GVL_SmallStation.GetInstance.PlcSystemIsAutoRun = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.0");//系统启停
- GVL_SmallStation.GetInstance.PlcSystemMode = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.1");//系统模式
- GVL_SmallStation.GetInstance.PlcSystemIsPause = HKDevice.HK_PLC_S7.Read<bool>("DB44.DBX0.2");//系统暂停
-
- GVL_SmallStation.GetInstance.Station1HaveTray = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.0");//工站1 有货架
-
- GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[0] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.0");
- GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[1] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1");
- GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[2] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2");
- GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[3] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3");
- GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[4] = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4");
- if (GVL_SmallStation.GetInstance.WindSendDosingComple)
- {
- //HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX1.7", true);
- HKDevice.HK_PLC_S7.Write<bool>("DB4.DBX4.0", true);
- GVL_SmallStation.GetInstance.WindSendDosingComple = false;
- 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.GetInstance.IsAllowSiemensSendRecipe = true;
- }*/
- //for (int i = 0; i < 5; i++)
- //{
- // if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i] && RecipeQueueTray[i].Count == 0)
- // {
- // GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = true;
- // }
- //}
- //GVL_SmallStation.GetInstance.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.1");
- //GVL_SmallStation.GetInstance.Station2Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.2");
- //GVL_SmallStation.GetInstance.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.3");
- //GVL_SmallStation.GetInstance.Station2Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX2.4");
- //GVL_SmallStation.GetInstance.RobotStatus = HKDevice.HK_PLC_S7.Read<ushort>("DB3.DBW100");
- //GVL_SmallStation.GetInstance.RobotProgramNum = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB102");
- if (Json<RemoteRecipeDataColl>.Data.Recipes.Count <= 3)
- {
- GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = true;
- }
-
- GVL_SmallStation.GetInstance.Station1Sensor = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.1");
- GVL_SmallStation.GetInstance.Station1Cylinder = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX40.2");
-
- GVL_SmallStation.GetInstance.RobotStatus = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB0");
- GVL_SmallStation.GetInstance.RobotProgramNum = HKDevice.HK_PLC_S7.Read<byte>("DB3.DBB1");
- }
- if (SiemensDevice.IsConnected)
- {
- ushort TrayCylinder = 0;
- ushort TraySensor = 0;
- if (GVL_SmallStation.GetInstance.Station1Sensor)
- {
- TraySensor = TraySensor.SetBitValue(1, true);
- }
- else
- {
- TraySensor = TraySensor.SetBitValue(0, false);
- }
- if (!GVL_SmallStation.GetInstance.Station1Cylinder)
- {
- TrayCylinder = TrayCylinder.SetBitValue(1, true);
- }
- else
- {
- TrayCylinder = TrayCylinder.SetBitValue(0, false);
- }
- this.SiemensDevice.Siemens_PLC_S7.Write<bool>("DB2231.DBX28.4", GVL_SmallStation.GetInstance.WindSendAllowAGVPutGet);
- this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW190", TraySensor);//添加工位传感器的信号
- this.SiemensDevice.Siemens_PLC_S7.Write<ushort>("DB2231.DBW192", TrayCylinder);//添加工位气缸的信号
- ushort AGV_Put = (ushort)SiemensDevice.XL_Status.AgvFinishPut;
- if (AGV_Put.Get16bitValue(1))
- {
- GVL_SmallStation.GetInstance.AGV_PutTray1Finish = true;
- }
- else
- {
- GVL_SmallStation.GetInstance.AGV_PutTray1Finish = false;
- }
- ushort AGV_Get = (ushort)SiemensDevice.XL_Status.AgvFinishGet;
- if (AGV_Get.Get16bitValue(1))
- {
- GVL_SmallStation.GetInstance.AGV_GetTray1Finish = true;
- }
- else
- {
- GVL_SmallStation.GetInstance.AGV_GetTray1Finish = false;
- }
- }
- }
-
- public void CancelOrder()
- {
- if (GVL_SmallStation.GetInstance.Order_Cancel) //订单取消
- {
- if (!string.IsNullOrEmpty(GVL_SmallStation.GetInstance.Order_CancelRecipeCode))
- {
- string code = GVL_SmallStation.GetInstance.Order_CancelRecipeCode;
- int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == code);
- int[] cnt = new int[5] { -1, -1, -1, -1, -1 };
- int index1 = -1;
- for (int i = 0; i < 5; i++)
- {
- cnt[i] = Array.FindIndex(RecipeQueueTray[i].ToArray(), p => p == code);
- if (cnt[i] >= 0)
- {
- index1 = i;
- }
- }
- switch (GVL_SmallStation.GetInstance.OrderCancelStep)
- {
- case 0://前提条件判断
- if (index == -1)
- {
- GVL_SmallStation.GetInstance.OrderCancelStep = 30;
- MessageNotify.GetInstance.ShowRunLog($"配方中并未找到订单{code}");
- }
- else
- {
- if (index1 >= 0)
- {
- GVL_SmallStation.GetInstance.OrderCancelStep = 1;
- }
- else
- {
- GVL_SmallStation.GetInstance.OrderCancelStep = 20;
- }
- }
- break;
-
- //Case 1-9为
- case 1:
- if (GVL_SmallStation.GetInstance.RecipeProcessStatus[index] != 0)
- {
- GVL_SmallStation.GetInstance.RecipeProcessStatus[index] = 0;
- HKDevice.HK_PLC_S7.Write("DB4.DBX6." + index1, true);
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,正在取消订单:{code}");
- GVL_SmallStation.GetInstance.OrderCancelStep = 2;
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"AGV未到达工站前,未给plc下发配方,取消订单:{code}");
- GVL_SmallStation.GetInstance.OrderCancelStep = 3;
- }
- break;
- case 2:
- if (HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX42." + index1))
- {
- if (GVL_SmallStation.GetInstance.Station1Cylinder == false)
- {
- GVL_SmallStation.GetInstance.OrderCancelStep = 3;
- MessageNotify.GetInstance.ShowRunLog($"PLC正在执行配料流程,取消订单:{code}");
- }
- }
- break;
- case 3:
- SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
- GVL_SmallStation.GetInstance.OrderCancelStep = 4;
- break;
- case 4:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2201.DBX440.1") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
- GVL_SmallStation.GetInstance.OrderCancelStep = 9;
- MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
- }
- break;
- case 9:
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);
- });
- RecipeQueueTray1.TryDequeue(out code);
- GVL_SmallStation.GetInstance.RecipeProcessStatus[index] = 0;
- GVL_SmallStation.GetInstance.Order_Cancel = false;
- GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
- GVL_SmallStation.GetInstance.OrderCancelStep = 0;
- break;
- case 20:
- SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
- GVL_SmallStation.GetInstance.OrderCancelStep = 21;
- break;
- case 21:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2201.DBX440.1") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
- GVL_SmallStation.GetInstance.OrderCancelStep = 29;
- MessageNotify.GetInstance.ShowRunLog($"队列1,西门子取消订单完成,订单号:{code}");
- }
- break;
- case 29:
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);
- });
- GVL_SmallStation.GetInstance.Order_Cancel = false;
- GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
- GVL_SmallStation.GetInstance.OrderCancelStep = 0;
- break;
-
- //30-39为订单还未下发至上位机
- case 30:
- SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", true);
- GVL_SmallStation.GetInstance.OrderCancelStep = 31;
- break;
- case 31:
- if (SiemensDevice.Siemens_PLC_S7.Read<bool>("DB2201.DBX440.1") == false)
- {
- SiemensDevice.Siemens_PLC_S7.Write("DB2201.DBX450.1", false);
- GVL_SmallStation.GetInstance.OrderCancelStep = 39;
- MessageNotify.GetInstance.ShowRunLog($"西门子取消订单完成,订单号:{code}");
- }
- break;
- case 39:
- GVL_SmallStation.GetInstance.Order_Cancel = false;
- GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
- GVL_SmallStation.GetInstance.OrderCancelStep = 0;
- break;
- }
- }
- }
- }
- /// <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 (SiemensDevice.XL_Status is XL_Status_DB status)
- {
- switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus)
- {
- case 3:
- SiemensDevice.Siemens_PLC_S7.WriteString(2231, data.RecipeCode, 10);
- SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", true);
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 4;
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},请求配料");
- break;
- case 4:
- if (SiemensDevice.XL_Status.Dosing_Confirm)
- {
- SiemensDevice.Siemens_PLC_S7.WriteString(2231, "", 10);//复位字符串
- SiemensDevice.Siemens_PLC_S7.Write("DB2231.DBX28.0", false);
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 5;
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},西门子确认配料");
- }
- break;
- case 5:
- if (SiemensDevice.XL_Status.Dosing_Confirm == false)
- {
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 6;
- MessageNotify.GetInstance.ShowRunLog($"配方{data.RecipeCode},西门子确认配料信号复位完成");
- }
- break;
- case 6:
- for (int i = 0; i < 5; i++)
- {
- if (GVL_SmallStation.GetInstance.NotUseSmallStation)
- {
- if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
- {
- RecipeQueueTray[i].Enqueue(data.RecipeCode);
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
- MessageNotify.GetInstance.ShowRunLog($"西门子配方配料 ,不使用小料配料,配方{data.RecipeCode},加入配方{i}");
- }
- }
- else if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i])
- {
- if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
- {
- RecipeQueueTray[i].Enqueue(data.RecipeCode);
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
- MessageNotify.GetInstance.ShowRunLog($"西门子配方配料 ,等待plc允许配料,配方{data.RecipeCode},加入配方{i}");
- }
- }
- }
- break;
- default:
- break;
- }
- }
-
- }
- }
- }
- else
- {
- for (int i = 0; i < 5; i++)
- {
- RecipeQueueTray[i].Clear();
- GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
- }
- GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
- GVL_SmallStation.GetInstance.WindSendDosing = false;
- }
- }
- else
- {
- RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
- if (RemoteRecipes.Count > 0)
- {
- foreach (var data in RemoteRecipes)
- {
- if (data.TrayCode == 1)
- {
- for (int i = 0; i < 5; i++)
- {
- if (GVL_SmallStation.GetInstance.NotUseSmallStation)
- {
- if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
- {
- RecipeQueueTray[i].Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"本地配方配料 ,不使用小料配料,配方{data.RecipeCode},加入配方{i}");
- }
- }
- else if (GVL_SmallStation.GetInstance.PlcAllowIssueRecipe[i])
- {
- if (RecipeQueueTray[i].Count == 0 && !RecipeQueueTray[0].Contains(data.RecipeCode) && !RecipeQueueTray[1].Contains(data.RecipeCode) && !RecipeQueueTray[2].Contains(data.RecipeCode) && !RecipeQueueTray[3].Contains(data.RecipeCode) && !RecipeQueueTray[4].Contains(data.RecipeCode))
- {
- RecipeQueueTray[i].Enqueue(data.RecipeCode);
- MessageNotify.GetInstance.ShowRunLog($"本地配方配料 ,等待plc允许配料,配方{data.RecipeCode},加入配方{i}");
- }
- }
- }
- }
- }
- }
- else
- {
- for (int i = 0; i < 5; i++)
- {
- RecipeQueueTray[i].Clear();
- GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
- }
- GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
- GVL_SmallStation.GetInstance.WindSendDosing = false;
- }
- }
- }
- /// <summary>
- /// 小料站配料
- /// </summary>
- private void RecipeInfoToHKPLC()
- {
- if (!GVL_SmallStation.GetInstance.NotUseSmallStation)
- {
- for (int i = 0; i < 5; i++)
- {
- switch (GVL_SmallStation.GetInstance.Tray_AGVLogic[i])
- {
- case 0:
- if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish && (RecipeQueueTray[i].Count > 0) && GVL_SmallStation.GetInstance.AGVIsGetTray == false)
- {
- GVL_SmallStation.GetInstance.AGVIsGetTray = true;
- HKDevice.HK_PLC_S7.Write("DB4.DBX8." + i, true);
- GVL_SmallStation.GetInstance.AGV_PutTray1Finish = false;
- GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 1;
- MessageNotify.GetInstance.ShowRunLog("AGV到位 发送到位信号给plc");
- }
- break;
- case 1:
- if (GVL_SmallStation.GetInstance.Station1HaveTray)
-
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX8." + i, false);
- GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 2;
- MessageNotify.GetInstance.ShowRunLog("托盘1有货架");
- }
- break;
- case 2:
- if (GVL_SmallStation.GetInstance.AGV_GetTray1Finish && GVL_SmallStation.GetInstance.RecipeProcessStatus[i] == 0)
- {
- GVL_SmallStation.GetInstance.AGVIsGetTray = false;
- HKDevice.HK_PLC_S7.Write("DB4.DBX10." + i, true);
- GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 3;
- MessageNotify.GetInstance.ShowRunLog("AGV取托盘1完成,发送给海科信号后1s后复位");
- }
- break;
- case 3:
- if (HKDevice.HK_PLC_S7.Read<bool>("DB4.DBX10." + i) == true)
- {
- Thread.Sleep(1000);
- HKDevice.HK_PLC_S7.Write("DB4.DBX10." + i, false);
- GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0;
- GVL_SmallStation.GetInstance.AGV_GetTray1Finish = false;
- MessageNotify.GetInstance.ShowRunLog("AGV取托盘1完成,信号复位");
- }
- break;
- default:
- break;
- }
- }
- }
- foreach (var recipe in RecipeQueueTray)
- {
- int recipeNum = recipe.Key;
- if (RecipeQueueTray[recipeNum].Count > 0)
- {
- int index = Array.FindIndex(RemoteRecipes.ToArray(), p => p.RecipeCode == RecipeQueueTray[recipeNum].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.NotUseSmallStation)
- {
- if (GVL_SmallStation.GetInstance.AGV_PutTray1Finish)
- {
- Thread.Sleep(5000);
- var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
- if (SiemensDevice.IsConnected && !GVL_SmallStation.GetInstance.IsUseLocalRecipe)
- {
- 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;
- }
- RecipeFinishInfo.Ask_For_Finish = true;
- RecipeFinishInfo.DosingTime = Convert.ToInt16(0);
- SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
-
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据反馈给西门子");
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方");
- }
- GVL_SmallStation.GetInstance.WindSendDosing = false;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
- });
- RecipeQueueTray[recipeNum].TryDequeue(out code);
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
- GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0;
- }
- }
- else
- {
- //粉料仓下发配方
- if (GVL_SmallStation.GetInstance.IsUseWindSend && GVL_SmallStation.GetInstance.WindSendDosing == false /*&& GVL_SmallStation.GetInstance.Tray_AGVLogic[recipeNum] == 2*/)
- {
- if (WindSendDevice.IsConnected)
- {
- if (GVL_SmallStation.GetInstance.WindSendDosingStatus == 1)
- {
- WindSend_Write WindSendData111 = new WindSend_Write();
- WindSendDevice.Siemens_PLC_S7.WriteClass<WindSend_Write>(WindSendData111, 95);
- Thread.Sleep(200);
- WindSendData111.TargetRecipeCode = code;
- WindSendData111.IsAllowDosing = true;
- foreach (var item in RemoteRecipes.ElementAt(index).WindSend)
- {
- if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(0).RawMaterialName || item.Location == 1)
- {
- WindSendData111.RawMaterial1_SetWeight = item.RawMaterialWeight;
- MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
- }
- if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(1).RawMaterialName || item.Location == 2)
- {
- WindSendData111.RawMaterial2_SetWeight = item.RawMaterialWeight;
- MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
- }
- if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(2).RawMaterialName || item.Location == 3)
- {
- WindSendData111.RawMaterial3_SetWeight = item.RawMaterialWeight;
- MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
- }
- if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(3).RawMaterialName || item.Location == 4)
- {
- WindSendData111.RawMaterial4_SetWeight = item.RawMaterialWeight;
- MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
- }
- if (item.RawMaterialName == Json<DevicePar>.Data.windSendRawMaterial.ElementAt(4).RawMaterialName || item.Location == 5)
- {
- WindSendData111.RawMaterial5_SetWeight = item.RawMaterialWeight;
- MessageNotify.GetInstance.ShowRunLog($"风送料仓{item.RawMaterialName},设定重量{item.RawMaterialWeight}");
- }
- }
- GVL_SmallStation.GetInstance.WindSendDosing = true;
- GVL_SmallStation.GetInstance.WindSendDosingStatus = 2;
- WindSendDevice.Siemens_PLC_S7.WriteClass<WindSend_Write>(WindSendData111, 95);
- }
- }
- else
- {
- if (Delay.GetInstance("delayTime").Start(true,60))
- {
- Delay.GetInstance("delayTime").Start(false, 60);
- MessageNotify.GetInstance.ShowRunLog($"风送设备PLC未连接");
- }
- }
- }
- if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 0)
- {
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
- HKDevice.IssueRecipeToPlc(RemoteRecipes.ElementAt(index).RawMaterial, recipeNum);
- HKDevice.HK_PLC_S7.Write("DB4.DBX2." + recipeNum, true);
- GVL_SmallStation.GetInstance.DosingTime[recipeNum] = DateTime.Now;
- GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 1;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号{code},配方号{recipeNum + 1},下发完成");
- }
- bool recipeReceviceFinish = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX4." + recipeNum);
- if (recipeReceviceFinish && GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 1)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBX2." + recipeNum, false);
- GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 2;
- GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0;
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号{code},配方号{recipeNum + 1},配方接收完成");
- }
- if (GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] == 2)
- {
- for (byte i = 1; i < 16; i++)
- {
- int indexArr = -1;
- if (GVL_SmallStation.GetInstance.plcReadDataDB3.StockBinAllowIssue[i - 1])
- {
- switch (recipeNum)
- {
- case 0:
- indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe1BarrelPosReserve.ToArray(), p => p == i);
- break;
- case 1:
- indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe2BarrelPosReserve.ToArray(), p => p == i);
- break;
- case 2:
- indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe3BarrelPosReserve.ToArray(), p => p == i);
- break;
- case 3:
- indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe4BarrelPosReserve.ToArray(), p => p == i);
- break;
- case 4:
- indexArr = Array.FindIndex(GVL_SmallStation.GetInstance.plcReadDataDB3.Recipe5BarrelPosReserve.ToArray(), p => p == i);
- break;
- }
- if (indexArr >= 0 && GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].Get16bitValue((byte)i) == false)
- {
- int loc_index = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
- float weight = RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(loc_index).RawMaterialWeight * 1000;//单位g转换kg
- if (weight <= 0)
- {
- if (i >= 1 && i <= 8)
- {
- string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX12." + (i - 1), true);
- MessageNotify.GetInstance.ShowRunLog(commInfo);
- }
- else if (i >= 9 && i <= 15)
- {
- string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX13." + (i - 9), true);
- MessageNotify.GetInstance.ShowRunLog(commInfo1);
- }
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false
- GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].SetBitValue((byte)i, true);//配料完成设备写成false
- }
- else
- {
- if (loc_index >= 0)
- {
- DeviceInquire.GetInstance.GetDevice((int)i)?.Start(weight);//根据料仓编号 启动并写入每个原料重量
- GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum].SetBitValue((byte)i, true);//配料完成设备写成false
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号:{code},配方号{recipeNum + 1},{indexArr + 1}号桶,错误没有找到{(int)i}号仓的配方");
- }
- }
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方编号:{code},配方号{recipeNum + 1},{indexArr + 1}号桶,{(int)i}号仓,正在配料");
- }
- else
- {
- //MessageNotify.GetInstance.ShowRunLog($"错误,有允许配料信号,但没有相应的位置 和桶号");
- }
- if ((DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3) && indexArr >= 0 && GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].Get16bitValue((byte)i))
- {
- int res = Array.FindIndex(RemoteRecipes.ElementAt(index).RawMaterial.ToArray(), p => p.RawMaterialLocation == i);
- if (res < 0)
- {
-
- }
- else
- {
- Thread.Sleep(GVL_SmallStation.GetInstance.Time);
- 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}");
- float AlarmRange = Math.Abs(RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight - RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).RawMaterialWeight * 1000);
- int iIndex = Array.FindIndex(Json<DevicePar>.Data.deviceParModels.ToArray(), p => p.MaterialName == DeviceInquire.GetInstance.GetDevice(i).DeviceName);
- if (iIndex >= 0)
- {
- if (Math.Abs(Json<DevicePar>.Data.deviceParModels.ElementAt(iIndex).ErrorRange) < AlarmRange)
- {
- HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", true);
- App.Current.Dispatcher.Invoke(() =>
- {
- MessageNotify.GetInstance.ShowDialog($"{i}号仓配料误差过大,设置出料重量{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).RawMaterialWeight * 1000}g,实际出料重量{RemoteRecipes.ElementAt(index).RawMaterial.ElementAt(res).Laying_Off_Weight}g,相差{AlarmRange}g,允许误差为{Math.Abs(Json<DevicePar>.Data.deviceParModels.ElementAt(iIndex).ErrorRange)}g,请联系人工处理", DialogType.Warning);
- HKDevice.HK_PLC_S7.Write("DB44.DBX3.0", false);
- });
- }
- }
- if (i >= 1 && i <= 8)
- {
- string commInfo = HKDevice.HK_PLC_S7.Write("DB4.DBX12." + (i - 1), true);
- MessageNotify.GetInstance.ShowRunLog(commInfo);
- }
- else if (i >= 9 && i <= 15)
- {
- string commInfo1 = HKDevice.HK_PLC_S7.Write("DB4.DBX13." + (i - 9), true);
- MessageNotify.GetInstance.ShowRunLog(commInfo1);
- }
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].SetBitValue((byte)i, false);//配料完成设备写成false
- MessageNotify.GetInstance.ShowRunLog($"配方{recipeNum},{GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].ToBinString()}");
- }
- }
- }
- }
- bool DosingComple = HKDevice.HK_PLC_S7.Read<bool>("DB3.DBX6." + recipeNum);
- if ((RTrig.GetInstance("配方配料完成").Start(DosingComple)) || (GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] > 0 && DosingComple))
- {
- GVL_SmallStation.GetInstance.RecipeDosingCompleNum = GVL_SmallStation.GetInstance.RecipeDosingCompleNum + 1;
- GVL_SmallStation.GetInstance.StockBinDosingIssue[recipeNum] = 0;
- if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] > 0)
- {
- for (int i = 1; i < 17; i++)
- {
- if (GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum].Get16bitValue((byte)i))
- {
- MessageNotify.GetInstance.ShowRunLog($"料仓配料完成,但存在料仓未配料:{i}号仓");
- }
- }
- }
- var res = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == code);
- double a = DateTime.Now.Subtract(GVL_SmallStation.GetInstance.DosingTime[recipeNum]).TotalSeconds;
- foreach (var item in RemoteRecipes.ElementAt(index).RawMaterial)
- {
- MessageNotify.GetInstance.ShowRunLog($"{item.RawMaterialName},下料重量:{item.Laying_Off_Weight}g");
- }
- if (SiemensDevice.IsConnected && !GVL_SmallStation.GetInstance.IsUseLocalRecipe)
- {
- 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;
- }
- RecipeFinishInfo.Ask_For_Finish = true;
- RecipeFinishInfo.DosingTime = Convert.ToInt16(a);
- SiemensDevice.Siemens_PLC_S7.WriteClass<XL_Finish_DB>(RecipeFinishInfo, 2261);
-
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据反馈给西门子");
- MessageNotify.GetInstance.ShowRecipeLog(res.RecipeName);
- }
- else
- {
- MessageNotify.GetInstance.ShowRunLog($"托盘1,配方{res.RecipeName},配料完成,数据无法反馈给西门子,西门子设备未连接或处于本地配方");
- MessageNotify.GetInstance.ShowRecipeLog(res.RecipeName);
- }
- GVL_SmallStation.GetInstance.WindSendDosing = false;
- App.Current.Dispatcher.Invoke(() =>
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.Remove(res);
- });
- RecipeQueueTray[recipeNum].TryDequeue(out code);
- GVL_SmallStation.GetInstance.RecipeStockBinDosing[recipeNum] = 0;
- GVL_SmallStation.GetInstance.RecipeProcessStatus[recipeNum] = 0;
- }
- }
- }
- }
- }
- }
- }
- }
- private void StockBinInit()
- {
- for (int i = 1; i < 16; i++)
- {
- if (DeviceInquire.GetInstance.GetDevice(i).deviceStatus.RunStatus == 3)
- {
- DeviceInquire.GetInstance.GetDevice(i).StatusReset();
- }
- }
- }
- /// <summary>
- /// 料仓的位置和原料名称的对应
- /// </summary>
- public void StockBinNameWithPos()
- {
- RawMaterialsNamePos.Clear();
- foreach (var material in RawMaterialsInfo)
- {
- if (!string.IsNullOrEmpty(material.RawMaterialName))
- {
- if (!RawMaterialsNamePos.ContainsKey(material.RawMaterialName))
- {
- RawMaterialsNamePos.Add(material.RawMaterialName, (short)material.RawMaterialLocation);
- }
- }
- }
- }
- /// <summary>
- /// PLC的DB3变量列表
- /// </summary>
- public void PlcVarMonitor()
- {
- foreach (PropertyInfo item in typeof(PlcReadAddressDB3).GetProperties())
- {
- if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
- {
- string type = item.PropertyType.ToString();
- CommData.Add(new PlcInfos()
- {
- Count = CommData.Count + 1,
- Name = item.Name,
- Address = item.GetCustomAttribute<VarCommAttribute>().Address,
- Type = type.Substring(type.IndexOf(".") + 1),
- Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
- Value = item.GetValue(GVL_SmallStation.GetInstance.plcReadDataDB3).ToString(),
- });
- }
- }
-
- foreach (PropertyInfo item in typeof(WindSend_Read).GetProperties())
- {
- if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
- {
- string type = item.PropertyType.ToString();
- CommData.Add(new PlcInfos()
- {
- Count = CommData.Count + 1,
- Name = item.Name,
- Address = item.GetCustomAttribute<VarCommAttribute>().Address,
- Type = type.Substring(type.IndexOf(".") + 1),
- Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
- Value = item.GetValue(GVL_SmallStation.GetInstance.WindSendDB94).ToString(),
- });
- }
- }
-
- foreach (PropertyInfo item in typeof(WindSend_Write).GetProperties())
- {
- if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
- {
- string type = item.PropertyType.ToString();
- CommData.Add(new PlcInfos()
- {
- Count = CommData.Count + 1,
- Name = item.Name,
- Address = item.GetCustomAttribute<VarCommAttribute>().Address,
- Type = type.Substring(type.IndexOf(".") + 1),
- Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
- Value = item.GetValue(GVL_SmallStation.GetInstance.WindSendDB95).ToString(),
- });
- }
- }
-
- foreach (PropertyInfo item in typeof(GVL_SmallStation).GetProperties())
- {
- if (Attribute.IsDefined(item, typeof(VarCommAttribute)))
- {
- string type = item.PropertyType.ToString();
- ProcessVar.Add(new PlcInfos()
- {
- Count = ProcessVar.Count + 1,
- Name = item.Name,
- Type = type.Substring(type.IndexOf(".") + 1),
- Address = item.GetCustomAttribute<VarCommAttribute>().Address,
- Describe = item.GetCustomAttribute<VarCommAttribute>().Describe,
- Value = item.GetValue(GVL_SmallStation.GetInstance).ToString()
- });
- }
- }
- }
- public void RegisterInit()
- {
- //手动控制气缸 DB5.DBX0.0~DB5.DBX4.5
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null)
- {
- if (o.ToString().Contains("升降气缸"))
- {
- int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
- if (index >= 1 && index <= 15)
- {
- string address = "DB5.DBX" + (index / 8) + "." + (index % 8 - 1);
- if (index == 8) address = "DB5.DBX0.7";
- HKDevice.HK_PLC_S7.Write<bool>(address, true);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:{address},值:true");
- }
- }
- else if (o.ToString().Contains("阻挡气缸"))
- {
- int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
- if (index >= 1 && index <= 15)
- {
- string address = "";
- if (index == 1) address = "DB5.DBX1.7";
- if (index == 2) address = "DB5.DBX2.0";
- if (index == 3) address = "DB5.DBX2.1";
- if (index == 4) address = "DB5.DBX2.2";
- if (index == 5) address = "DB5.DBX2.3";
- if (index == 6) address = "DB5.DBX2.4";
- if (index == 7) address = "DB5.DBX2.5";
- if (index == 8) address = "DB5.DBX2.6";
- if (index == 9) address = "DB5.DBX2.7";
- if (index == 10) address = "DB5.DBX3.0";
- if (index == 11) address = "DB5.DBX3.1";
- if (index == 12) address = "DB5.DBX3.2";
- if (index == 13) address = "DB5.DBX3.3";
- if (index == 14) address = "DB5.DBX3.4";
- if (index == 15) address = "DB5.DBX3.5";
- HKDevice.HK_PLC_S7.Write<bool>(address, true);
- }
- }
- else if (o.ToString().Contains("进料桶顶升气缸"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", false);//默认顶升
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.6,值:false");
- }
- else if (o.ToString().Contains("出料桶顶升气缸1"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", true);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.7,值:true");
- }
- else if (o.ToString().Contains("出料桶顶升气缸2"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", true);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.0,值:true");
- }
- else if (o.ToString().Contains("出料桶顶升气缸3"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", true);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址: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将 托盘的位置信息添加到配方中
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null)
- {
- if (o.ToString().Contains("升降气缸"))
- {
- int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
- if (index >= 1 && index <= 15)
- {
- string address = "DB5.DBX" + (index / 8) + "." + (index % 8 - 1);
- if (index == 8) address = "DB5.DBX0.7";
- HKDevice.HK_PLC_S7.Write<bool>(address, false);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:{address},值:false");
- }
- }
- else if (o.ToString().Contains("阻挡气缸"))
- {
- int index = Convert.ToInt16(o.ToString().Substring(o.ToString().Length - 2));
- if (index >= 1 && index <= 15)
- {
- string address = "";
- if (index == 1) address = "DB5.DBX1.7";
- if (index == 2) address = "DB5.DBX2.0";
- if (index == 3) address = "DB5.DBX2.1";
- if (index == 4) address = "DB5.DBX2.2";
- if (index == 5) address = "DB5.DBX2.3";
- if (index == 6) address = "DB5.DBX2.4";
- if (index == 7) address = "DB5.DBX2.5";
- if (index == 8) address = "DB5.DBX2.6";
- if (index == 9) address = "DB5.DBX2.7";
- if (index == 10) address = "DB5.DBX3.0";
- if (index == 11) address = "DB5.DBX3.1";
- if (index == 12) address = "DB5.DBX3.2";
- if (index == 13) address = "DB5.DBX3.3";
- if (index == 14) address = "DB5.DBX3.4";
- if (index == 15) address = "DB5.DBX3.5";
- HKDevice.HK_PLC_S7.Write<bool>(address, false);
- }
- }
- else if (o.ToString().Contains("进料桶顶升气缸"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX3.6", true);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.6,值:true");
- }
- else if (o.ToString().Contains("出料桶顶升气缸1"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX3.7", false);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX3.7,值:false");
- }
- else if (o.ToString().Contains("出料桶顶升气缸2"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX4.0", false);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址:DB5.DBX4.0,值:false");
- }
- else if (o.ToString().Contains("出料桶顶升气缸3"))
- {
- HKDevice.HK_PLC_S7.Write("DB5.DBX4.1", false);
- MessageNotify.GetInstance.ShowUserLog($"手动操作气缸,地址: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将 托盘的位置信息添加到配方中
- //手动控制电机轴 DB5.DBX4.6~DB5.DBX5.2
- 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>((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.ShowRunLog($"原料:{recipe.Material[i].Material_Name},不在配料表");
- }
- }
- 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.Register(new Action<Object>((res) =>
- {
- if (res != null && res is RemoteRecipeData recipe)
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.Add(recipe);
- }
- }), "LocalSimulationRecipeIssue", true);
-
- //手动控制系统模式
- 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(() =>
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.Clear();
- GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 0;
-
- GVL_SmallStation.GetInstance.WindSendDosingStatus = 0;
- GVL_SmallStation.GetInstance.WindSendDosing = false;
-
- GVL_SmallStation.GetInstance.Order_Cancel = false;
- GVL_SmallStation.GetInstance.Order_CancelRecipeCode = "";
- GVL_SmallStation.GetInstance.OrderCancelStep = 0;
-
- for (int i = 0; i < 5; i++)
- {
- RecipeQueueTray[i].Clear();
- GVL_SmallStation.GetInstance.RecipeProcessStatus[i] = 0;
- GVL_SmallStation.GetInstance.Tray_AGVLogic[i] = 0;
- }
- StockBinInit();
- WindSendReset();
- //for (int i = 0; i < GVL_SmallStation.GetInstance.StockInDosingComple.Length; i++)
- //{
- // GVL_SmallStation.GetInstance.StockInDosingComple[i] = false;
- //}
- MessageNotify.GetInstance.ShowRunLog("系统流程复位,等待西门子重新下发订单");
- }), "BPASystemReset", true);
-
- //往海科PLC写值
- ActionManage.GetInstance.Register(new Action<Object>((o) =>
- {
- if (o != null && o is HKDeviceWrite data)
- {
- if (data.PlcVarType == PlcVarType.Bool)
- {
- bool value = (bool)data.Value;
- HKDevice.HK_PLC_S7.Write<bool>(data.Address, value);
- }
- else if (data.PlcVarType == PlcVarType.Byte)
- {
- byte value = (byte)data.Value;
- HKDevice.HK_PLC_S7.Write<byte>(data.Address, value);
- }
- else if (data.PlcVarType == PlcVarType.Int)
- {
- short value = (short)data.Value;
- HKDevice.HK_PLC_S7.Write<short>(data.Address, value);
- }
- else if (data.PlcVarType == PlcVarType.Dint)
- {
- int value = (int)data.Value;
- HKDevice.HK_PLC_S7.Write<int>(data.Address, value);
- }
- else if (data.PlcVarType == PlcVarType.Real)
- {
- float value = (float)data.Value;
- HKDevice.HK_PLC_S7.Write<float>(data.Address, value);
- }
- }
- }), "PLCWrite", true);
-
- //电机速度
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBW8", value);
- }
- }), "AxisLoadSpeedSet", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBW10", value);
- }
- }), "AxisMidSpeedSet", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short value)
- {
- HKDevice.HK_PLC_S7.Write("DB47.DBW12", 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);
-
- //机器人的操作
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is string address)
- {
- HKDevice.HK_PLC_S7.Write(address, true);
- }
- }), "RobotSendTrueCommand", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is string address)
- {
- HKDevice.HK_PLC_S7.Write(address, false);
- }
- }), "RobotSendFalseCommand", true);
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o != null && o is short Value)
- {
- HKDevice.HK_PLC_S7.Write("DB4.DBB1", (byte)Value);
- }
- }), "RobotSetProgramNum", true);
-
- }
- public void DeviceConnect()
- {
- try
- {
- if (Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
- {
- HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
- if (HKDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科plc连接成功");
- }
- }
- catch (Exception ex)
- {
- MessageNotify.GetInstance.ShowAlarmLog("海科plc连接失败,等待重新连接");
- }
- finally
- {
- HKDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("海科plc初始化完成");
- }
- try
- {
- if (Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
- {
- SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- if (SiemensDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("西门子plc连接成功");
- }
- }
- catch (Exception ex)
- {
- MessageNotify.GetInstance.ShowAlarmLog("西门子plc连接失败,等待重新连接");
- }
- finally
- {
- SiemensDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("西门子plc初始化完成");
- }
- try
- {
- if (Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
- {
- WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
- if (WindSendDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("风送plc连接成功");
- }
- }
- catch (Exception ex)
- {
- MessageNotify.GetInstance.ShowAlarmLog("粉料plc连接失败,等待重新连接");
- }
- finally
- {
- WindSendDevice.Init();
- MessageNotify.GetInstance.ShowRunLog("风送粉料plc初始化完成");
- }
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- try
- {
- if (!HKDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.HKPlcConnect)
- {
- HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S71200, HK_PLC_IP);
- if (HKDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("海科PLC重新连接成功");
- }
- }
- catch (Exception ex)
- {
- }
- try
- {
- if (!SiemensDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.SiemensConnect)
- {
- SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- if (SiemensDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("西门子PLC重新连接成功");
- }
- }
- catch (Exception ex)
- {
- }
- try
- {
- if (!WindSendDevice.IsConnected && Json<DevicePar>.Data.deviceConnectPar.WindSendConnect)
- {
- WindSendDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71200, WindSend_PLC_IP);
- if (WindSendDevice.IsConnected) MessageNotify.GetInstance.ShowRunLog("风送plc重新连接成功");
- }
- }
- catch (Exception ex)
- {
- }
- Thread.Sleep(50);
- }), "设备连接", true);
- }
-
- 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 WindSendReset()
- {
- float weight = (float)0.0;
- WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD0", weight);
- WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD4", weight);
- WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD8", weight);
- WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD12", weight);
- WindSendDevice.Siemens_PLC_S7.Write("DB95.DBD16", weight);
- WindSendDevice.Siemens_PLC_S7.Write("DB95.DBX38.1", false);
- }
- public void RawMaterialNameWithCode()
- {
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.Clear();
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0001", "色拉油");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0002", "一级菜油");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0003", "菜籽油");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0004", "青花椒油");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0005", "卤牛肉丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0006", "冻鸡肉丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0007", "香菇丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0008", "高水分糍粑海椒");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0009", "低水分糍粑海椒");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0010", "辣豆瓣");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0011", "整豆豉");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0012", "豆豉细粒");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0013", "卤黄豆");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0014", "野山椒粒");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0015", "竹笋丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0016", "香辣酱辣椒酱");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0017", "芽菜粒");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0018", "榨菜丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0019", "盐菜");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0020", "洋葱丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0021", "番茄酱");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0022", "甜豆瓣");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0023", "甜面酱");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0024", "芝麻酱");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0025", "炸花生");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0026", "盐渍青椒丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0027", "备料剁红椒");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0028", "萝卜丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0029", "油芝麻");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0030", "生姜");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0031", "大蒜");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0032", "榨菜酱");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0033", "炸碗豆");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0034", "大头菜丁");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0035", "酱油");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0036", "I+G");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0037", "味精");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0038", "白糖");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0039", "食盐");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0040", "花椒酱");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0041", "调味膏2");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0042", "调味膏5");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0043", "十三香调味膏");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0044", "酱香膏");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0045", "芽菜香料粉");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0046", "香料A");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0047", "香料D");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0048", "猪肉精膏");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0049", "调味膏3");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0050", "柠檬酸粉");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0051", "辣椒红");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0052", "辣椒油树脂");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0053", "水态混和酸");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0054", "加水稀释后防腐剂");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0055", "异维C钠粉");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0056", "琼脂粉");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0057", "香葱油");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0058", "水态甜味剂");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0059", "孜然粉");
- GVL_SmallStation.GetInstance.RawMaterialsNameCode.TryAdd("0060", "孜然油");
- }
- }
- }
|