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 { /// /// 设备状态 /// /// /// public StackerCraneStatus StackerCraneStatusValue(SpeStackerCrane speStackerCrane) => GetStackerCraneStatus(speStackerCrane); /// /// 工作模式 /// /// /// public StackerCraneAutoStatus StackerCraneAutoStatusValue(SpeStackerCrane speStackerCrane) => GetStackerCraneAutoStatus(speStackerCrane); /// /// 工作状态 /// /// /// public StackerCraneWorkStatus StackerCraneWorkStatusValue(SpeStackerCrane speStackerCrane) => GetStackerCraneWorkStatus(speStackerCrane); /// /// 任务完成 /// /// /// public StackerCraneTaskCompleted StackerCraneTaskCompletedValue(SpeStackerCrane speStackerCrane) => GetStackerCraneTaskCompleted(speStackerCrane); /// /// 作业命令 /// /// /// public int WorkCommandValue(SpeStackerCrane speStackerCrane) => speStackerCrane.GetValue(StackerCraneDBName.WorkCommand); /// /// 获取堆垛机设备状态 /// /// private StackerCraneStatus GetStackerCraneStatus(SpeStackerCrane speStackerCrane) { return Enum.Parse(GetStatus(nameof(StackerCraneStatus), speStackerCrane)); } /// /// 获取堆垛机手自动状态 /// /// private StackerCraneAutoStatus GetStackerCraneAutoStatus(SpeStackerCrane speStackerCrane) { return Enum.Parse(GetStatus(nameof(StackerCraneAutoStatus), speStackerCrane)); } /// /// 获取堆垛机工作状态 /// /// private StackerCraneWorkStatus GetStackerCraneWorkStatus(SpeStackerCrane speStackerCrane) { return Enum.Parse(GetStatus(nameof(StackerCraneWorkStatus), speStackerCrane)); } /// /// 获取堆垛机任务状态 /// /// private StackerCraneTaskCompleted GetStackerCraneTaskCompleted(SpeStackerCrane speStackerCrane) { return Enum.Parse(GetStatus(nameof(StackerCraneTaskCompleted), speStackerCrane)); } private string GetEnumDes(T value) where T : Enum { FieldInfo? fieldInfo = typeof(T).GetField(value.ToString()); if (fieldInfo != null) { DescriptionAttribute? descriptionAttribute = fieldInfo.GetCustomAttribute(); if (descriptionAttribute != null) { return descriptionAttribute.Description; } return "未定义"; } return "未知"; } private string GetStatus(string protocolParamType, SpeStackerCrane speStackerCrane) { List 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(); } } }