using Autofac.Core;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Hosting;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
{
[DisallowConcurrentExecution]
public class SpeStackerCraneJob : IJob
{
private readonly ITaskService _taskService;
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
private readonly ITaskRepository _taskRepository;
private readonly IRouterService _routerService;
private readonly IAgvStationService _agvStationService;
public SpeStackerCraneJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IRouterService routerService, IAgvStationService agvStationService)
{
_taskService = taskService;
_taskExecuteDetailService = taskExecuteDetailService;
_taskRepository = taskRepository;
_routerService = routerService;
_agvStationService = agvStationService;
}
public Task Execute(IJobExecutionContext context)
{
try
{
SpeStackerCrane speStackerCrane = (SpeStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
if (speStackerCrane != null)
{
GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
//读取设备完成信息
if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid != 0)
{
_taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid,2);
}
if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
{
//下发RGV任务之前,先读取一下安全门状态
//查找RGV进行下发任务
Dt_Task task = GetTask(speStackerCrane.DeviceCode,getStackerObject);
if (task != null)
{
//调取写入RGV小车任务
RgvCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
bool sendFlag = getStackerObject.SendCommand(stackerCraneTaskCommand);
if (sendFlag)
{
//修改任务状态
_taskService.UpdateTaskStatusToNext(task);
}
}
else
{
if(speStackerCrane.DeviceCode=="RGV101" || speStackerCrane.DeviceCode == "RGV101")
{
//当没任务的时候,则进行移动
Returnposition(speStackerCrane.DeviceCode, getStackerObject.RGVCurrentlocation);
}
}
}
}
}
catch (Exception ex)
{
//Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
}
return Task.CompletedTask;
}
private Dt_Task? GetTask(string DeviceCode, GetStackerObject getStackerObject)
{
// 根据设备名称,获取到设备相关数据
AGVStation RGVTaskdevice = _agvStationService.Corridorequipment(DeviceCode); //根据设备获取到内容
return RGVTaskdevice.Station_tasktype switch
{
(int)RGVTasktype.Inbound => HandleInboundTask(RGVTaskdevice, getStackerObject),
(int)RGVTasktype.Outbound => OutboundEquipmentTask(RGVTaskdevice, getStackerObject),
_ => null
};
}
#region 入库方法
private Dt_Task? HandleInboundTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
{
if(RGVTaskdevice.Station_material== (int)RGVEquipment.InRGVForklift && getStackerObject.RgvCraneStatusValue== RgvEquipmentStatus.NoCargo)
{
return _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode, 1);
}
else if (RGVTaskdevice.Station_material == (int)RGVEquipment.InRGVForklift && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
{
return _taskService.GetInkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode, 2);
}else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
{
return ZichePickUpAisle(RGVTaskdevice, getStackerObject);
}else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
{
return GoodsPlacedCorridor(RGVTaskdevice, getStackerObject);
}
else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Corridorcar && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.NoCargo)
{
return ZicheMobile(RGVTaskdevice, getStackerObject);
}
else if (RGVTaskdevice.Station_material == (int)RGVEquipment.Mothertrailer && getStackerObject.RgvCraneStatusValue == RgvEquipmentStatus.HasCargo)
{
return MotherVehicleMovement(RGVTaskdevice);
}
else { return null; }
}
#region 过道子车进行取货
public Dt_Task? ZichePickUpAisle(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
{
//获取子车取货任务
Dt_Task dt_Task = _taskService.GetInzicheTask(RGVTaskdevice.ChildPosiDeviceCode,1);
if(dt_Task.CurrentAddress== getStackerObject.RGVCurrentlocation.ToString())
{
return dt_Task;
}
else
{
//如果不等于,则进行判断子车在哪个位置
if (RGVTaskdevice.Station_Area == 1)
{
// 根据子车位置处理不同情况
switch (getStackerObject.RGVCurrentlocation)
{
case int Waddress when Waddress == RGVTaskdevice.MotherCarDeviceCode:
return dt_Task;
case int Naddress when Naddress == RGVTaskdevice.MotherCardeputy:
return HandleMedialCase(dt_Task, RGVTaskdevice.MotherCarDeviceCode);
case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress:
return HandleMedialCase2(dt_Task, RGVTaskdevice);
default: return null;
}
}
else
{
//取HCJ位的料判断
switch (getStackerObject.RGVCurrentlocation)
{
case int Waddress when Waddress == RGVTaskdevice.MotherCarDeviceCode:
return dt_Task;
case int Naddress when Naddress == RGVTaskdevice.MotherCardeputy:
return HandleMedialCase(dt_Task, RGVTaskdevice.MotherCarDeviceCode);
default: return null;
}
}
}
}
///
/// 判断外侧母车是否在入口口
///
///
///
///
private Dt_Task? HandleMedialCase(Dt_Task task, int currentStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(currentStation);
int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
if (motherCarAddress == Muche.Motherinlaw) return task;
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
return null;
}
///
/// 判断内外侧母车是否在入库口
///
///
///
///
private Dt_Task? HandleMedialCase2(Dt_Task task, AGVStation currentStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(currentStation.MotherCarDeviceCode); //外侧母车
AGVStation Muche2 = _agvStationService.GetMothervehicle(currentStation.MotherCardeputy); //内侧母车
int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
if (motherCarAddress == 0 || motherCarAddress2 == 0) return null;
// 如果母车不在预期位置,下发移动任务
if (motherCarAddress != Muche.Motherinlaw)
{
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
}
if (motherCarAddress2 != Muche2.Motherinlaw)
{
RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
}
if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw) return task;
// 母车已在正确位置
return null;
}
#endregion
#region 过道子车进行放货
public Dt_Task? GoodsPlacedCorridor(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
{
Dt_Task task = _taskService.GetInzicheTask(RGVTaskdevice.ChildPosiDeviceCode, 2);
int nexaddres = int.Parse(task.NextAddress);
switch (nexaddres)
{
case int Whcjaddress when Whcjaddress == RGVTaskdevice.MotherCarDeviceCode: //放货点在第一个过道点
return MotherCarMoves(task, RGVTaskdevice);
case int Waddress when Waddress == RGVTaskdevice.MotherCardeputy: //放货点在第二个过道点
return MotherCarMovesinside(task, RGVTaskdevice);
case int HCJaddress when HCJaddress == RGVTaskdevice.HCJStorageaddress: //放货点在HCJ上
return HCJMotherCarMovesinside(task, RGVTaskdevice);
default: return null;
}
}
//区域一判断母车是否到位,可立即放货
private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.ZicheMotherinlaw);
int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
if (motherCarAddress == Muche.ZicheMotherinlaw) return _Task;
if(motherCarAddress!=0) RGVMovetask(Muche.ZicheMotherinlaw, aGVStation.ChildPosiDeviceCode);
return null;
}
///
/// 判断放第二个母车位置
///
///
///
///
private Dt_Task? MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode); //外侧母车
AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy); //内侧母车
int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
int motherCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(Muche2.ChildPosiDeviceCode);
// 如果母车不在预期位置,下发移动任务
if (motherCarAddress != Muche.Motherinlaw && motherCarAddress != 0)
{
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
}
if (motherCarAddress2 != Muche2.ZicheMotherinlaw && motherCarAddress2 != 0)
{
RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);
}
if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.ZicheMotherinlaw) return _Task;
// 母车已在正确位置
return null;
}
///
/// 判断放在HCJ上面
///
///
///
///
private Dt_Task? HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode); //外侧母车
AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy); //内侧母车
AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress); //内侧子车
int motherCarAddress = GetDeviceAddress.GetEquipmentInMuche(Muche.ChildPosiDeviceCode);
int motherCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(Muche2.ChildPosiDeviceCode);
int ZiCarAddress3 = GetDeviceAddress.GetEquipmentInMuche(Ziche3.ChildPosiDeviceCode);
// 如果母车不在预期位置,下发移动任务
if (motherCarAddress != Muche.Motherinlaw && motherCarAddress != 0)
{
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
}
if (motherCarAddress2 != Muche2.Motherinlaw && motherCarAddress2 != 0)
{
RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
}
if (ZiCarAddress3 == Ziche3.HCJStorageaddress && ZiCarAddress3!=0)
{
//判断目标站台是入库到几号堆垛机
if (_Task.TargetAddress == "3") //入库至3号堆垛机
{
//判断外侧母车位置(2区域)
AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode); //外侧母车
int motNCarAddress = GetDeviceAddress.GetEquipmentInMuche(MucheN.ChildPosiDeviceCode); //获取到母车当前位置
if (motNCarAddress!=0)
{
if (MucheN.ZicheMotherinlaw == motNCarAddress)
{
RGVMovetask(Ziche3.MotherCarDeviceCode, Ziche3.ChildPosiDeviceCode);
}
else
{
RGVMovetask(MucheN.ZicheMotherinlaw, MucheN.ChildPosiDeviceCode);
}
}
}
else if (_Task.TargetAddress == "4") //入库至4号堆垛机
{
//判断外侧母车位置(2区域)
AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode); //外侧母车
int motNCarAddress = GetDeviceAddress.GetEquipmentInMuche(MucheN.ChildPosiDeviceCode); //获取到母车当前位置
if (MucheN.Motherinlaw != motNCarAddress && motNCarAddress!=0)
{
RGVMovetask(MucheN.Motherinlaw, MucheN.ChildPosiDeviceCode);
}
AGVStation MucheN2 = _agvStationService.GetMothervehicle(Ziche3.MotherCardeputy); //外侧母车
int motNCarAddress2 = GetDeviceAddress.GetEquipmentInMuche(MucheN2.ChildPosiDeviceCode); //获取到母车当前位置
if (MucheN2.ZicheMotherinlaw != motNCarAddress2 && motNCarAddress2!=0)
{
RGVMovetask(MucheN2.ZicheMotherinlaw, MucheN2.ChildPosiDeviceCode);
}
if (MucheN.Motherinlaw == motNCarAddress && MucheN2.ZicheMotherinlaw == motNCarAddress2)
{
RGVMovetask(Ziche3.MotherCardeputy, Ziche3.ChildPosiDeviceCode);
}
}
}
if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw && ZiCarAddress3 != Ziche3.HCJStorageaddress) return _Task;
// 母车已在正确位置
return null;
}
#endregion
#region 子车移动任务(后续可能需要优化一下)
public Dt_Task? ZicheMobile(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
{
Dt_Task task = _taskService.GetInzicheTaskMobile(RGVTaskdevice.ChildPosiDeviceCode, 1);
return task;
}
#endregion
#region 母车移动任务
public Dt_Task? MotherVehicleMovement(AGVStation RGVTaskdevice)
{
Dt_Task task = _taskService.GetInzicheTaskMobile(RGVTaskdevice.ChildPosiDeviceCode, 2);
int curradder = int.Parse(task.CurrentAddress);
AGVStation GdZiche = _agvStationService.GetMotheaisle(curradder);
int motherCarAddress = GetDeviceAddress.GetEquipmentInformation(GdZiche.ChildPosiDeviceCode);
if (motherCarAddress != curradder && motherCarAddress!=0) return task;
RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
return null;
}
#endregion
#endregion
#region 出库方法
public Dt_Task? OutboundEquipmentTask(AGVStation RGVTaskdevice, GetStackerObject getStackerObject)
{
return (RGVTaskdevice.Station_material, getStackerObject.RgvCraneStatusValue) switch
{
((int)RGVEquipment.Mothertrailer, RgvEquipmentStatus.HasCargo)
=> Mothertaskdistribution(RGVTaskdevice),
((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.NoCargo)
=> ChildPickupAddres(RGVTaskdevice),
((int)RGVEquipment.Corridorcar, RgvEquipmentStatus.HasCargo)
=> Findshippingtask(RGVTaskdevice),
((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.NoCargo)
=> _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
RGVTaskdevice.HCJStorageaddress.ToString(), 1),
((int)RGVEquipment.OutRGVForklift, RgvEquipmentStatus.HasCargo)
=> _taskService.GetOutkouFinhuoTask(RGVTaskdevice.ChildPosiDeviceCode,
RGVTaskdevice.HCJStorageaddress.ToString(), 2),
_ => null
};
}
#region 下发母车任务,需要判断当前行小车在哪个位子
private Dt_Task? Mothertaskdistribution(AGVStation GdZiche)
{
// 提前检查无效的Area值
if (GdZiche.Station_Area < 1 || GdZiche.Station_Area > 4)
return null;
AGVStation ZicheinnerSide = _agvStationService.GetMotheaisle(GdZiche.ZicheMotherinlaw);
int ZiCarAddress3 = GetDeviceAddress.GetEquipmentInformation(ZicheinnerSide.ChildPosiDeviceCode);
// 使用switch语句提高可读性
return GdZiche.Station_Area switch
{
4 when ZiCarAddress3 != GdZiche.ZicheMotherinlaw
=> _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
3 when ZiCarAddress3 == ZicheinnerSide.HCJStorageaddress
=> _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
2 when ZiCarAddress3 != GdZiche.MotherCardeputy && ZiCarAddress3 != GdZiche.HCJStorageaddress
=> _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
1 when ZiCarAddress3 == ZicheinnerSide.HCJStorageaddress
=> _taskService.QueryStackerCraneTask(GdZiche.ChildPosiDeviceCode),
_ => null
};
}
#endregion
#region 判断已移动出来的母车,再判断小车位置
public Dt_Task? ChildPickupAddres(AGVStation GdZiche)
{
if (GdZiche.Station_Area == 5)
return _taskService.ChildVehicleMission(GdZiche);
var task = _taskService.ChildVehicleMission(GdZiche);
// 快速返回条件检查
if (task.CurrentAddress != GdZiche.HCJStorageaddress.ToString())
return task;
var innerStation = _agvStationService.GetZicheDeep(GdZiche.HCJStorageaddress);
if (GetDeviceAddress.GetEquipmentInformation(innerStation.ChildPosiDeviceCode) != innerStation.HCJStorageaddress)
return task;
var motherStation = _agvStationService.GetMothervehicle(innerStation.MotherCarDeviceCode);
if (GetDeviceAddress.ReturnCurrentStatus(motherStation.ChildPosiDeviceCode))
RGVMovetask(innerStation.MotherCarDeviceCode, innerStation.ChildPosiDeviceCode);
return null;
}
#endregion
#region 查找子车放货任务
public Dt_Task? Findshippingtask(AGVStation GdZiche)
{
Dt_Task task = _taskService.GetFinhuoTask(GdZiche.ChildPosiDeviceCode);
if (GetDeviceAddress.HCJIsstock(task.NextAddress)) return task;
return null;
}
#endregion
#endregion
#region 出库小车移动任务下发
public void Returnposition(string DeviceCode, int RGVCurrentlocation)
{
int HCJGoodsplatform = 1170; //定义的放货站台
//判断母车是否需要进行移动
AGVStation GdZiche = _agvStationService.Corridorequipment(DeviceCode);
if (GdZiche.Station_Area == 1)
{
switch (RGVCurrentlocation)
{
case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode: //在第一个母车上
RGVMovetask(HCJGoodsplatform, GdZiche.ChildPosiDeviceCode);
break;
case int Waddress when Waddress == GdZiche.MotherCardeputy: //在第二个母车上
OutNMotherCar(GdZiche.MotherCarDeviceCode);
break;
case int HCJaddress when HCJaddress == GdZiche.HCJStorageaddress: //在HCJ站台上
OutHCJMotherCar(GdZiche);
break;
default: break;
}
}
else
{
switch (RGVCurrentlocation)
{
case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode: //在第一个母车上,需要判断外侧子车是否在HCJ上
OutinnerSideNMotherCar(GdZiche);
break;
case int Waddress when Waddress == GdZiche.MotherCardeputy: //在第二个母车上,需要判断子车与外侧母车是否在过道上
OutinnerSideMotherCar(GdZiche);
break;
default: break;
}
}
}
#region 外侧小车回归到起始点位
///
/// 判断放第二个母车位置
///
///
///
///
private void OutNMotherCar(int MotherCarDeviceCode)
{
AGVStation Muche = _agvStationService.GetMothervehicle(MotherCarDeviceCode); //外侧母车
int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
if (motherCarAddress != Muche.Motherinlaw)
{
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
}
}
private void OutHCJMotherCar(AGVStation aGVStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode); //外侧母车
AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy); //内侧母车
int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
// 如果母车不在预期位置,下发移动任务
if (motherCarAddress != Muche.Motherinlaw)
{
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
}
if (motherCarAddress2 != Muche2.Motherinlaw)
{
RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
}
}
#endregion
#region 外侧小车回归到起始点位
///
/// 在第一个位置,则判断外侧子车是否在HCJ站台下面
///
///
///
///
private void OutinnerSideNMotherCar(AGVStation aGVStation)
{
AGVStation Ziche3 = _agvStationService.GetZicheOuterSide(aGVStation.HCJStorageaddress); //外侧子车
int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
if (ZiCarAddress3 == Ziche3.HCJStorageaddress)
{
OutHCJMotherCar(Ziche3);
}
else
{
RGVMovetask(aGVStation.HCJStorageaddress, aGVStation.ChildPosiDeviceCode);
}
}
private void OutinnerSideMotherCar(AGVStation aGVStation)
{
AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode); //外侧母车
int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
// 如果母车不在预期位置,下发移动任务
if (motherCarAddress != Muche.Motherinlaw)
{
RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
}
OutinnerSideNMotherCar(aGVStation);
}
#endregion
#endregion
///
/// 子母车移动任务
///
/// 目标地址
/// 设备编号
///
private bool RGVMovetask(int RGVAdders, string ChildPosiDeviceCode)
{
RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(RGVAdders);
bool sendFlag = SendCommand2(standardCommands, ChildPosiDeviceCode);
return sendFlag;
}
///
/// 任务实体转换成命令Model
///
/// 任务实体
///
///
public RgvCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
{
RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
short locaticurr = task.RGVTaskType switch
{
_ when task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp ||
(task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType != (int)TaskInStatusEnum.RGV_InZichemoveFinish)
=> short.Parse(task.CurrentAddress),
_ when task.RGVTaskType == (short)RGVTaskTypeEnum.Placing || (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType== (int)TaskInStatusEnum.RGV_InZichemoveFinish)
=> short.Parse(task.NextAddress),
_ => (short)0
};
stackerCraneTaskCommand.RGV_RGVTasklocation = locaticurr;
stackerCraneTaskCommand.RGV_RGVtasktype = (short)task.RGVTaskType;
stackerCraneTaskCommand.RGV_Rgvtaskid = (short)task.TaskNum;
stackerCraneTaskCommand.RGV_Lanjiantaskid = (short)task.TaskNum;
return stackerCraneTaskCommand;
}
///
/// 下发移动任务
///
/// 任务实体
///
///
public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(int RGVAddress)
{
RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
stackerCraneTaskCommand.RGV_RGVTasklocation = (short)RGVAddress;
stackerCraneTaskCommand.RGV_RGVtasktype = 3;
stackerCraneTaskCommand.RGV_Rgvtaskid = 999; //rgv任务号
stackerCraneTaskCommand.RGV_Lanjiantaskid = 999; //兰剑任务id
return stackerCraneTaskCommand;
}
public bool SendCommand2(RgvCraneTaskCommand command, string DeviceCode)
{
try
{
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
DeviceProDTO? deviceProDTO = GetDeviceAddress.GetRGVDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
int MCGStatus = GetDeviceAddress.RGVGetLine(Commonstacker, deviceProDTO.DeviceProAddress);
if (Commonstacker.IsConnected)
{
if (MCGStatus == (int)RgvJobCraneStatus.Ready)
{
Commonstacker.SetValue(RgvCraneDBName.RGV_RGVTasklocation, command.RGV_RGVTasklocation);
Commonstacker.SetValue(RgvCraneDBName.RGV_RGVtasktype, command.RGV_RGVtasktype);
Commonstacker.SetValue(RgvCraneDBName.RGV_Rgvtaskid, command.RGV_Rgvtaskid);
Commonstacker.SetValue(RgvCraneDBName.RGV_Lanjiantaskid, command.RGV_Lanjiantaskid);
return true;
}
}
return false;
}
catch (Exception ex)
{
return false;
}
}
}
}