huangxiaoqiang
5 天以前 0e674f770d785bfd24b5034456c2502dcc6671d2
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -10,6 +10,7 @@
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;
@@ -24,6 +25,7 @@
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
@@ -53,7 +55,6 @@
            try
            {
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
                    if (!commonStackerCrane.IsEventSubscribed)
@@ -67,7 +68,10 @@
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Idle)
                        {
                            GetTask(commonStackerCrane);
                            if (commonStackerCrane.GetValue<StackerCraneDBName, float>(StackerCraneDBName.Electricity) > 20)
                            {
                                GetTask(commonStackerCrane);
                            }
                        }
                    }
@@ -87,8 +91,8 @@
                            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),
                        };
@@ -116,8 +120,6 @@
           CommonStackerCrane? commonStackerCrane = sender as CommonStackerCrane;
            if (commonStackerCrane != null)
            {
                Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                _taskService.StackCraneTaskCompleted(e.TaskNum);
                commonStackerCrane.SetValue(StackerCraneDBName.TaskCompleted, 1);
@@ -135,39 +137,53 @@
            task = _taskService.QueryStackerCraneTask(commonStackerCrane.DeviceCode);
            if (task != null)
            {
                StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
                if (stackerCraneTaskCommand != null)
                if (task.Roadway == "3")
                {
                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                    Thread.Sleep(1000);
                    if (ReadReceived(commonStackerCrane) == 1)
                    if (AGVToSandyEdgeRead(commonStackerCrane))
                    {
                        WriteConfirm(commonStackerCrane);
                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                        WriteAGVTask(task, commonStackerCrane);
                    }
                    else
                    {
                        AGVToSandyEdge(commonStackerCrane);
                    }
                }
                else if (task.Roadway == "2")
                {
                    if (AGVToEdgeBandingRead(commonStackerCrane))
                    {
                        WriteAGVTask(task, commonStackerCrane);
                    }
                    else
                    {
                        AGVToEdgeBanding(commonStackerCrane);
                    }
                }
                else
                {
                    WriteAGVTask(task, commonStackerCrane);
                }
            }
        }
        //读取AGV状态
        public int ReadAGVstatus(CommonStackerCrane commonStackerCrane)
        public void WriteAGVTask(Dt_Task task, 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;
            StackerCraneTaskCommand? stackerCraneTaskCommand = ConvertToStackerCraneTaskCommand(task);
            if (stackerCraneTaskCommand != null)
            {
                bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                Thread.Sleep(2000);
                if (ReadReceived(commonStackerCrane) == 1)
                {
                    if (Clear(commonStackerCrane))
                    {
                        _taskService.UpdateTaskStatusToNext(task.TaskNum);
                    }
                }
            }
        }
        /// <summary>
@@ -179,10 +195,6 @@
        {
            return commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.Received);
        }
        public void WriteConfirm(CommonStackerCrane commonStackerCrane)
        {
            commonStackerCrane.SetValue(StackerCraneDBName.WriteConfirm, 1);
        }
        /// <summary>
        /// è°ƒåº¦AGV去封边区域
@@ -191,7 +203,90 @@
        /// <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>
@@ -203,15 +298,24 @@
        {
            DeviceProDTO? devicePro = commonStackerCrane.DeviceProDTOs.Where(x => x.DeviceProParamType == "AreaWrite" && x.DeviceChildCode == commonStackerCrane.DeviceCode && x.DeviceProParamName == "AreaWrite").OrderBy(x => x.DeviceProOffset).FirstOrDefault();
            if(devicePro == null)
            if (devicePro == null)
            {
                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>
@@ -234,7 +338,7 @@
            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);