| | |
| | | using AutoMapper; |
| | | using HslCommunication; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using NetTaste; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using SqlSugar; |
| | | using System.Drawing; |
| | | using System.Reflection; |
| | | using System.Security.Policy; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_BasicInfoRepository; |
| | | using WIDESEAWCS_BasicInfoService; |
| | | using WIDESEAWCS_Common; |
| | |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_SignalR; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; |
| | | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | |
| | | } |
| | | |
| | | // 查询平台信息 |
| | | Platform platform = _platFormRepository.QueryFirst(x => x.PLCCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); |
| | | Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); |
| | | if (platform != null && !string.IsNullOrEmpty(platform.Location)) |
| | | { |
| | | var strings = platform.Location.Split(',').ToList(); |
| | | foreach (var ite in strings) |
| | | if (platform.PlatCode == "1299" || platform.PlatCode == "1295" || platform.PlatCode == "1291" || platform.PlatCode == "1287" || platform.PlatCode == "1283") |
| | | { |
| | | // 读取任务命令 |
| | | ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite); |
| | | if (command1.InteractiveSignal != 2) |
| | | Platform platformJZ = _platFormRepository.QueryFirst(x => x.PlatCode == "10086" && x.Status == "Active"); |
| | | if (platformJZ != null) |
| | | { |
| | | command.InteractiveSignal = writeInteractiveSignal; |
| | | int count = strings.Count; |
| | | // 获取处理方法 |
| | | MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod); |
| | | if (method != null) |
| | | var strings = platform.Location.Split(',').ToList(); |
| | | foreach (var ite in strings) |
| | | { |
| | | command.InteractiveSignal = commandWrite.WriteInteractiveSignal; |
| | | // 调用处理方法 |
| | | method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform }); |
| | | // 读取任务命令 |
| | | ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite); |
| | | if (command1.InteractiveSignal != 2) |
| | | { |
| | | command.InteractiveSignal = writeInteractiveSignal; |
| | | int count = strings.Count; |
| | | // 获取处理方法 |
| | | MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod); |
| | | if (method != null) |
| | | { |
| | | command.InteractiveSignal = commandWrite.WriteInteractiveSignal; |
| | | // 调用处理方法 |
| | | method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform }); |
| | | } |
| | | |
| | | } |
| | | } |
| | | ; |
| | | } |
| | | //else |
| | | //{ |
| | | // //ConsoleHelper.WriteErrorLine("静置空托不允许出料"); |
| | | //} |
| | | } |
| | | else |
| | | { |
| | | var strings = platform.Location.Split(',').ToList(); |
| | | foreach (var ite in strings) |
| | | { |
| | | // 读取任务命令 |
| | | ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(ite); |
| | | if (command1.InteractiveSignal != 2) |
| | | { |
| | | command.InteractiveSignal = writeInteractiveSignal; |
| | | int count = strings.Count; |
| | | // 获取处理方法 |
| | | MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod); |
| | | if (method != null) |
| | | { |
| | | command.InteractiveSignal = commandWrite.WriteInteractiveSignal; |
| | | // 调用处理方法 |
| | | method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform }); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //if (conveyorLine.DeviceCode == "1001") |
| | | //{ |
| | |
| | | } |
| | | else |
| | | { |
| | | // 获取任务的下一目标地址 |
| | | var next = task.NextAddress; |
| | | if (task.Roadway.Contains("JZ")) |
| | | { |
| | | if (StaticVariable.isStackerRun) |
| | | { |
| | | StaticVariable.isLineRun = false; |
| | | ExecuteConveyorLineTask(conveyorLine, command, ProtocalDetailValue, childDeviceCode); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 获取任务的下一目标地址 |
| | | var next = task.NextAddress; |
| | | // 将任务映射为命令 |
| | | var taskCommand = MapTaskCommand(task, command); |
| | | // 恢复任务的下一目标地址 |
| | |
| | | ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | // 更新任务状态为下一状态 |
| | | _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 如果任务为空且条码不为"NoRead"且条码不为空,则处理新任务 |
| | | if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull()) |
| | | var taskInTray = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); |
| | | if (taskInTray != null && taskInTray.TaskType == (int)TaskInboundTypeEnum.InTray) |
| | | { |
| | | // 查询条码对应的任务 |
| | | task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode); |
| | | if (task == null) |
| | | RequestInNextAddress(conveyorLine, command, childDeviceCode, ProtocalDetailValue); |
| | | } |
| | | else |
| | | { |
| | | // 如果任务为空且条码不为"NoRead"且条码不为空,则处理新任务 |
| | | if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull()) |
| | | { |
| | | // 异步处理新任务 |
| | | await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue); |
| | | // 查询条码对应的任务 |
| | | task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode); |
| | | if (task == null) |
| | | { |
| | | // 异步处理新任务 |
| | | await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | // 捕获并输出异常信息 |
| | | Console.Out.WriteLine(ex.ToString()); |
| | | } |
| | | finally |
| | | { |
| | | StaticVariable.isLineRun = true; |
| | | } |
| | | } |
| | | |
| | |
| | | if (platform != null && !string.IsNullOrEmpty(platform.Location)) |
| | | { |
| | | var Location = platform.Location.Split(',').ToList(); |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == platform.PLCCode); |
| | | IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == platform.DeviceCode); |
| | | if (device != null) |
| | | { |
| | | int x = 3; |
| | | CommonConveyorLine conveyorLine = (CommonConveyorLine)device; |
| | | foreach (var item in Location) |
| | | { |
| | | x--; |
| | | ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item); |
| | | if (command1.InteractiveSignal != 2) |
| | | { |
| | | var tasks = _taskRepository.QueryData(x => (x.TaskType == (int)TaskInboundTypeEnum.InTray || x.TaskType == (int)TaskOutboundTypeEnum.OutTray) && x.TargetAddress == childDeviceCode); |
| | | var tasks = _taskRepository.QueryData(x => x.TargetAddress == childDeviceCode); |
| | | |
| | | // 如果已有任务数量小于指定索引 |
| | | if (tasks.Count < Location.Count && tasks.Count < x) |
| | | if (tasks.Count < Location.Count) |
| | | { |
| | | return childDeviceCode; |
| | | } |
| | | else |
| | | { |
| | | var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew); |
| | | if (Hastask != null && Hastask.Count > 0) |
| | | { |
| | | //doto处理陈化未执行的空托出库任务 |
| | | } |
| | | //var Hastask = _taskRepository.QueryData(x => x.TaskType == (int)TaskOutboundTypeEnum.OutTray && x.TargetAddress == childDeviceCode && x.Roadway.Contains("CH") && x.TaskState == (int)TaskOutStatusEnum.OutNew); |
| | | //if (Hastask != null && Hastask.Count > 0) |
| | | //{ |
| | | // //doto处理陈化未执行的空托出库任务 |
| | | //} |
| | | return null; |
| | | } |
| | | } |
| | |
| | | |
| | | _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); |
| | | WriteInfo(conveyorLine.DeviceName, log); |
| | | //if (childDeviceCode == "1279") |
| | | //{ |
| | | // var stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode); |
| | | // CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue, stationManager); |
| | | //} |
| | | |
| | | Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); |
| | | if (task != null) |
| | |
| | | WriteInfo(conveyorLine.DeviceName, logs); |
| | | |
| | | conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | |
| | | ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | // 解析任务数据 |
| | | taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); |
| | | WriteInfo("出库", $"【{JsonConvert.SerializeObject(taskDTO)}】"); |
| | | |
| | | #endregion 调用WMS获取出库任务 |
| | | |
| | |
| | | public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO) |
| | | { |
| | | var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | WriteInfo("出库", $"【{JsonConvert.SerializeObject(content)}】"); |
| | | if (content.Status) |
| | | { |
| | | Console.WriteLine($"{taskDTO.TargetAddress}呼叫成功"); |
| | |
| | | |
| | | if (result1.Success) |
| | | { |
| | | ConsoleHelper.WriteWarningLine("1"); |
| | | var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList(); |
| | | if (serialNosError.Count > 0) |
| | | { |
| | |
| | | //设备NG处理 |
| | | if (stationManager.remark == "DeviceNG") |
| | | { |
| | | ConsoleHelper.WriteWarningLine($"【{stationManager.stationChildCode}NG站台入库】"); |
| | | ConsoleHelper.WriteWarningLine($"【{stationManager.stationChildCode}NG站台实托入库】"); |
| | | if (result1.SerialNos.Count <= 0) |
| | | { |
| | | ConsoleHelper.WriteWarningLine("1000"); |
| | |
| | | } |
| | | else |
| | | { |
| | | ConsoleHelper.WriteWarningLine("2"); |
| | | ConsoleHelper.WriteWarningLine($"【{stationManager.stationChildCode}NG站台空托入设备】"); |
| | | ConsoleHelper.WriteWarningLine(stationManager.stationLocation); |
| | | conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, stationManager.stationLocation, stationManager.stationChildCode); |
| | |
| | | { |
| | | if (result1.SerialNos.Count <= 0) |
| | | { |
| | | ConsoleHelper.WriteWarningLine("2"); |
| | | ConsoleHelper.WriteWarningLine($"【{stationManager.stationChildCode}NG站台空托入库】"); |
| | | ConsoleHelper.WriteWarningLine(stationManager.stationLocation); |
| | | conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, stationManager.stationLocation, stationManager.stationChildCode); |
| | | } |
| | | else |
| | | { |
| | | ConsoleHelper.WriteWarningLine("1000"); |
| | | ConsoleHelper.WriteWarningLine($"【{stationManager.stationChildCode}NG站台实托入设备】"); |
| | | conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, 1000, stationManager.stationChildCode); |
| | | } |