using HslCommunication;
|
using System.ComponentModel;
|
using System.Reflection;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.StackerCrane;
|
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
|
|
namespace WIDESEAWCS_Tasks.StackerCraneJob
|
{
|
public class GetStackerObject
|
{
|
private SpeStackerCrane _speStackerCrane;
|
|
public GetStackerObject(SpeStackerCrane speStackerCrane)
|
{
|
_speStackerCrane = speStackerCrane;
|
}
|
/// <summary>
|
/// 设备状态(有无货状态)
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public RgvEquipmentStatus RgvCraneStatusValue => GetRgvCraneStatus();
|
|
/// <summary>
|
/// 工作模式(1联机 0脱机)
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public RgvCraneAutoStatus RgvCraneAutoStatusValue => GetRgvCraneAutoStatus();
|
|
/// <summary>
|
/// 任务状态(0空闲、1执行中、2已完成、3异常完成)
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public RgvJobCraneStatus StaclerkJobJobStatusValue => GetRgvJobCraneWorkStatus();
|
|
/// <summary>
|
/// 步进状态(0无动作、1取货行走、2取货、3放货行走、4放货、5仅行走中)
|
/// </summary>
|
/// <param name="speStackerCrane"></param>
|
/// <returns></returns>
|
public RGVStepprocess RgvCraneWorkStatusValue => GetRgvCraneWorkStatus();
|
|
/// <summary>
|
/// 当前,子母车的地址
|
/// </summary>
|
public int RGVCurrentlocation => GetRGVCurrentlocation();
|
|
/// <summary>
|
/// 当前rgv任务
|
/// </summary>
|
public int CurrentRgvtaskid => GetCurrentRgvtaskid();
|
/// <summary>
|
/// 当前兰剑任务
|
/// </summary>
|
public int CurrentLanjiantaskid => GetLanjiantaskid();
|
|
/// <summary>
|
/// 获取RGV设备状态
|
/// </summary>
|
/// <returns></returns>
|
private RgvEquipmentStatus GetRgvCraneStatus()
|
{
|
return Enum.Parse<RgvEquipmentStatus>(GetStatus(nameof(RgvEquipmentStatus)));
|
}
|
|
/// <summary>
|
/// 获取rgv手自动状态
|
/// </summary>
|
/// <returns></returns>
|
private RgvCraneAutoStatus GetRgvCraneAutoStatus()
|
{
|
return Enum.Parse<RgvCraneAutoStatus>(GetStatus(nameof(RgvCraneAutoStatus)));
|
}
|
|
/// <summary>
|
/// 获取rgv工作状态
|
/// </summary>
|
/// <returns></returns>
|
private RGVStepprocess GetRgvCraneWorkStatus()
|
{
|
return Enum.Parse<RGVStepprocess>(GetStatus(nameof(RGVStepprocess)));
|
}
|
|
/// <summary>
|
/// 获取rgv作业状态
|
/// </summary>
|
/// <returns></returns>
|
private RgvJobCraneStatus GetRgvJobCraneWorkStatus()
|
{
|
return Enum.Parse<RgvJobCraneStatus>(GetStatus(nameof(RgvJobCraneStatus)));
|
}
|
|
|
/// <summary>
|
/// 获取当前地址
|
/// </summary>
|
/// <returns></returns>
|
private int GetRGVCurrentlocation()
|
{
|
|
DeviceProDTO deviceProDTO = _speStackerCrane.DeviceProDTOs.FirstOrDefault((DeviceProDTO x) => x.DeviceProParamName == "RGVCurrentlocation");
|
if (deviceProDTO != null)
|
{
|
return (int)_speStackerCrane.Communicator.ReadAsObj(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceDataType, 1);
|
}
|
return 0;
|
}
|
|
/// <summary>
|
/// 获取rgv任务id
|
/// </summary>
|
/// <returns></returns>
|
private int GetCurrentRgvtaskid()
|
{
|
|
DeviceProDTO deviceProDTO = _speStackerCrane.DeviceProDTOs.FirstOrDefault((DeviceProDTO x) => x.DeviceProParamName == "RGV_Rgvtaskid");
|
if (deviceProDTO != null)
|
{
|
return (int)_speStackerCrane.Communicator.ReadAsObj(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceDataType, 1);
|
}
|
return 0;
|
}
|
|
/// <summary>
|
/// 获取当前兰剑任务id
|
/// </summary>
|
/// <returns></returns>
|
private int GetLanjiantaskid()
|
{
|
|
DeviceProDTO deviceProDTO = _speStackerCrane.DeviceProDTOs.FirstOrDefault((DeviceProDTO x) => x.DeviceProParamName == "RGV_Lanjiantaskid");
|
if (deviceProDTO != null)
|
{
|
return (int)_speStackerCrane.Communicator.ReadAsObj(deviceProDTO.DeviceProAddress, deviceProDTO.DeviceDataType, 1);
|
}
|
return 0;
|
}
|
|
|
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)
|
{
|
try
|
{
|
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();
|
}
|
catch (Exception ex)
|
{
|
|
throw;
|
}
|
}
|
|
public bool SendCommand(RgvCraneTaskCommand command)
|
{
|
try
|
{
|
if(_speStackerCrane.IsConnected)
|
{
|
_speStackerCrane.SetValue(RgvCraneDBName.RGV_RGVTasklocation, command.RGV_RGVTasklocation);
|
_speStackerCrane.SetValue(RgvCraneDBName.RGV_RGVtasktype, command.RGV_RGVtasktype);
|
_speStackerCrane.SetValue(RgvCraneDBName.RGV_Rgvtaskid, command.RGV_Rgvtaskid);
|
_speStackerCrane.SetValue(RgvCraneDBName.RGV_Lanjiantaskid, command.RGV_Lanjiantaskid);
|
return true;
|
}
|
return false;
|
|
}
|
catch (Exception ex)
|
{
|
return false;
|
}
|
}
|
|
|
|
}
|
}
|