using Aurora; using Aurora.Api; using Aurora.Api.Manager; using Aurora.Util.HislogPlus; using Aurora.View; using CoreUnit.Control.UserControl.Canvas; using CoreUnit.Scanner.UserControl.ScannerCanvas; using GUI; using ILSOS_KS.Device; using ILSOS_KS.Sequences; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using WeldingCommon; using WeldingCommon.Devices; using WeldingCommon.Recipes; using static ILSOS_KS.Device.PLCControllerKS; namespace ILSOS_KS.Recipes { // Recipe 의 상태 변경(EVENT_RECIPE_CHANGE_REQUEST <-> EVENT_AUTO_RUN_START_REQUEST) 등 장비별로 다르게 처리해야 하는 Recipe 관련 Event 처리 // 추가로 SYS_RECIPE_ACTIVATED 에서 처리가 다르게 이루어져야 할 수도 있음. 확장 가능하도록 사용성 열어둠 internal class RecipeEventHelper { public static bool RecipeChange = false; internal static void ExternalRecipeUpdate(Logger Log, IAuroraEnvironment aurora) { Log.I("ExternalRecipeUpdate "); } internal static bool KS_RecipeChangeRequest(Logger Log, IAuroraEnvironment aurora) { var plc = aurora.DeviceManager[CommonDeviceIds.PLCDevice] as PLCController; short recipeRequestId = (short)plc.ReadDWord((int)eWordInput.PLC_RECIPE_NO).data; Log.I(string.Format($"[PLCInterface]Get PLC_RECIPE_NO {recipeRequestId}")); Status.GetProcessingWeldingData().ChangeRequest = recipeRequestId.ToString(); SeqAutoRunKS ks = aurora.SequenceEntry[SequenceIds.SeqAutoRunKS_New] as SeqAutoRunKS; //Log.I("================================================================================="); //Log.I("KS_RecipeChangeRequest Start...."); Status.GetProcessingWeldingData().ActRecipe = $"RecipeChange {recipeRequestId} ..."; bool auto = plc.ReadBit((int)eBitInput.PLC_AUTO_STATUS).data; if (auto) { var recipeName = WeldingRecipeManager.SearchRecipeItem(recipeRequestId); if (recipeName != "") { //Status.GetProcessingWeldingData().ActRecipe = recipeName; //WeldingRecipeManager.OnActiveRecipe(recipeRequestId, recipeName); //WeldingRecipeManager.OnActiveReloaded(); //Log.I(string.Format($"[PLCInterface]Set ActiveReloaded {recipeRequestId} : {recipeName}")); //MessageUtil.ShowSuccessToast($"{recipeName} 레시피 변경 하였습니다."); RecipeChange = true; } else { //MessageUtil.ShowErrorToast(string.Format("{0}", "Recipe List에 해당 Recipe No.가 없습니다.")); //Log.E($"The requested Recipe No.{recipeRequestId} is not in the Recipe List."); //Log.I("================================================================================="); RecipeChange = false; return false; } //Log.I("Complete OnRecipeChangeRequest"); //Log.I("================================================================================="); return true; } return true; } internal static void KS_RecipeChangeComplete(Logger Log, IAuroraEnvironment aurora) { var plc = aurora.DeviceManager[CommonDeviceIds.PLCDevice] as PLCController; //if (RecipeChange) //{ // int activatedRecipeId = aurora.RecipeManager.ActivatedRecipe().Id; // Log.I(string.Format($"[PLCInterface]Get PLC_RECIPE_NO {activatedRecipeId}")); // plc.WriteWord((int)eWordOutput.PC_RECIPE_NO, (short)activatedRecipeId); // Log.I(string.Format($"[PLCInterface]Set PC_RECIPE_NO {activatedRecipeId}")); // plc.WriteBit((int)eBitOutput.PC_RECIPE_CHANGE_COMPLETE, true); // Log.I(string.Format($"[PLCInterface]Set PC_RECIPE_CHANGE_COMPLETE True")); //} short recipeRequestId = (short)plc.ReadDWord((int)eWordInput.PLC_RECIPE_NO).data; plc.WriteWord((int)eWordOutput.PC_RECIPE_NO, recipeRequestId); Thread.Sleep(100); plc.WriteBit((int)eBitOutput.PC_RECIPE_CHANGE_COMPLETE, true); TimeSpan spanTime; DateTime startTime = DateTime.Now; int timeOut = 10; while (true) { spanTime = DateTime.Now.Subtract(startTime); //if (!_Plc.GetDIStatus("PLC_RECIPE_CHANGE_REQ")) if (!plc.ReadBit((int)eBitInput.PLC_RECIPE_CHANGE_REQ).data) { Log.I(string.Format($"[PLCInterface]Set PLC_RECIPE_CHANGE_REQ False")); break; } if (spanTime.TotalMilliseconds > (timeOut * 1000)) { Log.I(string.Format($"[PLCInterface]Set PLC_RECIPE_CHANGE_REQ Time Out")); break; } } //_Plc.SetDOStatus("PC_RECIPE_CHANGE_COMPLETE", false); plc.WriteBit((int)eBitOutput.PC_RECIPE_CHANGE_COMPLETE, false); Log.I(string.Format($"[PLCInterface]Set PC_RECIPE_CHANGE_COMPLETE False")); } } }