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.
96 lines
3.6 KiB
C#
96 lines
3.6 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
|
|
{
|
|
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;
|
|
}
|
|
|
|
if (a == null)
|
|
{
|
|
LogHelper.Instance.Error("排程信号读取失败");
|
|
}
|
|
|
|
foreach (var item in a)
|
|
{
|
|
if (item.Value)
|
|
{
|
|
var schedulingInfo = zxSchedulingService.GetSchedulingInfo();
|
|
|
|
if ((item.Key + 1) < 63)
|
|
{
|
|
string recipeNo = schedulingInfo.Single(x => x.Id == item.Key + 1).RecipeNo1;
|
|
ZxRecipeParaEntity recipeParaInfo = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(recipeNo).FirstOrDefault();
|
|
List<ZxRecipePositionParaEntity> 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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string recipeNo = schedulingInfo.Single(x => x.Id == item.Key + 1).RecipeNo2;
|
|
ZxRecipeParaEntity recipeParaInfo = zxRecipeParaService.GetRecipeParaInfoByRecipeCode(recipeNo).FirstOrDefault();
|
|
List<ZxRecipePositionParaEntity> 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);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|