using HighWayIot.Log4net; using HighWayIot.Plc; using HighWayIot.Plc.PlcHelper; using HighWayIot.Repository.domain; using HighWayIot.Repository.service; using Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Schema; using Timer = System.Threading.Timer; namespace HighWayIot.Winform.Business { /// /// 排程信号业务类 /// public class RecipeSendBusiness { Timer GetSchedulingTimer; RecipeSignal recipeSignal = new RecipeSignal(); ZxSchedulingService zxSchedulingService = ZxSchedulingService.Instance; ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance; ZxRecipePositionParaService zxRecipePositionParaService = ZxRecipePositionParaService.Instance; RecipeParaHelper recipeParaHelper = new RecipeParaHelper(); public RecipeSendBusiness() { //GetSchedulingTimer = new Timer(new System.Threading.TimerCallback(ReadSignal), null, 0, 1000); } /// /// 重复读取 /// /// public void ReadSignal(object o) { Dictionary a = recipeSignal.ReadSchedulingSignal(); if(a == null) { return; } foreach (var item in a) { if (item.Value) { var schedulingInfo = zxSchedulingService.GetSchedulingInfo(); string recipeNo; ZxRecipeParaEntity recipeParaInfo; List zxRecipePositionParaEntities; if ((item.Key + 1) < 63) { recipeNo = schedulingInfo.Single(x => x.Id == item.Key + 1).RecipeNo1; recipeParaInfo = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(recipeNo).FirstOrDefault(); zxRecipePositionParaEntities = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.RecipeCode == recipeNo); if (recipeParaInfo == null) { LogHelper.Instance.Error("配方信息获取失败"); return; } if (recipeParaHelper.UploadToPLC(recipeParaInfo, zxRecipePositionParaEntities)) { PlcConnect.PlcWrite2($"B{(item.Key + 0x901).ToString("X")}", false, DataTypeEnum.Bool); MonitorInsert(recipeNo); } } else { recipeNo = schedulingInfo.Single(x => x.Id == item.Key + 1).RecipeNo2; recipeParaInfo = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(recipeNo).FirstOrDefault(); zxRecipePositionParaEntities = zxRecipePositionParaService.GetRecipePositionParaInfos(x => x.RecipeCode == recipeNo); if (recipeParaInfo == null) { LogHelper.Instance.Error("配方信息获取失败"); return; } if (recipeParaHelper.UploadToPLC(recipeParaInfo, zxRecipePositionParaEntities)) { PlcConnect.PlcWrite2($"B{(item.Key + 0x941).ToString("X")}", false, DataTypeEnum.Bool); MonitorInsert(recipeNo); } } return; } } } /// /// 监控画面信息插入 /// public void MonitorInsert(string recipeCode) { } } }