using HslCommunication;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DeviceBase;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.StackerCrane;
|
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
|
|
namespace WIDESEAWCS_Tasks.StackerCraneJob
|
{
|
public class GetStackerObject
|
{
|
|
/// <summary>
|
/// 设备状态
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public StackerCraneStatus StackerCraneStatusValue(SpeStackerCrane speStackerCrane) => GetStackerCraneStatus(speStackerCrane);
|
|
/// <summary>
|
/// 工作模式
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public StackerCraneAutoStatus StackerCraneAutoStatusValue(SpeStackerCrane speStackerCrane) => GetStackerCraneAutoStatus(speStackerCrane);
|
|
/// <summary>
|
/// 工作状态
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public StackerCraneWorkStatus StackerCraneWorkStatusValue(SpeStackerCrane speStackerCrane) => GetStackerCraneWorkStatus(speStackerCrane);
|
|
/// <summary>
|
/// 任务完成
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public StackerCraneTaskCompleted StackerCraneTaskCompletedValue(SpeStackerCrane speStackerCrane) => GetStackerCraneTaskCompleted(speStackerCrane);
|
|
/// <summary>
|
/// 作业命令
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public int WorkCommandValue(SpeStackerCrane speStackerCrane) => speStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkCommand);
|
|
/// <summary>
|
/// 获取堆垛机设备状态
|
/// </summary>
|
/// <returns></returns>
|
private StackerCraneStatus GetStackerCraneStatus(SpeStackerCrane speStackerCrane)
|
{
|
return Enum.Parse<StackerCraneStatus>(GetStatus(nameof(StackerCraneStatus), speStackerCrane));
|
}
|
|
/// <summary>
|
/// 获取堆垛机手自动状态
|
/// </summary>
|
/// <returns></returns>
|
private StackerCraneAutoStatus GetStackerCraneAutoStatus(SpeStackerCrane speStackerCrane)
|
{
|
return Enum.Parse<StackerCraneAutoStatus>(GetStatus(nameof(StackerCraneAutoStatus), speStackerCrane));
|
}
|
|
/// <summary>
|
/// 获取堆垛机工作状态
|
/// </summary>
|
/// <returns></returns>
|
private StackerCraneWorkStatus GetStackerCraneWorkStatus(SpeStackerCrane speStackerCrane)
|
{
|
return Enum.Parse<StackerCraneWorkStatus>(GetStatus(nameof(StackerCraneWorkStatus), speStackerCrane));
|
}
|
|
/// <summary>
|
/// 获取堆垛机任务状态
|
/// </summary>
|
/// <returns></returns>
|
private StackerCraneTaskCompleted GetStackerCraneTaskCompleted(SpeStackerCrane speStackerCrane)
|
{
|
return Enum.Parse<StackerCraneTaskCompleted>(GetStatus(nameof(StackerCraneTaskCompleted), speStackerCrane));
|
}
|
|
private string GetEnumDes<T>(T value) where T : Enum
|
{
|
FieldInfo? fieldInfo = typeof(T).GetField(value.ToString());
|
if (fieldInfo != null)
|
{
|
DescriptionAttribute? descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
|
if (descriptionAttribute != null)
|
{
|
return descriptionAttribute.Description;
|
}
|
return "未定义";
|
}
|
return "未知";
|
}
|
|
private string GetStatus(string protocolParamType, SpeStackerCrane speStackerCrane)
|
{
|
List<DeviceProDTO> devicePros = speStackerCrane.DeviceProDTOs.Where(x => x.DeviceProParamType == protocolParamType).ToList();
|
if (devicePros.Count == 0)
|
{
|
throw new Exception("未获取到协议信息");
|
}
|
for (int i = 0; i < devicePros.Count; i++)
|
{
|
object readStatus = speStackerCrane.Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType);
|
DeviceProtocolDetailDTO? deviceProtocolDetail = speStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception();
|
deviceProtocolDetail = speStackerCrane.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamType && x.ProtocalDetailValue.Equals(readStatus.ToString()));
|
if (deviceProtocolDetail != null)
|
{
|
return deviceProtocolDetail.ProtocolDetailType;
|
}
|
return StackerCraneStatus.Unkonw.ToString();
|
}
|
return StackerCraneStatus.Unkonw.ToString();
|
}
|
}
|
}
|