using AutoMapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Communicator;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_DTO.AGVInfo;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_Tasks.ConveyorLineJob.ConveyorLineExtend;
|
using WIDESEAWCS_Tasks.ProductionLineJob;
|
|
namespace WIDESEAWCS_Tasks
|
{
|
public partial class AGVsignal
|
{
|
/// <summary>
|
/// AGV与输送线交互
|
/// </summary>
|
/// <param name="conveyor"></param>
|
/// <returns></returns>
|
public static WebResponseContent AGVRequestin(ConveyorLineDTO conveyor)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
if (conveyor == null) throw new Exception("请求数据为空");
|
if (string.IsNullOrEmpty(conveyor.Station)) throw new Exception("站点编号为空");
|
switch (conveyor.Station)
|
{
|
case "1001":
|
case "1008":
|
content = AGVRequestinConveyorLine(conveyor);
|
break;
|
case "MDX01":
|
content = AGVRequestinProductionLine(conveyor);
|
break;
|
default: throw new Exception($"未定义站台号[Station:{conveyor.Station}]");
|
}
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// AGV和输送线交互
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent AGVRequestinConveyorLine(ConveyorLineDTO conveyor)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
CommonConveyorLine? conveyorLine = Storage.Devices.FirstOrDefault(x => x.DeviceName == "输送线") as CommonConveyorLine;
|
if (conveyorLine == null) throw new Exception("未找到输送线设备信息");
|
if (!conveyorLine.IsConnected) throw new Exception($"输送线设备通讯异常");
|
//conveyorLine.SetValue(ConveyorLine_AGV.WriteRGPutComplete, true, "1001");//人工放货完成
|
switch (conveyor.Type)
|
{
|
case 1:
|
{
|
if (conveyor.Station == "1001")
|
{
|
content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestPut, true, conveyor.Station);
|
if (content.Status) content.Status = conveyorLine.GetValue<ConveyorLine_AGV, bool>(ConveyorLine_AGV.ConveyorLinePermitPut, conveyor.Station);
|
}
|
else
|
{
|
content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestTake, true, conveyor.Station);
|
if (content.Status) content.Status = conveyorLine.GetValue<ConveyorLine_AGV, bool>(ConveyorLine_AGV.ConveyorLinePermitTake, conveyor.Station);
|
}
|
}
|
break;
|
case 2:
|
{
|
if (conveyor.Station == "1001")
|
{
|
content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVPutComplete, true, conveyor.Station);
|
if (content.Status)
|
{
|
Thread.Sleep(1000);
|
conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestPut, false, conveyor.Station);
|
conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVPutComplete, false, conveyor.Station);
|
}
|
}
|
else
|
{
|
content.Status = conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVTakeComplete, true, conveyor.Station);
|
if (content.Status)
|
{
|
Thread.Sleep(1000);
|
conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVRequestTake, false, conveyor.Station);
|
conveyorLine.SetValue(ConveyorLine_AGV.WriteAGVTakeComplete, false, conveyor.Station);
|
}
|
}
|
}
|
break;
|
case 3:
|
|
break;
|
case 4:
|
|
break;
|
default: throw new Exception($"类型有误[Type:{conveyor.Type}]");
|
}
|
content = content.Status ? content.OK() : content.Error();
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
/// <summary>
|
/// AGV和产线交互
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent AGVRequestinProductionLine(ConveyorLineDTO conveyor)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
OtherDevice? ProductionLine = Storage.Devices.FirstOrDefault(x => x.DeviceCode == conveyor.Station) as OtherDevice;
|
if (ProductionLine == null) throw new Exception("未找到产线设备信息");
|
if (!ProductionLine.IsConnected) throw new Exception($"产线设备通讯异常");
|
content.Status = ProductionLine.SetValue(ProductionLineDBName.WagvState, conveyor.Type);
|
if (!content.Status) throw new Exception("写入AGV信号失败");
|
var agvState = ProductionLine.GetValue<ProductionLineDBName, short>(ProductionLineDBName.agvState);
|
if (agvState == 3) throw new Exception("产线设备异常");
|
switch (conveyor.Type)
|
{
|
case 1:
|
if (agvState != conveyor.Type) throw new Exception("产线不允许进入作业");
|
break;
|
case 2:
|
if (agvState != conveyor.Type) throw new Exception("产线不允许离开");
|
break;
|
case 3:
|
content.Status = ProductionLine.SetValue(ProductionLineDBName.Wrequest, 2);
|
if (content.Status) content.Status = ProductionLine.SetValue(ProductionLineDBName.WagvState, 0);
|
break;
|
}
|
content = content.Status ? content.OK() : content.Error("写入失败");
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
}
|
}
|