using BPA.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; using BPASmartClient.CustomResource.Pages.Model; 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(); public XL_DataColl_DB DataColl = new XL_DataColl_DB(); public void Init() { TaskManage.GetInstance.StartLong(new Action(() => { if (IsConnected) { 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) { switch (GVL_SmallStation.GetInstance.SiemensSendRecipeStatus) { case 0: if (GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe) { this.Siemens_PLC_S7.Write("DB2201.DBX450.0", true); GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 1; } else { this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false); } break; case 1: if (st.Order_Request_ACK) { if (!string.IsNullOrEmpty(st.RecipeCode)) { GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 2; ActionManage.GetInstance.Send("SiemensRecipeRecive", st); this.Siemens_PLC_S7.Write("DB2201.DBX450.0", false); } } break; case 2: if (Start.Order_Request_ACK == false) { GVL_SmallStation.GetInstance.IsAllowSiemensSendRecipe = false; GVL_SmallStation.GetInstance.SiemensSendRecipeStatus = 3; } break; } if (RTrig.GetInstance("Order_Cancel").Start(st.Order_Cancel)) //订单取消 { if (GVL_SmallStation.GetInstance.Order_Cancel == false) { GVL_SmallStation.GetInstance.Order_Cancel = true; GVL_SmallStation.GetInstance.Order_CancelRecipeCode = st.RecipeCode; GVL_SmallStation.GetInstance.OrderCancelStep = 0; MessageNotify.GetInstance.ShowRunLog($"西门子下发取消工单指令:{st.RecipeName}"); } else { MessageNotify.GetInstance.ShowRunLog($"订单正在取消,请等待订单{ GVL_SmallStation.GetInstance.Order_CancelRecipeCode}取消完成,再取消订单:{st.RecipeName}"); } } } if (Finish != null && Finish is XL_Finish_DB FinishData) { if (FinishData.Ask_For_Finish_PLC) { 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(); } 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; } //从海科plc的数采 发送给西门子plc var res = ProcessControl.GetInstance.HKDevice.DeviceStatus; if (res != null) { DataColl.HeartBeatWithPLC = res.HeartBeat; DataColl.SystemStart = res.DeviceRun; DataColl.SystemStop = res.DeviceStop; DataColl.SystemPause = res.DevicePause; DataColl.SystemEStop = res.DeviceEStop; DataColl.Mode = res.Mode; DataColl.Alarm = res.Alarm; this.Siemens_PLC_S7.WriteClass(DataColl, 2291); } } Thread.Sleep(10); }),"监听服务数据",true); } } }