generated from wenjy/Sln.Iot
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.
103 lines
3.3 KiB
C#
103 lines
3.3 KiB
C#
using CFX;
|
|
using CFX.Structures.UVCuring;
|
|
using Sln.Iot.CFX.CFXConnect;
|
|
using Sln.Iot.CFX.Event;
|
|
using Sln.Iot.PLC;
|
|
using Sln.Iot.Serilog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sln.Iot.Business
|
|
{
|
|
/// <summary>
|
|
/// 配方支持类
|
|
/// </summary>
|
|
public class RecipeBusiness
|
|
{
|
|
private Timer _timer;
|
|
|
|
private readonly PLCConnect _plc = PLCConnect.Instance;
|
|
private readonly SerilogHelper _log = SerilogHelper.Instance;
|
|
|
|
private readonly RecipeActivatedEvent recipeActivatedEvent = new RecipeActivatedEvent();
|
|
private readonly RecipeModifiedEvent recipeModifiedEvent = new RecipeModifiedEvent();
|
|
|
|
private readonly CFXConnect1 connect1 = CFXConnect1.Instance;
|
|
|
|
public RecipeBusiness()
|
|
{
|
|
_timer = new Timer(TimerCallback, null, 0, 1500);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测配方变化
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
public void TimerCallback(object? state)
|
|
{
|
|
string recipeName = "recipeName";
|
|
|
|
var changeResult1 = _plc.ReadBool(_plc.DeltaInstance1, "M281");
|
|
var changeResult2 = _plc.ReadBool(_plc.DeltaInstance2, "M281");
|
|
var activeResult1 = _plc.ReadBool(_plc.DeltaInstance1, "M280");
|
|
var activeResult2 = _plc.ReadBool(_plc.DeltaInstance2, "M280");
|
|
|
|
if(changeResult1.Content || changeResult2.Content || activeResult1.Content || activeResult2.Content)
|
|
{
|
|
//获取现在激活的配方
|
|
var res = _plc.ReadBytes(_plc.DeltaInstance1, "D600", 10);
|
|
if (res.IsSuccess)
|
|
{
|
|
recipeName = Encoding.ASCII.GetString(res.Content);
|
|
}
|
|
}
|
|
|
|
if (changeResult1.IsSuccess)
|
|
{
|
|
if (changeResult1.Content)
|
|
{
|
|
//发布消息
|
|
connect1.PublishEvent(new CFXEnvelope(recipeModifiedEvent.Handle(recipeName)));
|
|
_log.Info($"真空箱1配方修改{recipeName}");
|
|
}
|
|
}
|
|
|
|
if (changeResult2.IsSuccess)
|
|
{
|
|
if (changeResult2.Content)
|
|
{
|
|
//发布消息
|
|
connect1.PublishEvent(new CFXEnvelope(recipeModifiedEvent.Handle(recipeName)));
|
|
_log.Info($"真空箱2配方修改{recipeName}");
|
|
}
|
|
}
|
|
|
|
if (activeResult1.IsSuccess)
|
|
{
|
|
if (activeResult1.Content)
|
|
{
|
|
//发布消息
|
|
connect1.PublishEvent(new CFXEnvelope(recipeActivatedEvent.Handle(recipeName, "VacuumInjection1", 1)));
|
|
_log.Info($"真空箱1配方激活{recipeName}");
|
|
}
|
|
}
|
|
|
|
if (activeResult2.IsSuccess)
|
|
{
|
|
if (activeResult2.Content)
|
|
{
|
|
//发布消息
|
|
connect1.PublishEvent(new CFXEnvelope(recipeActivatedEvent.Handle(recipeName, "VacuumInjection2", 2)));
|
|
_log.Info($"真空箱2配方激活{recipeName}");
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|