| | |
| | | using HslCommunication; |
| | | using Masuit.Tools.Systems; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using System.Diagnostics.CodeAnalysis; |
| | |
| | | using WIDESEAWCS_Core.Caches; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_DTO.MOM; |
| | | using WIDESEAWCS_IProcessRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_SignalR; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | using WIDESEAWCS_Common; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | |
| | | bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); |
| | | if (sendFlag) |
| | | { |
| | | StringBuilder builder = new StringBuilder(); |
| | | builder.AppendLine(); |
| | | builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】"); |
| | | builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】"); |
| | | builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】"); |
| | | builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】"); |
| | | builder.AppendLine($"时间:【{DateTime.Now}】"); |
| | | builder.AppendLine(); |
| | | ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue); |
| | | //StringBuilder builder = new StringBuilder(); |
| | | //builder.AppendLine(); |
| | | //builder.AppendLine($"【{commonStackerCrane.DeviceName}】堆垛机状态:【{commonStackerCrane.StackerCraneStatusDes}】,时间:【{DateTime.Now}】"); |
| | | //builder.AppendLine($"【{commonStackerCrane.DeviceName}】手自动状态:【{commonStackerCrane.StackerCraneAutoStatusDes}】,时间:【{DateTime.Now}】"); |
| | | //builder.AppendLine($"【{commonStackerCrane.DeviceName}】作业状态:【{commonStackerCrane.StackerCraneWorkStatusDes}】,时间:【{DateTime.Now}】"); |
| | | //builder.AppendLine($"【{commonStackerCrane.DeviceName}】下发任务成功,【{JsonConvert.SerializeObject(stackerCraneTaskCommand, Formatting.Indented)}】"); |
| | | //builder.AppendLine($"时间:【{DateTime.Now}】"); |
| | | //builder.AppendLine(); |
| | | //ConsoleHelper.WriteColorLine(builder, ConsoleColor.Blue); |
| | | commonStackerCrane.LastTaskType = task.TaskType; |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | } |
| | |
| | | str = $"{commonStackerCrane.DeviceName}】WMS|WCS任务完成:【{content.Status}】,堆垛机完成信号写入:【{isWorkType}】,任务号:【{e.TaskNum}】时间【{DateTime.Now}】"; |
| | | WriteInfo(commonStackerCrane.DeviceName, str); |
| | | ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue); |
| | | |
| | | if (content.Status) |
| | | { |
| | | var task = content.Data as Dt_Task; |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TargetAddress == "001-000-001") |
| | | { |
| | | Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress); |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); |
| | | if (device != null) |
| | | { |
| | | str = $"写入完成,给线体写入下降信号"; |
| | | WriteInfo(commonStackerCrane.DeviceName, str); |
| | | ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue); |
| | | |
| | | // 获取输送线对象 |
| | | CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device; |
| | | |
| | | // 获取协议地址 |
| | | var proAddress = conveyorLine.DeviceProDTOs |
| | | .FirstOrDefault(x => x.DeviceChildCode == stationManager.stationChildCode && x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString()) |
| | | ?.DeviceProAddress; |
| | | |
| | | if (proAddress == null) |
| | | { |
| | | str = "未找到协议地址"; |
| | | WriteInfo(commonStackerCrane.DeviceName, str); |
| | | ConsoleHelper.WriteColorLine(str, ConsoleColor.Red); |
| | | return; |
| | | } |
| | | |
| | | string address = proAddress.Contains(".0") ? proAddress : proAddress + ".0"; |
| | | |
| | | // 写入 false 信号 |
| | | WriteSignal(conveyorLine, address, false, commonStackerCrane.DeviceName); |
| | | } |
| | | else |
| | | { |
| | | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.NextAddress}】对应的通讯对象,无法清除出库站台顶升状态"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && task.TargetAddress == "001-000-001") |
| | | { |
| | | Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.Roadway == task.Roadway && x.stationLocation == task.TargetAddress); |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); |
| | | if (device != null) |
| | | { |
| | | CommonConveyorLine_After conveyorLine = (CommonConveyorLine_After)device; |
| | | var proAddress = conveyorLine.DeviceProDTOs.Where(x => x.DeviceChildCode == stationManager.stationChildCode).Where(x => x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString()).FirstOrDefault().DeviceProAddress; |
| | | string? str = proAddress; |
| | | if (!proAddress.Contains(".0")) |
| | | { |
| | | str = proAddress + ".0"; |
| | | } |
| | | conveyorLine.Communicator.Write(str, true); |
| | | } |
| | | else |
| | | { |
| | | _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"未找到出库站台【{task.NextAddress}】对应的通讯对象,无法判断出库站台是否被占用"); |
| | | return null; |
| | | } |
| | | } |
| | | // 检查当前出库任务站台是否允许放货 |
| | | var occupiedStation = OutTaskStationIsOccupied(task); |
| | | if (occupiedStation == null) |
| | |
| | | |
| | | return stackerCraneTaskCommand; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 写入信号并验证写入结果 |
| | | /// </summary> |
| | | /// <param name="conveyorLine">输送线对象</param> |
| | | /// <param name="address">协议地址</param> |
| | | /// <param name="signal">信号值</param> |
| | | /// <param name="deviceName">设备名称</param> |
| | | void WriteSignal(CommonConveyorLine_After conveyorLine, string address, bool signal, string deviceName) |
| | | { |
| | | string str = string.Empty; |
| | | |
| | | // 写入信号 |
| | | conveyorLine.Communicator.Write(address, signal); |
| | | |
| | | // 验证写入结果,最多重试5次 |
| | | for (int i = 0; i < 5; i++) |
| | | { |
| | | var isWrite = conveyorLine.Communicator.Read<bool>(address); |
| | | if (isWrite == signal) |
| | | { |
| | | break; |
| | | } |
| | | conveyorLine.Communicator.Write(address, signal); |
| | | } |
| | | |
| | | // 最终验证写入结果 |
| | | var finalWrite = conveyorLine.Communicator.Read<bool>(address); |
| | | if (finalWrite == signal) |
| | | { |
| | | str = $"{address}-写入{signal}成功"; |
| | | ConsoleHelper.WriteColorLine(str, ConsoleColor.Blue); |
| | | WriteInfo(deviceName, str); |
| | | } |
| | | else |
| | | { |
| | | str = $"{address}-写入{signal}失败"; |
| | | ConsoleHelper.WriteColorLine(str, ConsoleColor.Red); |
| | | WriteInfo(deviceName, str); |
| | | } |
| | | } |
| | | } |
| | | } |