|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Helper;
- using BPASmartClient.JXJFoodBigStation.Model.HK_PLC;
- using BPASmartClient.JXJFoodBigStation.Model.Siemens;
- 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.JXJFoodBigStation.Model
- {
- public class ProcessControl
- {
- private volatile static ProcessControl _Instance;
- public static ProcessControl GetInstance => _Instance ?? (_Instance = new ProcessControl());
- private ProcessControl() { }
-
- public ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
- public SiemensDeviceStatus SiemensDevice = new SiemensDeviceStatus();
- public HKDeviceStatus HKDevice = new HKDeviceStatus();
- GVL_BigStation BigStation = new GVL_BigStation();
- /// <summary>
- /// 接收原料数据
- /// </summary>
- public RecipeRawMaterial RawMaterial;
- public void Init()
- {
- ActionManage.GetInstance.Register(new Action(() =>
- {
- if (SiemensDevice.IsConnected)
- {
- var res = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeName);
- var res1 = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeID);
- int res2 = SiemensDevice.Siemens_PLC_S7.ReadClass(RawMaterial, 0, 0);
- if ((res != null && res is string recipeName) &&
- (res1 != null && res1 is uint recipeID) &&
- (res2 > 0))
- {
- int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeID);
- if (!(index >= 0))
- {
- RawMaterials.Clear();
- for (int i = 0; i < 15; i++)
- {
- RawMaterials.Add(new RemoteRecipeRawMaterial()
- {
- RawMaterialBarrelNum = RawMaterial.RawMaterialBarrelNum[i],
- RawMaterialLocation = RawMaterial.RawMaterialLocation[i],
- RawMaterialWeight = RawMaterial.RawMaterialWeight[i]
- });
- }
- Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
- {
- RecipeName = recipeName,
- RecipeCode = recipeID,
- RawMaterial = RawMaterials
- });
- }
- else
- {
- MessageLog.GetInstance.AlarmLog("配方列表中存在该配方ID");
- }
- }
- }
- }), "西门子下发配方", true);
- ActionManage.GetInstance.Register(new Action(() =>
- {
- if (SiemensDevice.IsConnected)
- {
- var res = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.TrayLocationNum);
- var res1 = SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.RecipeID);
- if (res != null && res is int TrayLocation && res1 != null && res1 is int recipeId)
- {
- int index = Array.FindIndex(Json<RemoteRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeId);
- if (index >= 0 && index < Json<RemoteRecipeDataColl>.Data.Recipes.Count)
- {
- Json<RemoteRecipeDataColl>.Data.Recipes.ElementAt(index).TrayCode = TrayLocation;
- }
- }
- }
- }), "AGV到位信号", true);//根据下发的配方ID将 托盘的位置信息添加到配方中
- string HK_PLC_IP = ConfigurationManager.AppSettings["HKPlc_IP"];
- string Siemens_PLC_IP = ConfigurationManager.AppSettings["Siemens_IP"];
- try
- {
- //HKDevice.HK_PLC_S7.Connect(S7.Net.CpuType.S7200Smart, HK_PLC_IP);
- //SiemensDevice.Siemens_PLC_S7.Connect(S7.Net.CpuType.S71500, Siemens_PLC_IP);
- if (HKDevice.IsConnected)
- {
- HKDevice.Init();
- }
- if (SiemensDevice.IsConnected)
- {
- SiemensDevice.Init();
- }
- }
- catch(Exception ex)
- {
-
- }
- BigStation.RecipeQueue.Clear();
- Json<RemoteRecipeDataColl>.Data.Recipes = TestData.GetInstance.Recipes;//添加测试数据
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- ReceviceData();
- RecipeInfoToHKPLC();
- Thread.Sleep(10);
- }), "流程处理", true);
- ThreadManage.GetInstance().StartLong(new Action(() => {
- if (HKDevice.IsConnected && SiemensDevice.IsConnected)
- {
- AgvGetInDelivery();
- AgvGetInPickUp();
- }
- Thread.Sleep(10);
- }), "AGV进站送取货", true);
- }
- /// <summary>
- /// AGV进站送货
- /// </summary>
- private void AgvGetInDelivery()
- {
-
- switch (BigStation.AgvDeliveryPosition)
- {
- case 0:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApply) is bool))
- {
- BigStation.AgvDeliveryPosition = 1;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApply, true);
- }
- break;
- case 1:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApply) is bool))
- {
- BigStation.AgvDeliveryPosition = 2;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApply, true);
- }
- break;
- case 2:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVApplyJack) is bool))
- {
- BigStation.AgvDeliveryPosition = 3;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVApplyJack, true);
- }
- break;
- case 3:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.DeliveryAGVIsApplyJack) is bool))
- {
- BigStation.AgvDeliveryPosition = 4;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.DeliveryAGVIsApplyJack, true);
- }
- break;
- case 4:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.DeliveryAGVFinsih) is bool))
- {
- BigStation.AgvDeliveryPosition = 5;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.DeliveryAGVFinsih, true);
- }
- break;
- case 5:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationHaveCargo) is bool))
- {
- BigStation.AgvDeliveryPosition = 0;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationHaveCargo, true);
- }
- break;
- default:
- break;
- }
- //获取工位上是否有小车
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.StationIsExistCar, (bool)
- HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.StationIsExistCar));
- }
- /// <summary>
- /// AGV进站取货
- /// </summary>
- private void AgvGetInPickUp()
- {
- switch (BigStation.AgvPickUpPosition)
- {
- case 0:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickAGVApply) is bool))
- {
- BigStation.AgvPickUpPosition = 1;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickAGVApply, true);
- }
- break;
- case 1:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVIsApply) is bool))
- {
- BigStation.AgvPickUpPosition = 2;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVIsApply, true);
- }
- break;
- case 2:
- if (RTrig.GetInstance("").Start(SiemensDevice.Siemens_PLC_S7.Read(SiemensCommAddress.PickCargoAGVFinish) is bool))
- {
- BigStation.AgvPickUpPosition = 3;
- HKDevice.HK_PLC_S7.Write(HKPlcCommAddress.PickCargoAGVFinish, true);
- }
- break;
- case 3:
- if (RTrig.GetInstance("").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.PickAGVFinish) is bool))
- {
- BigStation.AgvPickUpPosition = 0;
- SiemensDevice.Siemens_PLC_S7.Write(SiemensCommAddress.PickAGVFinish, true);
- }
- break;
- default:
- break;
- }
- }
- private void ReceviceData()
- {
- BigStation.RemoteRecipes = Json<RemoteRecipeDataColl>.Data.Recipes;
- if (Json<RemoteRecipeDataColl>.Data.Recipes.Count > 0)
- {
- foreach (var data in Json<RemoteRecipeDataColl>.Data.Recipes)
- {
- if(!(BigStation.RecipeQueue.Contains(data.RecipeCode)))
- BigStation.RecipeQueue.Enqueue(data.RecipeCode);
- }
- }
- }
- private void RecipeInfoToHKPLC()
- {
- if (BigStation.RecipeQueue.Count > 0)
- {
- int index = Array.FindIndex(BigStation.RemoteRecipes.ToArray(), p => p.RecipeCode == BigStation.RecipeQueue.ElementAt(0));
- if (index >= 0 && index <= BigStation.RemoteRecipes.Count)
- {
- long code = BigStation.RemoteRecipes.ElementAt(index).RecipeCode;
- if (RTrig.GetInstance("IsAllowDosing").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.IsAllowDosing) is bool a))
- {
- foreach (var item in BigStation.RemoteRecipes.ElementAt(index).RawMaterial)
- {
- HKDevice.StockBinPar((uint)item.RawMaterialBarrelNum, (ushort)item.RawMaterialLocation);
- }
- HKDevice.AllowDosingSignReset();
- BigStation.IssueRecipeFinish = true;
- }
- if (RTrig.GetInstance("StockState").Start(HKDevice.HK_PLC_S7.Read(HKPlcCommAddress.RecipeDosingFinish) is bool))
- {
- HKDevice.RecipeDosingFinishReset();
- BigStation.RecipeQueue.TryDequeue(out code);
- Json<RemoteRecipeDataColl>.Data.Recipes.RemoveAt(index);//制作完成,移除当前配方
- }
- }
- }
- }
- }
- }
|