zhanghonglin
2025-07-11 de3731f81b826c0188cb3dfc2a3ff0661db9c3d9
ÏîÄ¿´úÂë/WCS/WCSServices/WIDESEAWCS_Tasks/³ÉÆ·²Ö/ConveyorLineJob_CPB.cs
@@ -72,16 +72,15 @@
                {
                    DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault();
                    if (deviceProRead != null && deviceProWrite!=null)
                    if (item.StationType==StationTypeEnum.StationType_InStartAndOutEnd.ObjToInt() && deviceProRead != null && deviceProWrite!=null)
                    {
                        R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
                        if (conveyorLineInfoRead.Command == 6 && conveyorLineInfoRead.TaskNo>0 && !string.IsNullOrEmpty(conveyorLineInfoRead.PalletCode))
                        if (conveyorLineInfoRead.Command == 5 && conveyorLineInfoRead.TaskNo>0 && !string.IsNullOrEmpty(conveyorLineInfoRead.PalletCode))
                        {
                            Dt_Task task = _taskRepository.QueryFirst(x =>x.TaskNum== conveyorLineInfoRead.TaskNo && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode==device.DeviceCode);
                            Dt_Task task = _taskRepository.QueryFirst(x =>x.TaskNum== conveyorLineInfoRead.TaskNo && x.NextAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode==device.DeviceCode);
                            if (task != null)
                            {
                                //分配巷道 å­˜å…¥æ‰˜ç›˜æ•°æ®
                                List<Dt_Router> routers = _routerService.QueryNextRoutes(item.StationCode, "SC01_CP", task.TaskType);
                                Dt_Router? router = routers.FirstOrDefault();
                                if (routers == null || routers.Count == 0 || router == null)
@@ -95,9 +94,10 @@
                                    continue;
                                }
                                
                                device.SetValue(W_ConveyorLineCPDB.TargetAddress, router.NextPosi, item.StationCode);
                                device.SetValue(W_ConveyorLineCPDB.TaskNo, task.TaskNum, item.StationCode);
                                device.SetValue(W_ConveyorLineCPDB.Command, 1, item.StationCode);
                                device.SetValue(W_ConveyorLineCPDB.W_TargetAddress, router.NextPosi, item.StationCode);
                                device.SetValue(W_ConveyorLineCPDB.W_TaskNo, task.TaskNum, item.StationCode);
                                device.SetValue(W_ConveyorLineCPDB.W_Command, 1, item.StationCode);
                                task.CurrentAddress = item.StationCode;
                                task.NextAddress=router.NextPosi;
                                task.PalletType = 1;
                                task.PalletCode = conveyorLineInfoRead.PalletCode;
@@ -115,6 +115,40 @@
                            }
                        }
                    }
                    else if (item.StationType == StationTypeEnum.StationType_InboundAndOutbound.ObjToInt() && deviceProRead != null)
                    {
                        R_ConveyorLineCPInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_ConveyorLineCPInfo>(deviceProRead.DeviceProAddress);
                        if (conveyorLineInfoRead.Command == 4 && conveyorLineInfoRead.TaskNo > 0)
                        {
                            Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.TaskNo && x.CurrentAddress == item.StationCode && _taskService.TaskInboundTypes.Contains(x.TaskType) && x.TaskState == TaskStatusEnum.Line_Execute.ObjToInt() && x.DeviceCode == device.DeviceCode);
                            if (task != null)
                            {
                                List<Dt_Router> routers = _routerRepository.QueryData(x => x.InOutType == task.TaskType && task.CurrentAddress == x.StartPosi);
                                Dt_Router? router = routers.FirstOrDefault();
                                if (routers == null || routers.Count == 0 || router == null)
                                {
                                    WriteError(item.StationName, $"未找到对应路由信息,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                    continue;
                                }
                                if (routers.Count > 1)
                                {
                                    WriteError(item.StationName, $"路由信息配置错误,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                    continue;
                                }
                                device.SetValue(W_ConveyorLineCPDB.W_Command, 2, item.StationCode);
                                task.NextAddress = router.NextPosi;
                                _taskService.UpdateTask(task, TaskStatusEnum.Line_Executing);
                                WriteError(item.StationName, $"任务号{conveyorLineInfoRead.TaskNo}下一步");
                                //string? locationCode = _taskService.RequestAssignLocation(task.TaskNum, "AGV_CP");
                                //if (string.IsNullOrEmpty(locationCode) && task.TaskType != TaskTypeEnum.EmptyProductBack.ObjToInt())
                                //{
                                //    WriteError(item.StationName, $"请求分配货位返回信息错误,设备编号:{item.StationCode},任务号:{task.TaskNum}");
                                //    continue;
                                //}
                            }
                        }
                    }
                    else
                    {
                        WriteError(item.StationName, $"未找到设备子编号{item.StationCode}的协议信息");