huanghongfeng
9 小时以前 6ba24a49c009cca01d9c02b9dae692a53b8be116
´úÂë¹ÜÀí/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/SpeStackerCraneJob/SpeStackerCraneJob.cs
@@ -12,6 +12,7 @@
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
@@ -56,9 +57,6 @@
            _agvStationService = agvStationService;
        }
        public string ziche001 = "RGV104";
        public string ziche002 = "RGV107";
        public Task Execute(IJobExecutionContext context)
        {
@@ -70,19 +68,17 @@
                    GetStackerObject getStackerObject = new GetStackerObject(speStackerCrane);
                    //读取设备完成信息
                    if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid!=0)
                    if (getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Completed && getStackerObject.CurrentRgvtaskid != 0)
                    {
                        _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid);
                        _taskService.UpdateTaskStatus(getStackerObject.CurrentRgvtaskid,2);
                    }
                    if (getStackerObject.RgvCraneAutoStatusValue == RgvCraneAutoStatus.Automatic &&
                        getStackerObject.StaclerkJobJobStatusValue == RgvJobCraneStatus.Ready && getStackerObject.RgvCraneWorkStatusValue == RGVStepprocess.NoAction)
                    {
                        //下发RGV任务之前,先读取一下安全门状态
                        //查找RGV进行下发任务
                        Dt_Task task = GetTask(speStackerCrane.DeviceCode);
@@ -97,6 +93,43 @@
                                _taskService.UpdateTaskStatusToNext(task);
                            }
                        }
                        else
                        {
                            int HCJGoodsplatform = 1170;    //定义的放货站台
                            //判断母车是否需要进行移动
                            AGVStation GdZiche = _agvStationService.Corridorequipment(speStackerCrane.DeviceCode);
                            if(GdZiche.Station_Area == 1)
                            {
                                switch (getStackerObject.RGVCurrentlocation)
                                {
                                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //在第一个母车上
                                        RGVMovetask(HCJGoodsplatform, GdZiche.ChildPosiDeviceCode);
                                        break;
                                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //在第二个母车上
                                        OutNMotherCar(GdZiche.MotherCarDeviceCode);
                                        break;
                                    case int HCJaddress when HCJaddress == GdZiche.HCJStorageaddress:        //在HCJ站台上
                                        OutHCJMotherCar(GdZiche);
                                        break;
                                    default: return null;
                                }
                            }
                            else
                            {
                                switch (getStackerObject.RGVCurrentlocation)
                                {
                                    case int Whcjaddress when Whcjaddress == GdZiche.MotherCarDeviceCode:    //在第一个母车上,需要判断外侧子车是否在HCJ上
                                        OutinnerSideNMotherCar(GdZiche);
                                        break;
                                    case int Waddress when Waddress == GdZiche.MotherCardeputy:              //在第二个母车上,需要判断子车与外侧母车是否在过道上
                                        OutNMotherCar(GdZiche.MotherCarDeviceCode);
                                        break;
                                    default: return null;
                                }
                            }
                        }
                    }
                }
@@ -110,293 +143,63 @@
            return Task.CompletedTask;
        }
        /// <summary>
        /// èŽ·å–ä»»åŠ¡ï¼ˆæš‚æ—¶æ–¹æ³•if判断)
        /// </summary>
        /// <param name="DeviceCode"></param>
        /// <param name="RGVCurrentlocation"></param>
        /// <returns></returns>
        private Dt_Task? GetTask(string DeviceCode)
        {
            Dt_Task task;
            task = _taskService.QueryStackerCraneTask(DeviceCode);
            if (task != null)
            Dt_Task task = _taskService.QueryStackerCraneTask(DeviceCode);
            if (task == null) return null;
            return task.TaskType switch
            {
                //判断入库任务
                if(task.TaskType== (int)TaskInboundTypeEnum.Inbound)
                {
                    if(task.TaskState== (int)TaskInStatusEnum.RGV_InNew)
                    {
                        return task;
                    }else if(task.TaskState== (int)TaskInStatusEnum.RGV_InPickupFinish) //取货完成后,进行放货的流程
                    {
                        //判断该HCJ是否可放货
                        bool Currebool = QueryCurrentAdder(task); //判断HCJ是否可以放货
                        if (Currebool)
                        {
                            return task;
                        }
                        else { return null; }
                    }else if (task.TaskState == (int)TaskInStatusEnum.RGV_InReleaseFinish) //放货完成后,进行子车取货流程
                    {
                        //默认子车在取货的地方
                        return task;
                    }
                    else if (task.TaskState == (int)TaskInStatusEnum.RGV_InZicheFinish) //子车取货完成后,进行放货流程
                    {
                        //获取需要放货的站台
                        AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));   //获取到过道站台放货信息
                        if (aGVStation.Station_Area == 1)   //表示在外测
                        {
                            bool muchebool=MotherCarMoves(task, aGVStation);
                            if (muchebool)
                            {
                                return task;
                            }else { return null; }
                        }
                        else if(aGVStation.Station_Area == 2)   //表示在内侧
                        {
                            bool muchebool = MotherCarMovesinside(task, aGVStation);
                            if (muchebool)
                            {
                                return task;
                            }
                            else { return null; }
                        }else if (aGVStation.Station_Area == 3)     //放在过道HCJ
                        {
                            bool muchebool = HCJMotherCarMovesinside(task, aGVStation);
                            if (muchebool)
                            {
                                return task;
                            }
                            else { return null; }
                        }
                    }else if (task.TaskState == (int)TaskInStatusEnum.RGV_InZicheReleaseFinish) //子车放货完成
                    {
                        AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));
                        if(aGVStation.Station_Area == 1)
                        {
                            return task;
                            /*RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(task, "1021");
                            bool sendFlag = SendCommand2(standardCommands, ziche001);
                            if (sendFlag)
                            {
                                //记录下发过母车移动任务
                                _taskService.UpdateTaskStatusToNext(task);
                            }*/
                        }
                        else if (aGVStation.Station_Area == 2)
                        {
                            RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(task, "1021");   //注意::::该子车需要待定去向
                            bool sendFlag = SendCommand2(standardCommands, ziche002);
                            if (sendFlag)
                            {
                                //记录下发过母车移动任务
                                _taskService.UpdateTaskStatusToNext(task);
                            }
                        }
                        //进行移动子车
                    }
                    else if(task.TaskState == (int)TaskInStatusEnum.RGV_InZichemoveFinish) //子车移动完成后,进行
                    {
                        //获取需要放货的站台
                        AGVStation aGVStation = _agvStationService.GetAllStationByDeviceCode(int.Parse(task.CurrentAddress));   //获取入库站台信息
                        if (aGVStation.Station_Area == 1)   //入库口区域的1表示写入固定的1号子车104
                        {
                            //判断子车在哪个位置
                            int zicheadder = GetZichelocation(task, ziche001);
                            if(zicheadder!= int.Parse(aGVStation.ZicheMotherinlaw))
                            {
                                return task;
                            }
                        }
                        else if(aGVStation.Station_Area == 2)      //入库口区域的1表示写入固定的1号子车107
                        {
                            int zicheadder = GetZichelocation(task, ziche002);
                            if (zicheadder != int.Parse(aGVStation.ZicheMotherinlaw))
                            {
                                return task;
                            }
                        }
                    }
                }
                else if(task.TaskType == (int)TaskOutboundTypeEnum.Outbound)
                {
                    if (task.TaskState == (int)TaskOutStatusEnum.OutNew)
                    {
                        return task;
                    }else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutMothercarFinish)
                    {
                        return task;
                    }
                    else if (task.TaskState == (int)TaskOutStatusEnum.RGV_OutZicheFinish)
                    {
                        return task;
                    }else if(task.TaskState == (int)TaskOutStatusEnum.RGV_OutZicheReleaseFinish)
                    {
                        return task;
                    }else if(task.TaskState == (int)TaskOutStatusEnum.RGV_OutPickupFinish && task.CurrentAddress != "")
                    {
                        return task;
                    }
                }
            }
            return null;
                (int)TaskInboundTypeEnum.Inbound => HandleInboundTask(task),
                (int)TaskOutboundTypeEnum.Outbound => HandleOutboundTask(task),
                _ => null
            };
        }
        //判断外侧母车位置
        private bool MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
        private Dt_Task? HandleInboundTask(Dt_Task task)
        {
            int mcadder = GetMothercarlocation(_Task, aGVStation.Motherinlaw);
            if(mcadder != 0)
            return task.TaskState switch
            {
                if (mcadder == int.Parse(_Task.CurrentAddress))       //判断子车要去的位置,母车是否在该位置
                {
                    return true;
                }
                else
                {
                    //下发母车移动出来接货任务
                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, _Task.CurrentAddress);
                    bool sendFlag = SendCommand2(standardCommands, aGVStation.ChildPosiDeviceCode);
                    if (sendFlag)
                    {
                        //记录下发过母车移动任务
                        _taskService.UpdateTaskStatusToNext(_Task);
                    }
                }
            }
            return false;
                (int)TaskInStatusEnum.RGV_InNew => task,
                (int)TaskInStatusEnum.RGV_InPickupFinish => HandlePickupFinish(task),
                (int)TaskInStatusEnum.RGV_InReleaseFinish => HandInneRouterSides(task),
                (int)TaskInStatusEnum.RGV_InZicheFinish => HandleZicheFinish(task),
                (int)TaskInStatusEnum.RGV_InZicheReleaseFinish => task,
                (int)TaskInStatusEnum.RGV_InZichemoveFinish => HandleZicheMoveFinish(task),
                _ => null
            };
        }
        //判断内侧母车位置
        private bool MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        private Dt_Task? HandleOutboundTask(Dt_Task task)
        {
            //获取外侧母车位置
            int mcadder = GetMothercarlocation(_Task, aGVStation.MotherCarDeviceCode);
            //获取内侧母车位置
            int ncadder = GetMothercarlocation(_Task, _Task.CurrentAddress);    //传入过道的地址
            if (mcadder != int.Parse(aGVStation.MotherCarDeviceCode) && ncadder == aGVStation.Station_code)       //判断外侧母车位置
            // å‡ºåº“任务的状态判断相对简单,可以直接返回
            int[] validStates =
            {
                return true;
            }
            else
            {
                if (mcadder == int.Parse(aGVStation.MotherCarDeviceCode))    //外侧母车需要移动
                {
                    //下发母车往里面走的任务
                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCarDeviceCode);    //堆垛机入库口
                (int)TaskOutStatusEnum.OutNew,
                (int)TaskOutStatusEnum.RGV_OutMothercarFinish,
                (int)TaskOutStatusEnum.RGV_OutZicheFinish,
                (int)TaskOutStatusEnum.RGV_OutZicheReleaseFinish,
                (int)TaskOutStatusEnum.RGV_OutPickupFinish
            };
                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //下发母车移动至入库站台位
                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
                    if (sendFlag)
                    {
                        //记录下发过母车移动任务
                        _taskService.UpdateTaskStatusToNext(_Task);
                    }
                }
                if (ncadder != aGVStation.Station_code)    //下发母车
                {
                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVStation.Station_code.ToString());
                    bool sendFlag = SendCommand2(standardCommands, aGVStation.ChildPosiDeviceCode);
                    if (sendFlag)
                    {
                        //记录下发过母车移动任务
                        _taskService.UpdateTaskStatusToNext(_Task);
                    }
                }
            }
            return false;
        }
        private bool HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)  //传进来的站台为HCJ
        {
            //获取外侧母车位置
            int mcadder = GetMothercarlocation(_Task, aGVStation.MotherCarDeviceCode);
            //获取内侧母车位置
            int ncadder = GetMothercarlocation(_Task, aGVStation.MotherCardeputy);
            if (mcadder != int.Parse(aGVStation.MotherCarDeviceCode) && ncadder != int.Parse(aGVStation.MotherCardeputy))       //判断外侧母车位置
            {
                return true;
            }
            else
            {
                if (mcadder == int.Parse(aGVStation.MotherCarDeviceCode))    //外侧母车需要移动
                {
                    //下发母车往里面走的任务
                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCarDeviceCode);    //堆垛机入库口
                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //下发母车移动至入库站台位
                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
                    if (sendFlag)
                    {
                        //记录下发过母车移动任务
                        _taskService.UpdateTaskStatusToNext(_Task);
                    }
                }
                if (ncadder == int.Parse(aGVStation.MotherCardeputy))    //下发母车
                {
                    //下发母车往里面走的任务
                    AGVStation aGVSta = _agvStationService.GetMothercarCode(aGVStation.MotherCardeputy);    //堆垛机入库口
                    RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(_Task, aGVSta.Station_code.ToString()); //下发母车移动至入库站台位
                    bool sendFlag = SendCommand2(standardCommands, aGVSta.ChildPosiDeviceCode);
                    if (sendFlag)
                    {
                        //记录下发过母车移动任务
                        _taskService.UpdateTaskStatusToNext(_Task);
                    }
                }
            }
            return false;
            return validStates.Contains(task.TaskState) ? task : null;
        }
        #region å…¥åº“方法
        public bool QueryCurrentAdder(Dt_Task task)
        #region å…¥åº“口取货完成后,进行放货(HCJ,异常出库口)
        private Dt_Task? HandlePickupFinish(Dt_Task task)
        {
            try
            {
                //获取需要区分是否去入库与去不合格载货台任务
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, task.CurrentAddress, "HCJ_GoodsStatus");
                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetDeviceProDTO(Commonstacker, task.NextAddress, "HCJ_GoodsStatus");
                int HCJGStatus = GetDeviceAddress.GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (HCJGStatus == 0)    //为无货
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                //记录异常情况
                _taskService.UpdateTaskExceptionMessage(task.TaskNum,$"判断HCJ站台是否有货信息出错,出错信息:{ex.Message}");
                throw;
            }
            return false;
        }
        //判断是否
        public bool GetMotherCarCurrentAdder(Dt_Task task)
        {
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "HCJ2000");
                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, task.CurrentAddress, "HCJ_GoodsStatus");
                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (HCJGStatus == 0)    //为无货
                {
                    return true;
                    return task;
                }
            }
            catch (Exception ex)
@@ -406,65 +209,322 @@
                throw;
            }
            return false;
            return null;
        }
        #endregion
        #region å…¥åº“口放货完成后,进行取货内容
        private Dt_Task? HandInneRouterSides(Dt_Task task)
        {
            // æ ¹æ®è®¾å¤‡åç§°ï¼ŒèŽ·å–åˆ°è®¾å¤‡ç›¸å…³æ•°æ®
            AGVStation currentStation = _agvStationService.Corridorequipment(task.Roadway);
            // èŽ·å–å­è½¦ä½ç½®
            int zicheAddress = GetDeviceAddress.GetEquipmentlocation(currentStation.ChildPosiDeviceCode);
            if (currentStation.Station_Area == 1)
            {
                // æ ¹æ®å­è½¦ä½ç½®å¤„理不同情况
                switch (zicheAddress)
                {
                    case int Whcjaddress when Whcjaddress == int.Parse(task.CurrentAddress):
                        return task;
                    case int Waddress when Waddress == currentStation.MotherCarDeviceCode:
                        return task;
                    case int Naddress when Naddress == currentStation.MotherCardeputy:
                        return HandleMedialCase(task, currentStation.MotherCarDeviceCode);
                    case int HCJaddress when HCJaddress == currentStation.HCJStorageaddress:
                        return HandleMedialCase2(task, currentStation);
                    default: return null;
                }
            }
            else
            {
                //取HCJ位的料判断
                switch (zicheAddress)
                {
                    case int Whcjaddress when Whcjaddress == int.Parse(task.CurrentAddress):
                        return task;
                    case int Waddress when Waddress == currentStation.MotherCarDeviceCode:
                        return task;
                    case int Naddress when Naddress == currentStation.MotherCardeputy:
                        return HandleMedialCase(task, currentStation.MotherCarDeviceCode);
                    default: return null;
                }
            }
        }
        /// <summary>
        /// åˆ¤æ–­å¤–侧母车是否在入口口
        /// </summary>
        /// <param name="task"></param>
        /// <param name="currentStation"></param>
        /// <returns></returns>
        private Dt_Task? HandleMedialCase(Dt_Task task, int currentStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation);
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            if (motherCarAddress == Muche.Motherinlaw) return task;
            RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            return null;
        }
        /// <summary>
        /// åˆ¤æ–­å†…外侧母车是否在入库口
        /// </summary>
        /// <param name="task"></param>
        /// <param name="currentStation"></param>
        /// <returns></returns>
        private Dt_Task? HandleMedialCase2(Dt_Task task, AGVStation currentStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(currentStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(currentStation.MotherCardeputy);    //内侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            if (motherCarAddress == 0 || motherCarAddress2 == 0) return null;
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
            }
            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw) return task;
            // æ¯è½¦å·²åœ¨æ­£ç¡®ä½ç½®
            return null;
        }
        #endregion
        #region å–货完成后,进行放货操作
        private Dt_Task? HandleZicheFinish(Dt_Task task)
        {
            // æ ¹æ®è®¾å¤‡åç§°ï¼ŒèŽ·å–åˆ°è®¾å¤‡ç›¸å…³æ•°æ®
            AGVStation GdaoRgvStation = _agvStationService.Corridorequipment(task.Roadway);
            int nexaddres = int.Parse(task.NextAddress);
            switch (nexaddres)
            {
                case int Whcjaddress when Whcjaddress == GdaoRgvStation.MotherCarDeviceCode:    //放货点在第一个过道点
                    return MotherCarMoves(task, GdaoRgvStation);
                case int Waddress when Waddress == GdaoRgvStation.MotherCardeputy:              //放货点在第二个过道点
                    return MotherCarMovesinside(task, GdaoRgvStation);
                case int HCJaddress when HCJaddress == GdaoRgvStation.HCJStorageaddress:        //放货点在HCJ上
                    return HCJMotherCarMovesinside(task, GdaoRgvStation);
                default: return null;
            }
        }
        //区域一判断母车是否到位,可立即放货
        private Dt_Task? MotherCarMoves(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.ZicheMotherinlaw);
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            if (motherCarAddress == Muche.ZicheMotherinlaw) return _Task;
            RGVMovetask(Muche.ZicheMotherinlaw, aGVStation.ChildPosiDeviceCode);
            return null;
        }
        /// <summary>
        /// åˆ¤æ–­æ”¾ç¬¬äºŒä¸ªæ¯è½¦ä½ç½®
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private Dt_Task? MotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.ZicheMotherinlaw)
            {
                RGVMovetask(Muche2.ZicheMotherinlaw, Muche2.ChildPosiDeviceCode);
            }
            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.ZicheMotherinlaw) return _Task;
            // æ¯è½¦å·²åœ¨æ­£ç¡®ä½ç½®
            return null;
        }
        private Dt_Task? HCJMotherCarMovesinside(Dt_Task _Task, AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //内侧子车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
            }
            if(ZiCarAddress3== Ziche3.HCJStorageaddress)
            {
                //判断目标站台是入库到几号堆垛机
                if (_Task.TargetAddress == "3")     //入库至3号堆垛机
                {
                    //判断外侧母车位置(2区域)
                    AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //外侧母车
                    int motNCarAddress = GetDeviceAddress.GetEquipmentlocation(MucheN.ChildPosiDeviceCode); //获取到母车当前位置
                    if(MucheN.ZicheMotherinlaw== motNCarAddress)
                    {
                        RGVMovetask(Ziche3.MotherCarDeviceCode, Ziche3.ChildPosiDeviceCode);
                    }
                    else
                    {
                        RGVMovetask(MucheN.ZicheMotherinlaw, MucheN.ChildPosiDeviceCode);
                    }
                }
                else if (_Task.TargetAddress == "4")    //入库至4号堆垛机
                {
                    //判断外侧母车位置(2区域)
                    AGVStation MucheN = _agvStationService.GetMothervehicle(Ziche3.MotherCarDeviceCode);  //外侧母车
                    int motNCarAddress = GetDeviceAddress.GetEquipmentlocation(MucheN.ChildPosiDeviceCode); //获取到母车当前位置
                    if (MucheN.Motherinlaw != motNCarAddress)
                    {
                        RGVMovetask(MucheN.Motherinlaw, MucheN.ChildPosiDeviceCode);
                    }
                    AGVStation MucheN2 = _agvStationService.GetMothervehicle(Ziche3.MotherCardeputy);  //外侧母车
                    int motNCarAddress2 = GetDeviceAddress.GetEquipmentlocation(MucheN2.ChildPosiDeviceCode); //获取到母车当前位置
                    if (MucheN2.ZicheMotherinlaw != motNCarAddress2)
                    {
                        RGVMovetask(MucheN2.ZicheMotherinlaw, MucheN2.ChildPosiDeviceCode);
                    }
                    if(MucheN.Motherinlaw == motNCarAddress && MucheN2.ZicheMotherinlaw == motNCarAddress2)
                    {
                        RGVMovetask(Ziche3.MotherCardeputy, Ziche3.ChildPosiDeviceCode);
                    }
                }
            }
            if (motherCarAddress == Muche.Motherinlaw && motherCarAddress2 == Muche2.Motherinlaw && ZiCarAddress3 != Ziche3.HCJStorageaddress) return _Task;
            // æ¯è½¦å·²åœ¨æ­£ç¡®ä½ç½®
            return null;
        }
        #endregion
        #region æ¯è½¦ç§»åŠ¨è‡³å…¥åº“å£
        private Dt_Task? HandleZicheMoveFinish(Dt_Task task)
        {
            int curradder = int.Parse(task.CurrentAddress);
            AGVStation GdZiche = _agvStationService.GetMotheaisle(curradder);
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(GdZiche.ChildPosiDeviceCode);
            if (motherCarAddress != curradder) return task;
            RGVMovetask(GdZiche.Motherinlaw, GdZiche.ChildPosiDeviceCode);
            return null;
        }
        #endregion
        #endregion
        #region å‡ºåº“方法
        #region å¤–侧小车回归到起始点位
        /// <summary>
        /// åˆ¤æ–­æ”¾ç¬¬äºŒä¸ªæ¯è½¦ä½ç½®
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private void OutNMotherCar(int MotherCarDeviceCode)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(MotherCarDeviceCode);  //外侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
        }
        private void OutHCJMotherCar(AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
            }
        }
        #endregion
        #region å¤–侧小车回归到起始点位
        /// <summary>
        /// åœ¨ç¬¬ä¸€ä¸ªä½ç½®ï¼Œåˆ™åˆ¤æ–­å¤–侧子车是否在HCJ站台下面
        /// </summary>
        /// <param name="_Task"></param>
        /// <param name="aGVStation"></param>
        /// <returns></returns>
        private void OutinnerSideNMotherCar(AGVStation aGVStation)
        {
            AGVStation Ziche3 = _agvStationService.GetZicheDeep(aGVStation.HCJStorageaddress);    //内侧子车
            int ZiCarAddress3 = GetDeviceAddress.GetEquipmentlocation(Ziche3.ChildPosiDeviceCode);
            if (ZiCarAddress3 == Ziche3.HCJStorageaddress)
            {
            }
            else
            {
                //RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
        }
        private void OutinnerSideMotherCar(AGVStation aGVStation)
        {
            AGVStation Muche = _agvStationService.GetMothervehicle(aGVStation.MotherCarDeviceCode);  //外侧母车
            AGVStation Muche2 = _agvStationService.GetMothervehicle(aGVStation.MotherCardeputy);    //内侧母车
            int motherCarAddress = GetDeviceAddress.GetEquipmentlocation(Muche.ChildPosiDeviceCode);
            int motherCarAddress2 = GetDeviceAddress.GetEquipmentlocation(Muche2.ChildPosiDeviceCode);
            // å¦‚果母车不在预期位置,下发移动任务
            if (motherCarAddress != Muche.Motherinlaw)
            {
                RGVMovetask(Muche.Motherinlaw, Muche.ChildPosiDeviceCode);
            }
            if (motherCarAddress2 != Muche2.Motherinlaw)
            {
                RGVMovetask(Muche2.Motherinlaw, Muche2.ChildPosiDeviceCode);
            }
        }
        #endregion
        #endregion
        /// <summary>
        /// ä¼ å…¥è¿‡é“地址,获取母车位置
        /// å­æ¯è½¦ç§»åŠ¨ä»»åŠ¡
        /// </summary>
        /// <param name="task"></param>
        /// <param name="MotherCarDeviceCode">过道地址</param>
        /// <param name="RGVAdders">目标地址</param>
        /// <param name="ChildPosiDeviceCode">设备编号</param>
        /// <returns></returns>
        public int GetMothercarlocation(Dt_Task task,string MotherCarDeviceCode)
        private bool RGVMovetask(int RGVAdders, string ChildPosiDeviceCode)
        {
            try
            {
                //利用入库站台地址获取母车plc
                AGVStation aGVStation =_agvStationService.GetMothercarCode(MotherCarDeviceCode);
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == aGVStation.ChildPosiDeviceCode);
                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, aGVStation.ChildPosiDeviceCode, "RGVCurrentlocation");
                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                return HCJGStatus;
            }
            catch (Exception ex)
            {
                //记录异常情况
                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"判断母车位置信息出错,出错信息:{ex.Message}");
                throw;
            }
            RgvCraneTaskCommand standardCommands = ConvertMotherCarTaskCommand(RGVAdders);
            bool sendFlag = SendCommand2(standardCommands, ChildPosiDeviceCode);
            return sendFlag;
        }
        /// <summary>
        /// ä¼ å…¥è¿‡é“地址,获取子车车位置
        /// </summary>
        /// <param name="task"></param>
        /// <param name="MotherCarDeviceCode">入库站台地址</param>
        /// <returns></returns>
        public int GetZichelocation(Dt_Task task, string ChildPosiDeviceCode)
        {
            try
            {
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == ChildPosiDeviceCode);
                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
                DeviceProDTO? deviceProDTO = GetDeviceProDTO(Commonstacker, ChildPosiDeviceCode, "RGVCurrentlocation");
                int HCJGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                return HCJGStatus;
            }
            catch (Exception ex)
            {
                //记录异常情况
                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"判断子车位置信息出错,出错信息:{ex.Message}");
                throw;
            }
        }
        /// <summary>
        /// ä»»åŠ¡å®žä½“è½¬æ¢æˆå‘½ä»¤Model
        /// </summary>
@@ -474,10 +534,19 @@
        public RgvCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
        {
            RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(task.CurrentAddress);
            stackerCraneTaskCommand.RGV_RGVtasktype = 2;
            stackerCraneTaskCommand.RGV_Rgvtaskid = 1;          //rgv任务号
            stackerCraneTaskCommand.RGV_Lanjiantaskid = 0;      //兰剑任务id
            short locaticurr = task.RGVTaskType switch
            {
                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.PickingUp ||
                       (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType != (int)TaskInStatusEnum.RGV_InZichemoveFinish)
                    => short.Parse(task.CurrentAddress),
                _ when task.RGVTaskType == (short)RGVTaskTypeEnum.Placing || (task.RGVTaskType == (short)RGVTaskTypeEnum.TravelingOnly && task.TaskType== (int)TaskInStatusEnum.RGV_InZichemoveFinish)
                    => short.Parse(task.NextAddress),
                _ => (short)0
            };
            stackerCraneTaskCommand.RGV_RGVTasklocation = locaticurr;
            stackerCraneTaskCommand.RGV_RGVtasktype = (short)task.RGVTaskType;
            stackerCraneTaskCommand.RGV_Rgvtaskid = (short)task.TaskNum;
            stackerCraneTaskCommand.RGV_Lanjiantaskid = (short)task.TaskNum;
            return stackerCraneTaskCommand;
        }
@@ -488,49 +557,15 @@
        /// <param name="task">任务实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand([NotNull] Dt_Task task,string CurrentAddress)
        public RgvCraneTaskCommand? ConvertMotherCarTaskCommand(int RGVAddress)
        {
            RgvCraneTaskCommand stackerCraneTaskCommand = new RgvCraneTaskCommand();
            stackerCraneTaskCommand.RGV_RGVTasklocation = short.Parse(CurrentAddress);
            stackerCraneTaskCommand.RGV_RGVTasklocation = (short)RGVAddress;
            stackerCraneTaskCommand.RGV_RGVtasktype = 3;
            stackerCraneTaskCommand.RGV_Rgvtaskid = 999;          //rgv任务号
            stackerCraneTaskCommand.RGV_Lanjiantaskid = 999;      //兰剑任务id
            return stackerCraneTaskCommand;
        }
        public void wcsWriteLog(string SCLLinStack, string Logtype, string Magessadd)
        {
            WriteLog.Write_Log("RGV", SCLLinStack + "号RGV", Logtype, new { ä¿¡æ¯ = Magessadd });
        }
        //===========================================================HCJ协议读写查=============================================================================
        /// <summary>
        /// æŸ¥è¯¢å…·ä½“地址
        /// </summary>
        /// <param name="Commonstacker"></param>
        /// <param name="SCAddress"></param>
        /// <param name="Interactivet"></param>
        /// <returns></returns>
        public DeviceProDTO? GetDeviceProDTO(CommonStackerCrane Commonstacker, string SCAddress, string Interactivet)
        {
            return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == Interactivet && x.DeviceProParamType== "ReadDeviceCommand");
        }
        /// <summary>
        /// æ ¹åœ°å€è¯»å–输送线信息
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="DeviceProDataBlock"></param>
        /// <returns></returns>
        public int GetLine(CommonStackerCrane Commonstacker, string DeviceProDataBlock)
        {
            return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
        }
        //===========================================================HCJ协议读写查===============================================================================
        public bool SendCommand2(RgvCraneTaskCommand command, string DeviceCode)
        {
            try
@@ -538,8 +573,8 @@
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode);
                CommonStackerCrane Commonstacker = (CommonStackerCrane)device;
                DeviceProDTO? deviceProDTO =  GetDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
                int MCGStatus = GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                DeviceProDTO? deviceProDTO = GetDeviceAddress.GetDeviceProDTO(Commonstacker, DeviceCode, "RGV_Rgvtaskstutas");
                int MCGStatus = GetDeviceAddress.GetLine(Commonstacker, deviceProDTO.DeviceProAddress);
                if (Commonstacker.IsConnected)
                {
                    if (MCGStatus == (int)RgvJobCraneStatus.Ready)