| | |
| | | using WIDESEAWCS_Core.Caches; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_DTO.Enum; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ISystemRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_SignalR; |
| | | using WIDESEAWCS_Tasks.StackerCraneJob; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; |
| | | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | |
| | | try |
| | | { |
| | | CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | |
| | | if (commonStackerCrane != null) |
| | | { |
| | | if (!commonStackerCrane.IsEventSubscribed) |
| | |
| | | |
| | | if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Idle) |
| | | { |
| | | if (commonStackerCrane.GetValue<StackerCraneDBName, float>(StackerCraneDBName.Electricity) > 20) |
| | | { |
| | | GetTask(commonStackerCrane); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | commonStackerCrane.DeviceName, |
| | | commonStackerCrane.CurrentTaskNum, |
| | | commonStackerCrane.LastTaskNum, |
| | | SourceAddress = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.SourceAddress), |
| | | TargetAddress = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.TargetAddress), |
| | | SourceAddress = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.StartAddress), |
| | | TargetAddress = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.EndAddress), |
| | | Command = commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Command), |
| | | Electricity = commonStackerCrane.GetValue<StackerCraneDBName, float>(StackerCraneDBName.Electricity), |
| | | }; |
| | |
| | | CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane; |
| | | if (commonStackerCrane != null) |
| | | { |
| | | |
| | | Console.Out.WriteLine("TaskCompleted" + e.TaskNum); |
| | | _taskService.StackCraneTaskCompleted(e.TaskNum); |
| | | commonStackerCrane.SetValue(StackerCraneDBName.TaskCompleted, 1); |
| | | |
| | |
| | | task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | if (task.Roadway == "3") |
| | | { |
| | | if (AGVToSandyEdgeRead(commonStackerCrane)) |
| | | { |
| | | WriteAGVTask(task, commonStackerCrane); |
| | | } |
| | | else |
| | | { |
| | | AGVToSandyEdge(commonStackerCrane); |
| | | } |
| | | |
| | | } |
| | | else if (task.Roadway == "2") |
| | | { |
| | | if (AGVToEdgeBandingRead(commonStackerCrane)) |
| | | { |
| | | WriteAGVTask(task, commonStackerCrane); |
| | | } |
| | | else |
| | | { |
| | | AGVToEdgeBanding(commonStackerCrane); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteAGVTask(task, commonStackerCrane); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | public void WriteAGVTask(Dt_Task task, CommonStackerCrane commonStackerCrane) |
| | | { |
| | | StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task); |
| | | if (stackerCraneTaskCommand != null) |
| | | { |
| | | bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand); |
| | | Thread.Sleep(1000); |
| | | Thread.Sleep(2000); |
| | | if (ReadReceived(commonStackerCrane) == 1) |
| | | { |
| | | WriteConfirm(commonStackerCrane); |
| | | if (Clear(commonStackerCrane)) |
| | | { |
| | | _taskService.UpdateTaskStatusToNext(task.TaskNum); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //读åAGVç¶æ |
| | | public int ReadAGVstatus(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | var deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AGVCraneStatus"); |
| | | return deviceProDTO != null ? commonStackerCrane.Communicator.Read<int>(deviceProDTO.DeviceProAddress) : 99; |
| | | } |
| | | //读åAGV工使¨¡å¼ |
| | | public int ReadAGVworkingmode(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | var deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AGVWorkingmode"); |
| | | return deviceProDTO != null ? commonStackerCrane.Communicator.Read<int>(deviceProDTO.DeviceProAddress) : 99; |
| | | } |
| | | |
| | | //读åä»»å¡å· |
| | | public int Readtasknumber(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | var deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AGVWorkingmode"); |
| | | return deviceProDTO != null ? commonStackerCrane.Communicator.Read<int>(deviceProDTO.DeviceProAddress) : 99; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | return commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Received); |
| | | } |
| | | public void WriteConfirm(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | commonStackerCrane.SetValue(StackerCraneDBName.WriteConfirm, 1); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è°åº¦AGVå»å°è¾¹åºå |
| | |
| | | /// <param name="value"></param> |
| | | public void AGVToEdgeBanding(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | commonStackerCrane.SetValue(StackerCraneDBName.AreaWrite, true); |
| | | DeviceProDTO? devicePro = commonStackerCrane.DeviceProDTOs.Where(x => x.DeviceProParamType == "AreaWrite" && x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AreaWrite").OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | commonStackerCrane.Communicator.Write(devicePro.DeviceProAddress, true); |
| | | commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 3); |
| | | commonStackerCrane.SetValue(StackerCraneDBName.WriteConfirm, 1); |
| | | Thread.Sleep(1000); |
| | | if (ReadReceived(commonStackerCrane) == 1) |
| | | { |
| | | Clear(commonStackerCrane); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åAGVæ¯å¦å¨ç è¾¹ |
| | | /// </summary> |
| | | /// <param name="commonStackerCrane"></param> |
| | | /// <returns></returns> |
| | | public bool AGVToSandyEdgeRead(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | DeviceProDTO? devicePro = commonStackerCrane.DeviceProDTOs.Where(x => x.DeviceProParamType == "AreaRead" && x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AreaRead").OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | ConsoleHelper.WriteColorLine($"ãæªæ¾å°é
ç½®è°åº¦AGVåºååè®®ã", ConsoleColor.Magenta); |
| | | return false; |
| | | } |
| | | |
| | | string[] x = devicePro.DeviceProAddress.Split('.'); |
| | | |
| | | x[x.Length - 1] = (int.Parse(x[x.Length - 1]) + 1).ToString(); |
| | | |
| | | string DeviceProAddress = string.Join(".", x); |
| | | bool read = commonStackerCrane.Communicator.Read<bool>(DeviceProAddress); |
| | | |
| | | return read; |
| | | } |
| | | |
| | | public bool Clear(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | DeviceProDTO? devicePro = commonStackerCrane.DeviceProDTOs.Where(x => x.DeviceProParamType == "WriteConfirm" && x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "WriteConfirm").OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | ConsoleHelper.WriteColorLine($"ãæªæ¾å°é
ç½®è°åº¦AGVåºååè®®ã", ConsoleColor.Magenta); |
| | | return false; |
| | | } |
| | | commonStackerCrane.Communicator.Write(devicePro.DeviceProAddress,Convert.ToInt16(0)); |
| | | |
| | | for (int i = 0; i < 6; i++) |
| | | { |
| | | if (i == 5) |
| | | { |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | int read = commonStackerCrane.Communicator.Read<int>(devicePro.DeviceProAddress); |
| | | if (read == 0) |
| | | { |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | commonStackerCrane.Communicator.Write(devicePro.DeviceProAddress, Convert.ToInt16(0)); |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读åAGVæ¯å¦å¨å°è¾¹ |
| | | /// </summary> |
| | | /// <param name="commonStackerCrane"></param> |
| | | /// <returns></returns> |
| | | public bool AGVToEdgeBandingRead(CommonStackerCrane commonStackerCrane) |
| | | { |
| | | DeviceProDTO? devicePro = commonStackerCrane.DeviceProDTOs.Where(x => x.DeviceProParamType == "AreaRead" && x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AreaRead").OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | |
| | | if (devicePro == null) |
| | | { |
| | | ConsoleHelper.WriteColorLine($"ãæªæ¾å°é
ç½®è°åº¦AGVåºååè®®ã", ConsoleColor.Magenta); |
| | | return false; |
| | | } |
| | | return commonStackerCrane.Communicator.Read<bool>(devicePro.DeviceProAddress); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | ConsoleHelper.WriteColorLine($"ãæªæ¾å°é
ç½®è°åº¦AGVåºååè®®ã", ConsoleColor.Magenta); |
| | | return; |
| | | } |
| | | var writeBool = commonStackerCrane.Communicator.Read<bool>(devicePro.DeviceProAddress+0.1); |
| | | if (!writeBool) |
| | | |
| | | string[] x = devicePro.DeviceProAddress.Split('.'); |
| | | |
| | | x[x.Length - 1] = (int.Parse(x[x.Length - 1]) + 1).ToString(); |
| | | |
| | | string DeviceProAddress = string.Join(".", x); |
| | | commonStackerCrane.Communicator.Write(DeviceProAddress, true); |
| | | commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 4); |
| | | commonStackerCrane.SetValue(StackerCraneDBName.WriteConfirm, 1); |
| | | Thread.Sleep(1000); |
| | | if (ReadReceived(commonStackerCrane) == 1) |
| | | { |
| | | commonStackerCrane.Communicator.Write(devicePro.DeviceProAddress + 0.1, true); |
| | | Clear(commonStackerCrane); |
| | | } |
| | | } |
| | | /// <summary> |
| | |
| | | |
| | | stackerCraneTaskCommand.TaskNum = task.TaskNum; |
| | | stackerCraneTaskCommand.WorkType = 1; |
| | | stackerCraneTaskCommand.TaskType = 0; |
| | | stackerCraneTaskCommand.WriteConfirm = 1; |
| | | stackerCraneTaskCommand.StartAddress = Convert.ToInt16(SourceAddress.stationCode); |
| | | stackerCraneTaskCommand.EndAddress = Convert.ToInt16(TargetAddress.stationCode); |
| | | |