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.

133 lines
5.2 KiB
C#

using CFX.InformationSystem.UnitValidation;
using CFX.ResourcePerformance;
using CFX.Structures;
using CFX;
using Sln.Iot.CFX.RequestReceived;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CFX.Production;
using Sln.Iot.CFX.CFXRequestes;
using Sln.Iot.CFX.CFXBusiness;
using Sln.Iot.CFX.Event;
namespace Sln.Iot.CFX.CFXConnect
{
/// <summary>
/// 提升机2连接
/// </summary>
public class CFXConnect4 : CFXHelper
{
private static readonly Lazy<CFXConnect4> lazy = new Lazy<CFXConnect4>(() => new CFXConnect4());
public static CFXConnect4 Instance
{
get
{
return lazy.Value;
}
}
AreYouThereRequestReceived4 areYouThereRequestReceived4 = new AreYouThereRequestReceived4();
GetEndpointInformationRequestReceived4 getEndpointInformationRequestReceived4 = new GetEndpointInformationRequestReceived4();
WhoIsThereRequestReceived4 whoIsThereRequestReceived4 = new WhoIsThereRequestReceived4();
GetActiveRecipeRequestReceived4 getActiveRecipeRequestReceived4 = new GetActiveRecipeRequestReceived4();
GetActiveFaultsRequestReceived4 getActiveFaultsRequestReceived4 = new GetActiveFaultsRequestReceived4();
HandleFaultRequestReceived4 handleFaultRequestReceived4 = new HandleFaultRequestReceived4();
ModifyStationParametersRequestReceived4 modifyStationParametersRequestReceived4 = new ModifyStationParametersRequestReceived4();
//HeartbeatEvent heartbeatEvent = new HeartbeatEvent();
CFXEventTools cFXEventTools = CFXEventTools.Instance;
public string CFXHandle { get; set; } = "CFX.A00.OT00470020";
protected override CFXMessage HandleRequest(CFXEnvelope request)
{
CFXMessage response = null;
if (request.MessageBody is AreYouThereRequest) //存在性检测请求
{
areYouThereRequestReceived4.Handle(request.MessageBody as AreYouThereRequest, out response);
}
else if (request.MessageBody is GetEndpointInformationRequest) //获取终端节点信息请求
{
getEndpointInformationRequestReceived4.Handle(request.MessageBody as GetEndpointInformationRequest, out response);
}
else if (request.MessageBody is WhoIsThereRequest) //设备存在性查询请求
{
whoIsThereRequestReceived4.Handle(request.MessageBody as WhoIsThereRequest, out response);
}
else if (request.MessageBody is GetActiveRecipeRequest) //获取当前激活配方请求
{
getActiveRecipeRequestReceived4.Handle(request.MessageBody as GetActiveRecipeRequest, out response);
}
else if (request.MessageBody is GetActiveFaultsRequest) //获取当前错误状态请求
{
getActiveFaultsRequestReceived4.Handle(request.MessageBody as GetActiveFaultsRequest, out response);
}
else if (request.MessageBody is HandleFaultRequest) //处理错误请求
{
handleFaultRequestReceived4.Handle(request.MessageBody as HandleFaultRequest, out response);
}
else if (request.MessageBody is ModifyStationParametersRequest) //设备修改参数请求
{
modifyStationParametersRequestReceived4.Handle(request.MessageBody as ModifyStationParametersRequest, out response);
}
else //不支持的请求类型
{
response = new NotSupportedResponse()
{
RequestResult = new RequestResult()
{
Result = StatusResult.Failed,
ResultCode = 0,
Message = $"不支持的请求类型:{request.MessageBody.GetType().Name}"
}
};
}
return response;
}
/// <summary>
/// 发送生产单元验证请求接收通知
/// </summary>
public void SendValidateUnitsRequest(string uri, string primaryIdentifier, string[] unitsIdentifier)
{
try
{
ValidateUnitsRequest msg = new ValidateUnitsRequest()
{
Validations = new List<ValidationType>()
{
ValidationType.UnitTraceValidation,
},
PrimaryIdentifier = primaryIdentifier,
Units = cFXEventTools.UnitPositionTrans(unitsIdentifier)
};
var validateresult = Endpoint.ExecuteRequest(uri, new CFXEnvelope(msg)
{
Source = Endpoint.CFXHandle,
Target = "inline-control"
});
if (validateresult == null)
{
return;
}
var response = validateresult.MessageBody as ValidateUnitsResponse;
//响应逻辑
}
catch (Exception ex)
{
}
}
}
}