using BPASmartClient.Helper; using BPASmartClient.Modbus; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using BPASmartClient.S7Net; using System.Threading; namespace BPASmartClient.JXJFoodSmallStation.Model.Siemens { public class SiemensDeviceStatus { public SiemensHelper Siemens_PLC_S7 = new SiemensHelper(); public bool IsConnected => Siemens_PLC_S7.IsConnected; public XL_Status_DB XL_Status = new XL_Status_DB(); bool test; public void Init() { if (IsConnected) { ThreadManage.GetInstance().StartLong(new Action(() => { var Start = this.Siemens_PLC_S7.ReadClass(2201); var Status = this.Siemens_PLC_S7.ReadClass(2231); var Finish = this.Siemens_PLC_S7.ReadClass(2261); var DataColl = this.Siemens_PLC_S7.ReadClass(2291); if (Start != null && Start is XL_Start_DB st) { if (RTrig.GetInstance("DB2201.DBX450.0").Start(GVL_SmallStation.IsAllowSiemensSendRecipe) && GVL_SmallStation.SiemensSendRecipeStatus == 0) { GVL_SmallStation.SiemensSendRecipeStatus = 1; this.Siemens_PLC_S7.Write("DB2201.DBX450.0", true); } if (RTrig.GetInstance("Order_Request_ACK").Start(Start.Order_Request_ACK) && GVL_SmallStation.SiemensSendRecipeStatus == 1) { if (!string.IsNullOrEmpty(st.RecipeCode)) { GVL_SmallStation.SiemensSendRecipeStatus = 2; ActionManage.GetInstance.Send("SiemensRecipeRecive", st); this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false); } } if (TTrig.GetInstance("Order_Request_ACK_").Start(Start.Order_Request_ACK) && GVL_SmallStation.SiemensSendRecipeStatus == 2) { GVL_SmallStation.IsAllowSiemensSendRecipe = false; GVL_SmallStation.SiemensSendRecipeStatus = 3; //需要等待请求信号复位才能认为接收配方完成 } } if (Finish != null && Finish is XL_Finish_DB FinishData) { if (RTrig.GetInstance("Ask_For_Finish_PLC").Start(FinishData.Ask_For_Finish_PLC) && GVL_SmallStation.SiemensSendRecipeStatus == 7) { FinishData.Order_No = ""; FinishData.Product_Code = ""; FinishData.Job_No = 0; for (int i = 0; i < 20; i++) { FinishData.Material[i] = new UDT1(); } for (int i = 0; i < 10; i++) { FinishData.Powder[i] = new UDT2(); } GVL_SmallStation.SiemensSendRecipeStatus = 0; FinishData.Ask_For_Finish = false; FinishData.DosingTime = 0; this.Siemens_PLC_S7.WriteClass(FinishData, 2261); } } if (Status != null && Status is XL_Status_DB state) { for (int i = 0; i < XL_Status.Powder.Length; i++) { XL_Status.Powder[i] = new PowderStatus(); } XL_Status = state; if (RTrig.GetInstance("Allow_AGV_Put[0]").Start(Status.AgvRequestPut)) { ActionManage.GetInstance.Send("AGV放货架到位", Status); Status.AgvRequestPut = false; this.Siemens_PLC_S7.WriteClass(Status, 2); } } if (Status != null && RTrig.GetInstance("Allow_AGV_Put[1]").Start(Status.AgvRequestGet)) { ActionManage.GetInstance.Send("AGV取货架到位", Status); Status.AgvRequestGet = false; this.Siemens_PLC_S7.WriteClass(Status, 2); } Thread.Sleep(10); }),"监听服务数据"); } } } }