using AutoMapper; using HslCommunication; using Newtonsoft.Json; using Quartz; using SqlSugar; using System.Reflection; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_BasicInfoService; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_Core.HttpContextUser; using WIDESEAWCS_DTO.MOM; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_IProcessRepository; using WIDESEAWCS_ISystemServices; using WIDESEAWCS_ITaskInfo_HtyRepository; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DeviceBase; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Repository; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_SignalR; using WIDESEAWCS_Tasks.ConveyorLineJob; using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] public partial class CommonConveyorLineJob : JobBase, IJob { private readonly ITaskService _taskService; private readonly ITaskRepository _taskRepository; private readonly ITask_HtyRepository _task_HtyRepository; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly IRouterService _routerService; private readonly IPlatFormRepository _platFormRepository; private readonly ISys_ConfigService _sys_ConfigService; private readonly IMapper _mapper; private readonly IDt_StationManagerService _stationManagerService; private readonly IDt_StationManagerRepository _stationManagerRepository; private readonly ICacheService _cacheService; private readonly INoticeService _noticeService; private readonly IDeviceInfoRepository _deviceInfoRepository; private static List<string>? userTokenIds; private static List<int>? userIds; public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerService stationManagerService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService, IDeviceInfoRepository deviceInfoRepository, ITask_HtyRepository task_HtyRepository) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _routerService = routerService; _mapper = mapper; _taskRepository = taskRepository; _platFormRepository = platFormRepository; _sys_ConfigService = sys_ConfigService; _stationManagerService = stationManagerService; _stationManagerRepository = stationManagerRepository; _cacheService = cacheService; _noticeService = noticeService; _deviceInfoRepository = deviceInfoRepository; _task_HtyRepository = task_HtyRepository; } public async Task Execute(IJobExecutionContext context) { string jobName = context.JobDetail.Key.Name; try { // 从JobDataMapä¸èŽ·å–ä¼ é€’çš„å‚æ•° CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams"); if (conveyorLine != null) { //ConsoleHelper.WriteColorLine("开始:" + DateTime.Now, ConsoleColor.Cyan); // 查询所有å设备的ä½ç½® List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); // èŽ·å–æ‰€æœ‰ç«™ç‚¹ç®¡ç†å™¨ List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); // å¹¶è¡Œå¤„ç†æ¯ä¸ªå设备 var tasks = childDeviceCodes.Select(childDeviceCode => ProcessDeviceAsync(conveyorLine, childDeviceCode)).ToList(); // å¹¶è¡Œå¤„ç†æ¯ä¸ªç«™ç‚¹ç®¡ç†å™¨ tasks = stationManagers.Select(station => Task.Run(async () => { var (command, commandWrite) = ReadCommands(station, conveyorLine); if (command == null || commandWrite == null) { return; } IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this); await handler.HandleStationAsync(conveyorLine, station, command, commandWrite); })).ToList(); #region //foreach (var station in stationManagers) //{ // #region // //tasks.Add(Task.Run(async () => // //{ // // if (station.stationType == 11) // // { // // // 读å–任务命令和设备命令 // // ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); // // ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); // // if (command != null && commandWrite != null) // // { // // // 将交互信å·è½¬æ¢ä¸ºå¸ƒå°”数组 // // var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray(); // // if (structs[0] == true) // // { // // // 输出è¦å‘Šä¿¡æ¯ // // var log = $"ã€{conveyorLine.DeviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{station.stationChildCode}】空托盘请求扫ç 入库"; // // ConsoleHelper.WriteWarningLine(log); // // await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); // // WriteInfo(conveyorLine.DeviceName, log); // // // 处ç†å…¥åº“请求 // // NGRequestTaskInbound(conveyorLine, command, station, 0); // // } // // else // // { // // // å‘é€å®Œæˆä¿¡å· // // ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false); // // } // // } // // } // // else if (station.stationType == 5) // // { // // // 读å–任务命令和设备命令 // // ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); // // ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); // // if (command != null && commandWrite != null) // // { // // // 将交互信å·è½¬æ¢ä¸ºå¸ƒå°”数组 // // var structs = BitConverter.GetBytes(commandWrite.WriteInteractiveSignal).Reverse().ToArray().ToBoolArray(); // // if (structs[0] == true) // // { // // // 检查是å¦å˜åœ¨ä»»åŠ¡ // // if (_taskRepository.QueryData(x => x.SourceAddress == station.stationChildCode).Count() > 0) // // { // // return; // // } // // // 输出è¦å‘Šä¿¡æ¯ // // var log = $"ã€{conveyorLine.DeviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{station.stationChildCode}】异常å£è¯·æ±‚扫ç 入库"; // // ConsoleHelper.WriteWarningLine(log); // // await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); // // WriteInfo(conveyorLine.DeviceName, log); // // // å¤„ç†æ–°ä»»åŠ¡ // // await HandleNewTaskAsync(conveyorLine, command, station.stationChildCode, 0); // // } // // else // // { // // // å‘é€å®Œæˆä¿¡å· // // ConveyorLineSendFinish(conveyorLine, station.stationChildCode, 0, false); // // } // // } // // } // //})); // #endregion // tasks.Add(Task.Run(async () => // { // var (command, commandWrite) = ReadCommands(station, conveyorLine); // if (command == null || commandWrite == null) // { // return; // } // IStationHandler handler = StationHandlerFactory.GetHandler(station.stationType, this); // await handler.HandleStationAsync(conveyorLine, station, command, commandWrite); // })); //} #endregion await Task.WhenAll(tasks); //ConsoleHelper.WriteColorLine("结æŸï¼š" + DateTime.Now, ConsoleColor.Cyan); } } catch (Exception ex) { // è¾“å‡ºå¼‚å¸¸ä¿¡æ¯ Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); } return; } private Task ProcessDeviceAsync(CommonConveyorLine conveyorLine, string childDeviceCode) { try { // 读å–任务命令和设备命令 ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode); ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(childDeviceCode, "DeviceCommand"); if (command != null && commandWrite != null) { #region 调用事件总线通知å‰ç«¯ // 获å–缓å˜ä¸çš„ç”¨æˆ·ä¿¡æ¯ var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); if (tokenInfos != null && tokenInfos.Any()) { userTokenIds = tokenInfos.Select(x => x.Token_ID).ToList(); userIds = tokenInfos.Select(x => x.UserId).ToList(); // æž„é€ é€šçŸ¥æ•°æ® object obj = new { command, commandWrite }; // å‘é€é€šçŸ¥ _noticeService.LineData(userIds.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, childDeviceCode, data = obj }); } #endregion 调用事件总线通知å‰ç«¯ // 将交互信å·è½¬æ¢ä¸ºå¸ƒå°”数组 var writeInteractiveSignal = commandWrite.WriteInteractiveSignal; var structs = BitConverter.GetBytes(writeInteractiveSignal).Reverse().ToArray().ToBoolArray(); // 获å–设备å议详情 List<DeviceProtocolDetailDTO>? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.Where(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)).ToList(); if (deviceProtocolDetails != null) { foreach (var item in deviceProtocolDetails) { int itemValue = item.ProtocalDetailValue.ObjToInt(); if (structs[itemValue] == true) { // 获å–å¤„ç†æ–¹æ³• MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType); if (method != null) { command.InteractiveSignal = writeInteractiveSignal; // è°ƒç”¨å¤„ç†æ–¹æ³• method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, itemValue }); } } else { // å‘é€å®Œæˆä¿¡å· ConveyorLineSendFinish(conveyorLine, childDeviceCode, itemValue, false); } } } // 查询平å°ä¿¡æ¯ Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); if (platform != null && !string.IsNullOrEmpty(platform.Location)) { if (platform.PlatCode == "1299" || platform.PlatCode == "1295" || platform.PlatCode == "1291" || platform.PlatCode == "1287" || platform.PlatCode == "1283") { Platform platformJZ = _platFormRepository.QueryFirst(x => x.PlatCode == "10086" && x.Status == "Active"); if (platformJZ != null) { 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 }); } } } } //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") //{ // ConsoleHelper.WriteSuccessLine("ProcessDeviceAsyncæ–¹æ³•ç»“æŸæ—¶é—´ï¼š" + DateTime.Now.ToString("G") + $"点ä½ï¼š{childDeviceCode}"); //} } } catch (Exception ex) { } return Task.CompletedTask; } #region 入库 /// <summary> /// 输é€çº¿è¯·æ±‚入库 /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> /// <param name="ProtocalDetailValue">线体当å‰bool读å–å移地å€</param> public async Task RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) { try { // 输出è¦å‘Šä¿¡æ¯ï¼Œè¡¨ç¤ºä»»åŠ¡å·²åˆ°è¾¾å设备并请求扫ç 入库 var log = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】请求扫ç 入库"; ConsoleHelper.WriteWarningLine(log); // å‘é€é€šçŸ¥ await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); // 查询æ¡ç 对应的任务 var task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode); if (task != null) { // 如果任务类型是出库或出托盘,则处ç†å‡ºåº“任务 if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray || task.TaskType == (int)TaskOutboundTypeEnum.Outbound) { HandleTaskOut(conveyorLine, command, childDeviceCode, ProtocalDetailValue, task); } else { 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); // æ¢å¤ä»»åŠ¡çš„ä¸‹ä¸€ç›®æ ‡åœ°å€ task.NextAddress = next; // å‘é€å‘½ä»¤åˆ°å设备 conveyorLine.SendCommand(taskCommand, childDeviceCode); // 输出è¦å‘Šä¿¡æ¯ï¼Œè¡¨ç¤ºä»»åŠ¡å·²åˆ°è¾¾å设备并请求扫ç å…¥åº“ï¼Œä¸‹ä¸€ç›®æ ‡åœ°å€ var logs = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】请求扫ç 入库,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€{taskCommand.TargetAddress}】"; ConsoleHelper.WriteWarningLine(logs); await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, logs); // å‘é€ä»»åŠ¡å®Œæˆé€šçŸ¥ ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); // 更新任务状æ€ä¸ºä¸‹ä¸€çŠ¶æ€ _taskService.UpdateTaskStatusToNext(task); } } } else { var taskInTray = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); if (taskInTray != null && taskInTray.TaskType == (int)TaskInboundTypeEnum.InTray) { RequestInNextAddress(conveyorLine, command, childDeviceCode, ProtocalDetailValue); } else { // 如果任务为空且æ¡ç ä¸ä¸º"NoRead"且æ¡ç ä¸ä¸ºç©ºï¼Œåˆ™å¤„ç†æ–°ä»»åŠ¡ if (task == null && command.Barcode != "NoRead" && command.Barcode.IsNotEmptyOrNull()) { // 查询æ¡ç 对应的任务 task = _taskService.QueryBarcodeTask(command.Barcode, childDeviceCode); if (task == null) { // 异æ¥å¤„ç†æ–°ä»»åŠ¡ await HandleNewTaskAsync(conveyorLine, command, childDeviceCode, ProtocalDetailValue); } } } } } catch (Exception ex) { // æ•èŽ·å¹¶è¾“å‡ºå¼‚å¸¸ä¿¡æ¯ Console.Out.WriteLine(ex.ToString()); } finally { StaticVariable.isLineRun = true; } } public string RequestInboundPlatform(string childDeviceCode, string productLine, bool IsTrayBarcode) { try { Platform platform = _platFormRepository.QueryFirst(x => x.PlatCode == childDeviceCode && x.ProductionLine == productLine && x.Status == "Active"); if (platform != null && !string.IsNullOrEmpty(platform.Location)) { var Location = platform.Location.Split(',').ToList(); IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == platform.DeviceCode); if (device != null) { CommonConveyorLine conveyorLine = (CommonConveyorLine)device; foreach (var item in Location) { ConveyorLineTaskCommand command1 = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item); if (command1.InteractiveSignal != 2) { var tasks = _taskRepository.QueryData(x => x.TargetAddress == childDeviceCode); // 如果已有任务数é‡å°äºŽæŒ‡å®šç´¢å¼• 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处ç†é™ˆåŒ–未执行的空托出库任务 //} return null; } } } return null; } else { ConsoleHelper.WriteErrorLine($"未找到节点{childDeviceCode}åè®®"); throw new InvalidOperationException($"未找到节点{childDeviceCode}åè®®"); } } } catch (Exception ex) { ConsoleHelper.WriteErrorLine($"方法RequestInboundPlatform:{ex.Message}"); } return null; } #region 输é€çº¿è¯·æ±‚å…¥åº“ä¸‹ä¸€åœ°å€ /// <summary> /// 输é€çº¿è¯·æ±‚å…¥åº“ä¸‹ä¸€åœ°å€ /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) { var log = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】请求入库下一地å€"; ConsoleHelper.WriteWarningLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); if (task != null) { if (command.Barcode == task.PalletCode) { Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); if (newTask != null) { //ConveyorLineTaskCommand taskCommand = _mapper.Map<ConveyorLineTaskCommand>(newTask); //taskCommand.InteractiveSignal = command.InteractiveSignal; var next = newTask.NextAddress; var taskCommand = MapTaskCommand(newTask, command); newTask.NextAddress = next; var logs = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】请求入库下一地å€,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€{taskCommand.TargetAddress}】"; ConsoleHelper.WriteWarningLine(logs); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, logs); conveyorLine.SendCommand(taskCommand, childDeviceCode); ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); } } } } #endregion 输é€çº¿è¯·æ±‚å…¥åº“ä¸‹ä¸€åœ°å€ /// <summary> /// 输é€çº¿å…¥åº“å®Œæˆ /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> /// <param name="ProtocalDetailValue">线体当å‰bool读å–å移地å€</param> public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) { try { var log = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿å…¥åº“完æˆ"; ConsoleHelper.WriteWarningLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish) { if (command.Barcode == task.PalletCode && childDeviceCode == task.NextAddress) { conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, "1000", childDeviceCode); var logs = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿å…¥åº“完æˆ,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€ç‰å¾…分é…è´§ä½,并写入1000】"; ConsoleHelper.WriteWarningLine(logs); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, logs); ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); if (task.TaskType == (int)TaskInboundTypeEnum.InNG) { int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); var station = _stationManagerRepository.QueryFirst(x => x.stationChildCode == task.SourceAddress); task.CurrentAddress = station.stationLocation; task.NextAddress = station.stationNGLocation; task.TargetAddress = task.NextAddress; task.TaskState = nextStatus; task.ModifyDate = DateTime.Now; task.Modifier = "System"; _taskRepository.UpdateData(task); } else { WebResponseContent content = _taskService.UpdateTaskStatusToNext(task); Console.Out.WriteLine(content.ToJsonString()); } } } } catch (Exception ex) { } } #endregion 入库 #region 出库 /// <summary> /// 输é€çº¿è¯·æ±‚å‡ºåº“ä¿¡æ¯ /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> /// <param name="ProtocalDetailValue">线体当å‰bool读å–å移地å€</param> public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) { try { // 查询输é€çº¿ä»»åŠ¡ï¼Œæ ¹æ®è¾“é€çº¿è®¾å¤‡å’Œå设备代ç 获å–ä»»åŠ¡ä¿¡æ¯ var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); // 输出æˆåŠŸä¿¡æ¯ï¼ŒåŒ…括输é€çº¿åç§°ã€ä»»åŠ¡å·ã€æ‰˜ç›˜æ¡ç å’Œå设备代ç ,以åŠä»»åŠ¡ä¿¡æ¯ var logs = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿è¯·æ±‚出库,task{task.ToJsonString()}"; ConsoleHelper.WriteSuccessLine(logs); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, logs); // 如果任务ä¸ä¸ºç©ºï¼Œåˆ™æ‰§è¡Œä»¥ä¸‹æ“作 if (task != null) { // 获å–ä»»åŠ¡çš„ä¸‹ä¸€ç›®æ ‡åœ°å€ var next = task.NextAddress; // å°†ä»»åŠ¡å‘½ä»¤æ˜ å°„åˆ°å½“å‰ä»»åŠ¡ var taskCommand = MapTaskCommand(task, command); // æ¢å¤ä»»åŠ¡çš„ä¸‹ä¸€ç›®æ ‡åœ°å€ task.NextAddress = next; // 输出æˆåŠŸä¿¡æ¯ï¼ŒåŒ…括输é€çº¿åç§°ã€ä»»åŠ¡å·ã€æ‰˜ç›˜æ¡ç ã€å设备代ç å’Œä¸‹ä¸€ç›®æ ‡åœ°å€ var log = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿è¯·æ±‚出库,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€{taskCommand.TargetAddress}】"; ConsoleHelper.WriteSuccessLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); // å‘输é€çº¿å‘é€å‘½ä»¤ conveyorLine.SendCommand(taskCommand, childDeviceCode); // 完æˆè¾“é€çº¿å‘é€ä»»åŠ¡ï¼Œå¹¶æ›´æ–°ä»»åŠ¡çŠ¶æ€ ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); // 更新任务状æ€åˆ°ä¸‹ä¸€ä¸ªçŠ¶æ€ _taskService.UpdateTaskStatusToNext(task); // å¦‚æžœä»»åŠ¡çš„ç›®æ ‡åœ°å€æ˜¯"1020-1"ï¼Œåˆ™å†æ¬¡æ›´æ–°ä»»åŠ¡çŠ¶æ€åˆ°ä¸‹ä¸€ä¸ªçŠ¶æ€ if (task.TargetAddress == "1020-1") { _taskService.UpdateTaskStatusToNext(task); } } } catch (Exception ex) { } } /// <summary> /// 输é€çº¿è¯·æ±‚å‡ºåº“ä¸‹ä¸€åœ°å€ /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) { // æ‰“å°æˆåŠŸæ—¥å¿—ï¼Œæ˜¾ç¤ºå½“å‰è®¾å¤‡åç§°ã€ä»»åŠ¡å·ã€æ‰˜ç›˜æ¡ç 以åŠè¯·æ±‚出库下一地å€çš„å设备代ç var log = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿è¯·æ±‚出库下一地å€"; ConsoleHelper.WriteSuccessLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); // 查询æ£åœ¨æ‰§è¡Œçš„输é€çº¿ä»»åŠ¡ï¼Œæ ¹æ®ä»»åŠ¡å·å’Œå设备代ç 获å–ä»»åŠ¡ä¿¡æ¯ Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); // 如果任务å˜åœ¨ if (task != null) { // 检查任务ä¸çš„æ‰˜ç›˜æ¡ç 是å¦ä¸Žå‘½ä»¤ä¸çš„æ‰˜ç›˜æ¡ç 一致 if (command.Barcode == task.PalletCode) { // 更新任务的ä½ç½®ä¿¡æ¯ï¼Œå¹¶èŽ·å–æ›´æ–°åŽçš„任务对象 Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); // 如果更新åŽçš„任务对象ä¸ä¸ºç©º if (newTask != null) { // 获å–ä¸‹ä¸€ç›®æ ‡åœ°å€ var next = newTask.NextAddress; // å°†æ–°ä»»åŠ¡å¯¹è±¡æ˜ å°„ä¸ºä»»åŠ¡å‘½ä»¤å¯¹è±¡ var taskCommand = MapTaskCommand(newTask, command); // æ¢å¤æ–°ä»»åŠ¡å¯¹è±¡çš„ä¸‹ä¸€ç›®æ ‡åœ°å€ newTask.NextAddress = next; // æ‰“å°æˆåŠŸæ—¥å¿—ï¼Œæ˜¾ç¤ºå½“å‰è®¾å¤‡åç§°ã€ä»»åŠ¡å·ã€æ‰˜ç›˜æ¡ç ã€å设备代ç 以åŠä¸‹ä¸€ç›®æ ‡åœ°å€ var logs = $"ã€{conveyorLine._deviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿è¯·æ±‚出库下一地å€,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€{taskCommand.TargetAddress}】"; ConsoleHelper.WriteSuccessLine(logs); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, logs); // å‘é€ä»»åŠ¡å‘½ä»¤åˆ°å设备 conveyorLine.SendCommand(taskCommand, childDeviceCode); // æ ‡è®°è¾“é€çº¿å‘é€ä»»åŠ¡å®Œæˆ ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); } } } } /// <summary> /// 输é€çº¿å‡ºåº“å®Œæˆ /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) { try { // æ‰“å°æˆåŠŸä¿¡æ¯ï¼Œè¡¨ç¤ºæ‰˜ç›˜å·²åˆ°è¾¾æŒ‡å®šè¾“é€çº¿å¹¶å®Œæˆå‡ºåº“ var logs = $"ã€{conveyorLine.DeviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿å‡ºåº“完æˆ"; ConsoleHelper.WriteSuccessLine(logs); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = logs, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, logs); // 查询æ£åœ¨æ‰§è¡Œçš„输é€çº¿ä»»åŠ¡ var task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode); // 如果任务å˜åœ¨ if (task != null) { // 如果任务ä¸çš„æ‰˜ç›˜æ¡ç 与命令ä¸çš„æ‰˜ç›˜æ¡ç 一致 if (command.Barcode == task.PalletCode) { // 创建一个空的WebResponseContent对象 WebResponseContent content = new WebResponseContent(); // ä¿å˜ä»»åŠ¡çš„ä¸‹ä¸€ç›®æ ‡åœ°å€ var next = task.NextAddress; // å°†ä»»åŠ¡æ˜ å°„ä¸ºå‘½ä»¤ var taskCommand = MapTaskCommand(task, command); // æ¢å¤ä»»åŠ¡çš„ä¸‹ä¸€ç›®æ ‡åœ°å€ task.NextAddress = next; // 如果任务的托盘æ¡ç 与命令ä¸çš„æ‰˜ç›˜æ¡ç ä¸ä¸€è‡´æˆ–者任务备注为"NG" if (task.PalletCode != command.Barcode || task.Remark == "NG") { // æŸ¥è¯¢ç›®æ ‡åœ°å€çš„å®¹é‡ var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity; // è®¾ç½®å‘½ä»¤çš„ç›®æ ‡åœ°å€ä¸ºNGåœ°å€ taskCommand.TargetAddress = NGAddress; } else { // è®¾ç½®å‘½ä»¤çš„ç›®æ ‡åœ°å€ä¸º1000 taskCommand.TargetAddress = 1000; } // æ‰“å°æˆåŠŸä¿¡æ¯ï¼Œè¡¨ç¤ºæ‰˜ç›˜å·²åˆ°è¾¾æŒ‡å®šè¾“é€çº¿å¹¶å®Œæˆå‡ºåº“ï¼Œä¸‹ä¸€ç›®æ ‡åœ°å€å·²ç¡®å®š var log = $"ã€{conveyorLine.DeviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿å‡ºåº“完æˆ,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€{taskCommand.TargetAddress}】"; ConsoleHelper.WriteSuccessLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); // å‘é€å‘½ä»¤åˆ°è¾“é€çº¿ conveyorLine.SendCommand(taskCommand, childDeviceCode); // 完æˆè¾“é€çº¿å‘é€ ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); // 更新任务状æ€åˆ°ä¸‹ä¸€ä¸ªçŠ¶æ€ content = _taskService.UpdateTaskStatusToNext(task); } else { // æŸ¥è¯¢ç›®æ ‡åœ°å€çš„å®¹é‡ var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity; // æ‰“å°æˆåŠŸä¿¡æ¯ï¼Œè¡¨ç¤ºæ‰˜ç›˜å·²åˆ°è¾¾æŒ‡å®šè¾“é€çº¿å¹¶å®Œæˆå‡ºåº“ï¼Œä¸‹ä¸€ç›®æ ‡åœ°å€å·²ç¡®å®š var log = $"ã€{conveyorLine.DeviceName}】任务å·ï¼šã€{command.TaskNum}】,托盘æ¡ç :ã€{command.Barcode}】已到达ã€{childDeviceCode}】输é€çº¿å‡ºåº“完æˆ,ä¸‹ä¸€ç›®æ ‡åœ°å€ã€{NGAddress}】"; ConsoleHelper.WriteSuccessLine(log); _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); // 设置输é€çº¿çš„ç›®æ ‡åœ°å€ä¸ºNGåœ°å€ conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, NGAddress, childDeviceCode); // 完æˆè¾“é€çº¿å‘é€ ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); // 更新任务状æ€åˆ°ä¸‹ä¸€ä¸ªçŠ¶æ€ _taskService.UpdateTaskStatusToNext(task); } } } catch (Exception ex) { } } #endregion 出库 #region 输é€çº¿äº¤äº’å®Œæˆ /// <summary> /// 输é€çº¿äº¤äº’å®Œæˆ /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="childDeviceCode">å设备编å·</param> /// <param name="ProtocalDetailValue">线体当å‰bool读å–å移地å€</param> /// <param name="value">值</param> public void ConveyorLineSendFinish(CommonConveyorLine conveyorLine, string childDeviceCode, int ProtocalDetailValue, bool value) { // 从conveyorLineä¸çš„DeviceProDTOsåˆ—è¡¨ä¸æŸ¥æ‰¾ç¬¬ä¸€ä¸ªç¬¦åˆæ¡ä»¶çš„DeviceProDTO对象 // æ¡ä»¶æ˜¯DeviceProParamTypeç‰äºŽDeviceCommand,且DeviceChildCodeç‰äºŽchildDeviceCode // 查找结果按DeviceProOffsetå‡åºæŽ’列 DeviceProDTO? devicePro = conveyorLine.DeviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == childDeviceCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); // å°†deviceProçš„DeviceProAddress按'.'分割æˆå—符串数组x string[] x = devicePro.DeviceProAddress.Split('.'); // 将数组x的最åŽä¸€ä¸ªå…ƒç´ 替æ¢ä¸ºProtocalDetailValueåŠ 1åŽçš„å—ç¬¦ä¸²å½¢å¼ x[x.Length - 1] = (ProtocalDetailValue + 1).ToString(); // 将修改åŽçš„æ•°ç»„x釿–°æ‹¼æŽ¥æˆå—符串,作为新的DeviceProAddress string DeviceProAddress = string.Join(".", x); var writeBool = conveyorLine.Communicator.Read<bool>(DeviceProAddress); if (writeBool != value) { // 使用conveyorLineçš„Communicator对象的Write方法,将value写入新的DeviceProAddressåœ°å€ conveyorLine.Communicator.Write(DeviceProAddress, value); } } #endregion #region 检测空盘实盘任务 /// <summary> /// 监测空托盘实盘出库 /// </summary> /// <param name="conveyorLine">输é€çº¿å®žä¾‹å¯¹è±¡</param> /// <param name="command">读å–的请求信æ¯</param> /// <param name="childDeviceCode">å设备编å·</param> /// <param name="index">线体当å‰bool读å–å移地å€</param> // å®šä¹‰ä¸€ä¸ªå¼‚æ¥æ–¹æ³•,用于处ç†ç©ºæ‰˜ç›˜è¿”回任务 public async void EmptyTrayReturn(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int index, Platform platform) { try { // 定义任务类型枚举å˜é‡ TaskOutboundTypeEnum taskOutboundTypeEnum; // æ ¹æ®å¹³å°ç±»åž‹è®¾ç½®ä»»åŠ¡ç±»åž‹æžšä¸¾ if (platform.PlatformType.Contains("OutTray")) taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray; else taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound; // 调用检查并创建任务的方法 await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform); } catch (Exception) { // æ•获并忽略异常 } } /// <summary> /// 检查任务并创建新任务 /// </summary> private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, Platform platform) { // 查询数æ®åº“ä¸å·²æœ‰çš„任务 var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode); // 如果已有任务数é‡å°äºŽæŒ‡å®šç´¢å¼• if (tasks.Count < index) { // 调用WMS获å–出库任务 #region 调用WMS获å–出库任务 // 定义WMS任务数æ®ä¼ 输对象 WMSTaskDTO taskDTO = new WMSTaskDTO(); // 获å–WMS IP地å€é…ç½® var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var requestTrayOutTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayOutTask)?.ConfigValue; // 如果WMS IPåœ°å€æœªé…置,抛出异常 if (wmsBase == null || requestTrayOutTask == null) { throw new InvalidOperationException("WMS IP 未é…ç½®"); } var wmsIpAddress = wmsBase + requestTrayOutTask; var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1"); var deviceCode = device.Select(x => x.DeviceCode).ToList(); // å‘é€HTTP POST请求获å–ä»»åŠ¡æ•°æ® var result = await HttpHelper.PostAsync(wmsIpAddress, new { position = childDeviceCode, tag = (int)taskType, areaCdoe = platform.Stacker, AreaCdoes = deviceCode, platform.ProductionLine }.ToJsonString()); // è§£æžè¿”回的JSONæ•°æ® WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); // 检查返回状æ€ï¼Œå¦‚果失败则返回 if (!content.Status) return; // è§£æžä»»åŠ¡æ•°æ® taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); #endregion 调用WMS获å–出库任务 // 创建并å‘é€ä»»åŠ¡ CreateAndSendTask(taskDTO); } } /// <summary> /// 创建任务 /// </summary> public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO) { var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); if (content.Status) { Console.WriteLine($"{taskDTO.TargetAddress}呼嫿ˆåŠŸ"); } return content; } #endregion 检测空盘实盘任务 #region 设备NGå£å…¥åº“ public void NGRequestTaskInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, Dt_StationManager stationManager, int ProtocalDetailValue) { var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue; var ipAddress = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.TrayCellsStatus)?.ConfigValue; if (wmsBase == null || ipAddress == null) { throw new InvalidOperationException("MOM IP 未é…ç½®"); } TrayCellsStatusDto trayCells = new TrayCellsStatusDto() { Software = "WMS", TrayBarcode = command.Barcode, EquipmentCode = stationManager.stationEquipMOM, SessionId = Guid.NewGuid().ToString(), EmployeeNo = "MITest", SceneType = "4", RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") }; var MOMIpAddress = wmsBase + ipAddress; var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.ToJsonString()).Result; WriteInfo("å…¥ç«™æ ¡éªŒ", $"ã€{stationManager.stationChildCode}ã€‘å…¥ç«™æ ¡éªŒè¯·æ±‚å‚æ•°ã€{trayCells.ToJsonString()}】"); WriteInfo("å…¥ç«™æ ¡éªŒ", ""); WriteInfo("å…¥ç«™æ ¡éªŒ", $"ã€{stationManager.stationChildCode}ã€‘å…¥ç«™æ ¡éªŒè¿”å›žå‚æ•°ã€{result}】"); ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result); if (result1.Success) { var serialNosError = result1.SerialNos.Where(x => x.SerialNoStatus != 1 && x.SerialNoStatus != 4).ToList(); if (serialNosError.Count > 0) { conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, 100, stationManager.stationChildCode); ConveyorLineSendFinish(conveyorLine, stationManager.stationChildCode, ProtocalDetailValue, true); return; } //设备NGå¤„ç† if (stationManager.remark == "DeviceNG") { ConsoleHelper.WriteWarningLine($"ã€{stationManager.stationChildCode}NGç«™å°å®žæ‰˜å…¥åº“】"); if (result1.SerialNos.Count <= 0) { ConsoleHelper.WriteWarningLine("1000"); conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode); conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, 1000, stationManager.stationChildCode); } else { ConsoleHelper.WriteWarningLine($"ã€{stationManager.stationChildCode}NGç«™å°ç©ºæ‰˜å…¥è®¾å¤‡ã€‘"); ConsoleHelper.WriteWarningLine(stationManager.stationLocation); conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode); conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, stationManager.stationLocation, stationManager.stationChildCode); } ConveyorLineSendFinish(conveyorLine, stationManager.stationChildCode, ProtocalDetailValue, true); } else { if (result1.SerialNos.Count <= 0) { 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($"ã€{stationManager.stationChildCode}NGç«™å°å®žæ‰˜å…¥è®¾å¤‡ã€‘"); conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, 5, stationManager.stationChildCode); conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, 1000, stationManager.stationChildCode); } ConveyorLineSendFinish(conveyorLine, stationManager.stationChildCode, ProtocalDetailValue, true); } } else { ConsoleHelper.WriteErrorLine(result1.MOMMessage); } } #endregion 设备NGå£å…¥åº“ #region 输出日志 public async Task LogAndWarn(string deviceName, string log, string color = "red") { ConsoleHelper.WriteWarningLine(log); await _noticeService.Logs(userTokenIds, new { deviceName, log = log, time = DateTime.Now.ToString("G"), color = color }); WriteInfo(deviceName, log); } #endregion private (ConveyorLineTaskCommand, ConveyorLineTaskCommandWrite) ReadCommands(Dt_StationManager station, CommonConveyorLine conveyorLine) { ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.stationChildCode); ConveyorLineTaskCommandWrite commandWrite = conveyorLine.ReadCustomer<ConveyorLineTaskCommandWrite>(station.stationChildCode, "DeviceCommand"); return (command, commandWrite); } } }