| | |
| | | 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); |
| | | |
| | | // è·åææç«ç¹ç®¡çå¨ |
| | | List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); |
| | | foreach (var station in stationManagers) |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ConsoleHelper.WriteColorLine("ç»æï¼" + DateTime.Now, ConsoleColor.Cyan); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | } |
| | | |
| | | #endregion 设å¤NGå£å
¥åº |
| | | |
| | | 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); |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |