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.

184 lines
7.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.Windows.Forms;
using System.Xml.Schema;
using Timer = System.Threading.Timer;
namespace HighWayIot.Winform.Business
{
/// <summary>
/// 排程信号业务类
/// </summary>
public class RecipeSendBusiness
{
private Timer GetSchedulingTimer;
private RecipeSignal recipeSignal = new RecipeSignal();
private ZxSchedulingService zxSchedulingService = ZxSchedulingService.Instance;
private ZxRecipeParaService zxRecipeParaService = ZxRecipeParaService.Instance;
private ZxRecipePositionParaService zxRecipePositionParaService = ZxRecipePositionParaService.Instance;
private RecipeParaHelper recipeParaHelper = new RecipeParaHelper();
public static bool RecipeSendMode = false;
public static string NowRecipeCode = string.Empty;
public static string NowDeviceNo = string.Empty;
public RecipeSendBusiness()
{
GetSchedulingTimer = new Timer(new System.Threading.TimerCallback(ReadSignal), null, 0, 1500);
}
/// <summary>
/// 重复读取
/// </summary>
/// <param name="o"></param>
public void ReadSignal(object o)
{
//读取是True的点位
Dictionary<int, bool> a = recipeSignal.ReadSchedulingSignal();
if (a == null)
{
return;
}
int destinationVulcanizationNo;
var ares = a.Where(x => x.Value == true).ToList();
if (ares.Count == 1)
{
destinationVulcanizationNo = ares[0].Key;
}
else
{
if (ares.Count > 1)
{
LogHelper.Instance.Error($"排程信号True值不唯一 {string.Join(", ", ares.Select(x => x.Key).ToList())}");
}
return;
}
if (RecipeSendMode) //通过MES下配方
{
//读同步数据库找到等于0的
List<ZxMesPlanTransferEntity> transferEntity = ZxMesPlanTransferService.Instance.GetRecipeInfos(x => x.RequestFlag == false).ToList();
if (transferEntity.Count > 1)
{
LogHelper.Instance.Error($"标识同步数据不唯一,请检查数据库,当前数量:{transferEntity.Count}");
return;
}
if (transferEntity.Count == 0)
{
LogHelper.Instance.Error("配方下发请求不存在,请检查数据库");
return;
}
//同步到配方(配方和称量,如果是新的加字段)
//////////////////////////////更新配方表/////////////////////////////////
//var newEneitys = RecipeLists.Where(x => x.RecipeCode == newRecipes.RecipeCode).ToList();
//if (newEneitys.Count > 0) //有就更新
//{
// //配方
// newEneitys[0].RecipeSpecCode = newRecipes.SpecCode;
// newEneitys[0].RecipeSpecName = newRecipes.SpecName;
// newEneitys[0].SizeKind = newRecipes.RimInch;
// newEneitys[0].FixedWidth = newRecipes.FixRubWidth;
// if (!zxRecipeService.UpdateRecipeInfo(newEneitys[0]))
// {
// return;
// }
//}
//else //没有就插入
//{
// ZxRecipeEntity entity = new ZxRecipeEntity()
// {
// RecipeName = newRecipes.RecipeName,
// RecipeCode = newRecipes.RecipeCode,
// RecipeSpecCode = newRecipes.SpecCode,
// RecipeSpecName = newRecipes.SpecName,
// SizeKind = newRecipes.RimInch,
// FixedWidth = newRecipes.FixRubWidth,
// IsUse = true,
// IsDeleted = false,
// };
// zxRecipeService.InsertRecipeInfo(entity);
//}
//同步到对应硫化排程的界面
//后续流程相同
}
else //手动下配方
{
var schedulingInfo = zxSchedulingService.GetSchedulingInfo();
string recipeNo;
ZxRecipeParaEntity recipeParaInfo;
List<ZxRecipePositionParaEntity> zxRecipePositionParaEntities;
if ((destinationVulcanizationNo + 1) <= 62)
{
recipeNo = schedulingInfo.Single(x => x.Id == destinationVulcanizationNo + 1).RecipeCode1;
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{(destinationVulcanizationNo + 0x901).ToString("X")}", false, DataTypeEnum.Bool);
int deviceNo = schedulingInfo.Single(x => x.Id == destinationVulcanizationNo + 1).DeviceNo ?? 0;
//MonitorInsert(recipeNo, $"{deviceNo}上模");
LogHelper.Instance.Info($"配方上传成功,配方号:{recipeNo},模具号:{deviceNo}上模");
NowRecipeCode = recipeNo;
NowDeviceNo = deviceNo + "-2";
}
else
{
LogHelper.Instance.Error("配方上传失败检查PLC连接");
return;
}
}
else
{
recipeNo = schedulingInfo.Single(x => x.Id == destinationVulcanizationNo + 1 - 62).RecipeCode2;
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{(destinationVulcanizationNo - 62 + 0x941).ToString("X")}", false, DataTypeEnum.Bool);
int deviceNo = schedulingInfo.Single(x => x.Id == destinationVulcanizationNo + 1 - 62).DeviceNo ?? 0;
//MonitorInsert(recipeNo, $"{deviceNo}下模");
LogHelper.Instance.Info($"配方上传成功,配方号:{recipeNo},模具号:{deviceNo}下模");
NowRecipeCode = recipeNo;
NowDeviceNo = deviceNo + "-1";
}
else
{
LogHelper.Instance.Error("配方上传失败检查PLC连接");
return;
}
}
}
}
}
}