You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.9 KiB
C#

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
{
/// <summary>
/// 排程信号业务类
/// </summary>
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);
}
/// <summary>
/// 重复读取
/// </summary>
/// <param name="o"></param>
public void ReadSignal(object o)
{
Dictionary<int, bool> a = recipeSignal.ReadSchedulingSignal();
if(a == null)
{
return;
}
foreach (var item in a)
{
if (item.Value)
{
var schedulingInfo = zxSchedulingService.GetSchedulingInfo();
string recipeNo;
ZxRecipeParaEntity recipeParaInfo;
List<ZxRecipePositionParaEntity> 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;
}
}
}
/// <summary>
/// 监控画面信息插入
/// </summary>
public void MonitorInsert(string recipeCode)
{
}
}
}