|
- 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.JXJFoodBigStation.Model.Siemens
- {
- public class SiemensDeviceStatus
- {
- public SiemensHelper Siemens_PLC_S7 = new SiemensHelper();
- public bool IsConnected => Siemens_PLC_S7.IsConnected;
-
- public DL_Status_DB DL_Status = new DL_Status_DB();
- bool printFirstLog = false;
- public void Init()
- {
- TaskManage.GetInstance.StartLong(new Action(() =>
- {
- if (IsConnected)
- {
- var res = this.Siemens_PLC_S7.ReadClass<DL_Start_DB>(2301);
- var res1 = this.Siemens_PLC_S7.ReadClass<DL_Status_DB>(2331);
- var res2 = this.Siemens_PLC_S7.ReadClass<DL_Finish_DB>(2361);
- //var res3 = this.Siemens_PLC_S7.ReadClass<DL_DataColl_DB>(2391);
- if (res != null && res is DL_Start_DB start)
- {
- if (GVL_BigStation.SiemensSendRecipeStatus == 0)
- {
- if (GVL_BigStation.Order_Request)
- {
- this.Siemens_PLC_S7.Write("DB2301.DBX330.0", true);
- MessageNotify.GetInstance.ShowRunLog($"向西门子请求订单");
- GVL_BigStation.SiemensSendRecipeStatus = 1;
- }
- else
- {
- this.Siemens_PLC_S7.Write("DB2301.DBX330.0", false);
- if (!printFirstLog)
- {
- printFirstLog = true;
- MessageNotify.GetInstance.ShowRunLog($"plc不允许下发订单");
- }
- }
- }
- if (RTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack) && GVL_BigStation.SiemensSendRecipeStatus == 1)
- {
- printFirstLog = false;
- ActionManage.GetInstance.Send("SiemensSendRecipe", start);
- this.Siemens_PLC_S7.Write("DB2301.DBX330.0", false);
- MessageNotify.GetInstance.ShowRunLog($"西门子下发订单:{start.RecipeCode}");
- GVL_BigStation.SiemensSendRecipeStatus = 2;
- }
- if (TTrig.GetInstance("Order_Request_Ack").Start(start.Order_Request_Ack) && GVL_BigStation.SiemensSendRecipeStatus == 2)
- {
- GVL_BigStation.Order_Request = false;
- MessageNotify.GetInstance.ShowRunLog($"西门子确认上位机接收到订单:{start.RecipeName}");
- GVL_BigStation.SiemensSendRecipeStatus = 3;
- }
- if (RTrig.GetInstance("Order_Cancel").Start(start.Order_Cancel)) //订单取消
- {
- GVL_BigStation.Order_Cancel = true;
- GVL_BigStation.Order_CancelRecipeCode = start.RecipeCode;
- MessageNotify.GetInstance.ShowRunLog($"西门子下发取消工单指令:{start.RecipeName}");
- }
- }
- if (res1 != null && res1 is DL_Status_DB status)
- {
- DL_Status = status;
- }
- if (res2 != null && res2 is DL_Finish_DB finish)
- {
- if (finish.Ask_For_Finish_PLC &&(GVL_BigStation.Recipe1DosingFinish || GVL_BigStation.Recipe2DosingFinish || GVL_BigStation.Recipe3DosingFinish || GVL_BigStation.Recipe4DosingFinish))
- {
- finish.Order_No = "";
- finish.Product_Code = "";
- finish.job_No = 0;
- for (int i = 0; i < 20; i++)
- {
- finish.Material[i] = new UDT1();
- }
- finish.Ask_For_Finish = false;
- finish.ProcessTime = 0;
- this.Siemens_PLC_S7.WriteClass<DL_Finish_DB>(finish, 2361);
- if (GVL_BigStation.Recipe1DosingFinish) GVL_BigStation.Recipe1DosingFinish = false;
- if (GVL_BigStation.Recipe2DosingFinish) GVL_BigStation.Recipe2DosingFinish = false;
- if (GVL_BigStation.Recipe3DosingFinish) GVL_BigStation.Recipe3DosingFinish = false;
- if (GVL_BigStation.Recipe4DosingFinish) GVL_BigStation.Recipe4DosingFinish = false;
- }
- }
- Thread.Sleep(10);
- var dataColl = ProcessControl.GetInstance.HKDevice.DataColl;
- if (dataColl != null && dataColl is DL_DataColl_DB data)
- {
- Siemens_PLC_S7.WriteClass<DL_DataColl_DB>(data, 2391);
- }
- }
- Thread.Sleep(10);
- }), "西门子数据交互",true);
- }
- }
- }
|