| | |
| | | using MapsterMapper; |
| | | using Serilog; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, $"RequestInNextAddress:入库下一地址,任务号: {task.TaskNum},子设备: {childDeviceCode}", conveyorLine.DeviceCode); |
| | | |
| | | //// 如果不是空托盘任务,处理目标地址 |
| | | //if (task.TaskType != (int)TaskOutboundTypeEnum.OutEmpty) |
| | | //{ |
| | | bool isEmptyTask = task.TaskType == (int)TaskOutboundTypeEnum.OutEmpty; |
| | | |
| | | Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress); |
| | | if (routers == null) throw new Exception($"未找到设备路由信息"); |
| | | // 确定目标地址 |
| | | string targetAddress; |
| | | if (isEmptyTask) |
| | | { |
| | | targetAddress = "2125"; |
| | | QuartzLogHelper.LogDebug(_logger, $"子设备: {childDeviceCode},入库下一目标地址: {2125}", conveyorLine.DeviceCode); |
| | | } |
| | | else |
| | | { |
| | | Dt_Router routers = _routerService.QueryNextRoute(task.NextAddress, task.TargetAddress); |
| | | if (routers == null) throw new Exception($"未找到设备路由信息"); |
| | | targetAddress = routers.ChildPosi; |
| | | } |
| | | |
| | | _targetAddressSelector.HandleInboundNextAddress(conveyorLine, routers.ChildPosi, childDeviceCode); |
| | | //} |
| | | // 处理目标地址:ChildPosi == "2125" 时跳过 HandleInboundNextAddress |
| | | if (targetAddress == "2125") |
| | | { |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.Target, "2125", childDeviceCode); |
| | | } |
| | | else if (!_targetAddressSelector.HandleInboundNextAddress(conveyorLine, targetAddress, childDeviceCode)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | // 更新任务当前位置 |
| | | _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); |
| | | |
| | | // 设置 WCS_STB 标志,表示 WCS 已处理 |
| | | // 更新任务当前位置和 WCS_ACK |
| | | if (isEmptyTask) |
| | | { |
| | | _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress, "2125"); |
| | | } |
| | | else |
| | | { |
| | | _ = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); |
| | | } |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode); |
| | | } |
| | | |
| | |
| | | /// <param name="conveyorLine">输送线设备对象</param> |
| | | /// <param name="command">PLC 命令数据</param> |
| | | /// <param name="childDeviceCode">子设备编码</param> |
| | | public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode) |
| | | public Task RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandNew command, string childDeviceCode) |
| | | { |
| | | // 查询待处理任务 |
| | | Dt_Task? task = _taskFilter.QueryPendingTask(conveyorLine.DeviceCode, childDeviceCode); |
| | | if (task != null) |
| | | if (task == null) return Task.CompletedTask; |
| | | |
| | | // 确定目标地址:空托盘任务使用 "2201",其他任务使用 NextAddress |
| | | var isEmptyTask = task.TaskType == (int)TaskOutboundTypeEnum.OutEmpty; |
| | | var targetAddress = task.CurrentAddress == "2217" ? (isEmptyTask ? "2201" : task.NextAddress) : task.NextAddress; |
| | | |
| | | // 处理特殊地址 2217,需要调用目标地址选择器 |
| | | if (task.CurrentAddress == "2217" && !_targetAddressSelector.HandleOutboundNextAddress(conveyorLine, targetAddress, childDeviceCode)) |
| | | { |
| | | // 设置任务号 |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, task.TaskNum, childDeviceCode); |
| | | |
| | | // 设置托盘条码 |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.Barcode, task.PalletCode, childDeviceCode); |
| | | |
| | | // 设置目标地址 |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.Target, task.NextAddress, childDeviceCode); |
| | | |
| | | // 回复 ACK 确认 |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode); |
| | | |
| | | // 更新任务状态 |
| | | _taskService.UpdateTaskStatusToNext(task); |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, "RequestOutbound:出库任务已下发,任务号: {TaskNum},子设备: {ChildDeviceCode}", $"出库任务已下发,任务号: {task.TaskNum}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode); |
| | | return Task.CompletedTask; ; |
| | | } |
| | | |
| | | // 设置任务号、托盘条码、目标地址、WCS_ACK |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.TaskNo, task.TaskNum, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.Barcode, task.PalletCode, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.Target, targetAddress, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBNameNew.WCS_ACK, (short)1, childDeviceCode); |
| | | |
| | | // 更新任务状态或位置 |
| | | if (isEmptyTask && task.NextAddress == "2217") |
| | | { |
| | | task.TaskStatus = task.TaskStatus.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | task.NextAddress = "2201"; |
| | | _taskService.Repository.UpdateData(task); |
| | | } |
| | | else |
| | | { |
| | | _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | |
| | | QuartzLogHelper.LogInfo(_logger, "RequestOutbound:出库任务已下发,任务号: {TaskNum},子设备: {ChildDeviceCode}", $"出库任务已下发,任务号: {task.TaskNum}", conveyorLine.DeviceCode, task.TaskNum, childDeviceCode); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <remarks> |
| | | /// 当出库任务执行到某个中间站点时调用。 |
| | | /// 根据下一地址判断是否需要与拘束机/插拔钉机等设备交互。 |
| | | /// </remarks> |
| | | /// <param name="conveyorLine">输送线设备对象</param> |
| | | /// <param name="command">PLC 命令数据</param> |