Admin
2026-03-26 dea22f4759b5c8a4f79a3e93e5af1741f5e00ae4
ÏîÄ¿´úÂë/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -57,15 +57,8 @@
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
                    //if (!commonStackerCrane.IsEventSubscribed)
                    //{
                    //    commonStackerCrane.StackerCraneTaskCompletedEventHandler += CommonStackerCrane_StackerCraneTaskCompletedEventHandler;//订阅任务完成事件
                    //}
                    if ((int)commonStackerCrane.StackerCraneWorkStatusValue == 6)
                    //任务完成StackerCraneWorkStatus
                    if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted)
                    {
                        //判断当前任务是否是盘点
                        Dt_Task? currtask = _taskService.CurrtaskInfo(commonStackerCrane.CurrentTaskNum);
@@ -108,6 +101,8 @@
                                    bool sendFlag = commonStackerCrane.SendCommand(stackerCraneTaskCommand);
                                    if (sendFlag)
                                    {
                                        commonStackerCrane.Communicator.Write("DB105.52", 1);
                                        WebResponseContent webResponseContent=_taskService.UpdateTaskStatusToNext(task.TaskNum);
                                    }
                                }
@@ -162,7 +157,7 @@
                    {
                        if (taskItem.TaskType == (int)TaskTypeEnum.Outbound)
                        {
                            if (OutTaskStationIsOccupied(taskItem.NextAddress))
                            if (OutTaskStationIsOccupied(taskItem.NextAddress,taskItem.Roadway))
                            {
                                return taskItem;
                            }
@@ -188,14 +183,49 @@
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns>如果未被占用,返回传入的任务信息,否则,返回null</returns>
        private bool OutTaskStationIsOccupied(string NextAddress)
        private bool OutTaskStationIsOccupied(string NextAddress,string Roadway)
        {
            IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
            if (device == null) return false;
            CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
            DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationFree");
            if (deviceProDTO == null) return false;
            return conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
            try
            {
                if (Roadway == "C")
                {
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1004");
                    if (device == null) return false;
                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationNum");
                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "HandShake");
                    if (deviceProDTO == null || HandShakeprodto == null) return false;
                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                    if (StationNum == 0 && HandShake == 0 && Roadway == "C")
                    {
                        return true;
                    }
                }
                else
                {
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1003");
                    if (device == null) return false;
                    CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                    DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "StationNum");
                    DeviceProDTO? HandShakeprodto = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == NextAddress && x.DeviceProParamName == "HandShake");
                    if (deviceProDTO == null || HandShakeprodto == null) return false;
                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                    if ((StationNum == 1 && HandShake == 0 && Roadway == "B") || (StationNum == 0 && HandShake == 0 && Roadway != "B"))
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("读取站台信息错误:"+ex.Message);
            }
            return false;
        }
@@ -208,6 +238,7 @@
        public StackerCraneTaskCommand? ConvertToStackerCraneTaskCommand([NotNull] Dt_Task task)
        {
            StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
            stackerCraneTaskCommand.Barcode = task.PalletCode;
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
@@ -236,7 +267,9 @@
                if (EndCodest.Length == 3)
                {
                    string EndRow = EndCodest[0].Substring(1);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
                    string SCEndRow = LaneModification(task.Roadway, int.Parse(EndRow));
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow );
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
@@ -253,7 +286,8 @@
                if (sourceCodes.Length == 3)
                {
                    string StartRow = sourceCodes[0].Substring(1);
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(StartRow);
                    string SCStartRow = LaneModification(task.Roadway, int.Parse(StartRow));
                    stackerCraneTaskCommand.StartRow = Convert.ToInt16(SCStartRow);
                    stackerCraneTaskCommand.StartColumn = Convert.ToInt16(sourceCodes[1]);
                    stackerCraneTaskCommand.StartLayer = Convert.ToInt16(sourceCodes[2]);
                }
@@ -265,7 +299,7 @@
                }
                //获取站台编号
                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.NextAddress);
                string[] EndCodest = dt_Platform.Station_storey.Split("-");
                if (EndCodest.Length == 3)
                {
@@ -293,12 +327,15 @@
                if (EndCodest.Length == 3)
                {
                    string EndRow = EndCodest[0].Substring(1);
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(EndRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                   string SCEnRow=LaneModification(task.Roadway,int.Parse(EndRow));
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEnRow);
                    stackerCraneTaskCommand.EndColumn = (short)(Convert.ToInt16(EndCodest[1]) + 1);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
@@ -308,5 +345,20 @@
            }
            return stackerCraneTaskCommand;
        }
        public string LaneModification(string Roadway,int SCRow)
        {
            if (Roadway == "F")
            {
                return SCRow == 1 ? "3" : "4";
            }else if(Roadway == "C")
            {
                return SCRow == 1 ? "5" : "6";
            }
            else
            {
                return SCRow.ToString();
            }
        }
    }
}