huangxiaoqiang
5 天以前 0e674f770d785bfd24b5034456c2502dcc6671d2
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs
@@ -15,9 +15,12 @@
 *----------------------------------------------------------------*/
#endregion << ç‰ˆ æœ¬ æ³¨ é‡Š >>
using AngleSharp.Dom;
using Autofac.Core;
using AutoMapper;
using HslCommunication;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using System.Reflection;
@@ -113,8 +116,7 @@
                    #endregion è°ƒç”¨äº‹ä»¶æ€»çº¿é€šçŸ¥å‰ç«¯
                    // å°†äº¤äº’信号转换为布尔数组
                    var writeInteractiveSignal = command.InteractiveSignal;
                    var structs = BitConverter.GetBytes(writeInteractiveSignal).Reverse().ToArray().ToBoolArray();
                    var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                    // èŽ·å–è®¾å¤‡åè®®è¯¦æƒ…
                    List<DeviceProtocolDetailDTO>? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.Where(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)).ToList();
@@ -130,7 +132,7 @@
                                MethodInfo? method = GetType().GetMethod(item.ProtocolDetailType);
                                if (method != null)
                                {
                                    method.Invoke(this, new object[] { conveyorLine, station.stationName });
                                    method.Invoke(this, new object[] { conveyorLine, station });
                                }
                            }
                        }
@@ -149,107 +151,81 @@
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>Request outbound
        /// <param name="childDeviceCode">子设备编号</param>
        public async Task RequestInbound(CommonConveyorLine conveyorLine, string childDeviceCode)
        public async Task RequestInbound(CommonConveyorLine conveyorLine, Dt_StationManager station)
        {
            try
            {
                // è¾“出信息,表示站台请求取货
                var log = $"【{conveyorLine._deviceName}】站台【{childDeviceCode}】请求取货";
                ConsoleHelper.WriteWarningLine(log);
                // æŽ¨é€é€šçŸ¥åˆ°å‰ç«¯SignIR
                await _noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "Red" });
                WriteInfo(conveyorLine.DeviceName, log);
                var log = $"【{conveyorLine._deviceName}】站台【{station.stationName}】请求取货";
                await LogAndWarn(conveyorLine.DeviceName, log);
                // èŽ·å–æ‰€æœ‰ä»»åŠ¡æºåœ°å€
                List<string> task = _taskService.QueryConveyorLineTaskSourceAddress();
                List<string> taskSourceAddress = _taskService.QueryConveyorLineTask();
                if (_taskService.QueryConveyorLineTask(station.stationName) != null)
                {
                    ConveyorLineSendFinish(conveyorLine, station.stationName);
                    await LogAndWarn(conveyorLine.DeviceName, $"【{conveyorLine._deviceName}】站台【{station.stationName}】存在任务");
                    return;
                }
                // æ ¹æ®è®¾å¤‡ç¼–号和任务源地址查询所有未执行的任务
                List<Dt_StationManager> childDeviceCodes = _stationManagerService.QuerypLatform(conveyorLine.DeviceCode, task);  //对应每个ip找全部的下料站点与垫板回收点站台点
                List<Dt_StationManager> childDeviceCodes = _stationManagerService.QueryPlatform(station, taskSourceAddress);  //对应每个ip找全部的下料站点与垫板回收点站台点
                if(childDeviceCodes.Count()==0|| childDeviceCodes == null)
                {
                    ConveyorLineSendFinish(conveyorLine, station.stationName);
                    await LogAndWarn(conveyorLine.DeviceName, $"【{conveyorLine._deviceName}】站台【{station.stationName}】未找到可前往站台");
                    return;
                }
                foreach (var item in childDeviceCodes)
                {
                    ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
                    if (command != null)
                    IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == item.DeviceCode);
                    if (device != null)
                    {
                        var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                        if (structs[1])
                        CommonConveyorLine commonConveyorLine = (CommonConveyorLine)device;
                        ConveyorLineTaskCommand command = commonConveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
                        if (command != null)
                        {
                            if (item.stationMaterial == (int)AgvStationEnum.PadRecycle)
                            {
                                RequestHcdbst(conveyorLine, item.stationArea, item.stationName, item.stationRemark);
                                return;
                            }
                            else
                            var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                            if (structs[2])
                            {
                                Dt_Task taskDTO = new Dt_Task()
                                {
                                    TaskNum = _taskRepository.GetTaskNo().Result,
                                    Grade = 1,
                                    Roadway = item.stationArea.ToString(),
                                    SourceAddress = childDeviceCode,
                                    SourceAddress = station.stationName,
                                    CurrentAddress= station.stationName,
                                    TargetAddress = item.stationName,
                                    NextAddress = item.stationName,
                                    TaskState = (int)AGVTaskStatusEnum.AGVNew,
                                    TaskType = item.stationMaterial,
                                    TaskType = (int)AGVTaskTypeEnum.AGVCarry,
                                    AGVName = item.stationArea switch
                                    {
                                        1 => "AGV01",
                                        4 => "AGV03",
                                        _ => "AGV02",
                                    }
                                };
                                _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO });
                                ConveyorLineSendFinish(conveyorLine,station.stationName);
                                return;
                            }
                        }
                        else
                        {
                            WriteInfo(conveyorLine.DeviceName, $"站台{item.stationName}状态不可用{structs[2]}");
                        }
                    }
                    else
                    {
                        WriteInfo(conveyorLine.DeviceName, $"通讯连接错误,{item.stationName}未找到读取模块地址");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteInfo(conveyorLine.DeviceName, ex.Message);
            }
        }
        /// <summary>
        /// æ ¹æ®agv下料任务,把料放至上料口或缓存位
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestOutbound(CommonConveyorLine conveyorLine, string childDeviceCode)
        {
            try
            {
                List<Dt_StationManager> station = _stationManagerService.QuerypLatformarer(conveyorLine.DeviceCode);
                foreach (var item in station)
                {
                    ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
                    if (command != null)
                    {
                        var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                        if (structs[2])
                        {
                            if (item.stationMaterial == (int)AgvStationEnum.BoardLoad)
                            else
                            {
                                //Dt_Task agvstack= _taskService.QueryConveyorLineTaskRoadway(AGVStationitem.stationArea);
                                //if(agvstack != null)
                                //{
                                //    _taskService.UpdateTargetAddress(agvstack.TaskId, AGVStationitem.stationName);
                                //}
                                //else
                                //{
                                //    //去找缓存区库存
                                //    RequestHcst(conveyorLine, AGVStationitem.stationArea, AGVStationitem.stationName, AGVStationitem.stationRemark);
                                //}
                                await LogAndWarn(conveyorLine.DeviceName, $"站台{item.stationName}状态不可用{structs[2]}");
                            }
                        }
                        else
                        {
                            WriteInfo(conveyorLine.DeviceName, $"站台{item.stationName}状态不可用{structs[2]}");
                            WriteInfo(conveyorLine.DeviceName, $"通讯连接错误,{item.stationName}未找到读取模块地址");
                        }
                    }
                    else
                    {
                        var logerror = $"【{conveyorLine.DeviceName}】站台:【{item.stationName}】未配置设备表头";
                        await LogAndWarn(conveyorLine.DeviceName, logerror);
                    }
                }
            }
@@ -258,88 +234,6 @@
                WriteInfo(conveyorLine.DeviceName, ex.Message);
            }
        }
        public void RequestHcst(CommonConveyorLine conveyorLine,int Station_Area,string Station_names,string Station_remark)
        {
            List<Dt_StationManager> AGVStationListdata = _stationManagerService.QuerypLatformmaterial(Station_Area);   //查出缓存位
            if (Station_remark != null)   //找寻对应的放货站台
            {
                AGVStationListdata = _stationManagerService.QuerypStation_Area2(Station_remark);
            }
            foreach (var item in AGVStationListdata)
            {
                ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
                if (command != null)
                {
                    var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                    if (structs[1])
                    {
                        if (_taskService.QueryConveyorLinetaeersuadd(item.stationName))
                        {
                            Dt_Task taskDTO = new Dt_Task()
                            {
                                TaskNum = _taskRepository.GetTaskNo().Result,
                                Grade = 1,
                                Roadway = item.stationArea.ToString(),
                                SourceAddress = item.stationName,
                                CurrentAddress = item.stationName,
                                TaskState = (int)TaskInStatusEnum.InNew,
                                TaskType = (int)item.stationMaterial,
                                TargetAddress = Station_names,
                                NextAddress = Station_names,
                            };
                            _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO });
                        }
                    }
                    else
                    {
                        WriteInfo(conveyorLine.DeviceName,  $"通讯连接错误,{item.stationName}未找到读取模块地址");
                    }
                }
            }
        }
        public void RequestHcdbst(CommonConveyorLine conveyorLine, int Station_Area, string Station_names,string Station_remark)
        {
            List<Dt_StationManager> AGVStationListdata = _stationManagerService.QuerypStation_Area(Station_Area);   //查出缓存位
            if(Station_remark !=null)   //找寻对应的放货站台
            {
                AGVStationListdata= _stationManagerService.QuerypStation_Area2(Station_remark);
            }
            foreach (var item in AGVStationListdata)
            {
                ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(item.stationName);
                if (command != null)
                {
                    var structs = BitConverter.GetBytes(command.InteractiveSignal).Reverse().ToArray().ToBoolArray();
                    if (structs[1])
                    {
                        if (_taskService.QueryConveyorLinetaeersuadd(item.stationName))
                        {
                            Dt_Task taskDTO = new Dt_Task()
                            {
                                TaskNum = _taskRepository.GetTaskNo().Result,
                                Grade = 1,
                                Roadway = item.stationArea.ToString(),
                                SourceAddress = Station_names,
                                CurrentAddress = Station_names,
                                TaskState = (int)TaskInStatusEnum.InNew,
                                TaskType = (int)item.stationMaterial,
                                TargetAddress = item.stationName,
                                NextAddress = item.stationName,
                            };
                            _taskService.ReceiveWMSTask(new List<Dt_Task> { taskDTO });
                        }
                    }
                    else
                    {
                        WriteInfo(conveyorLine.DeviceName, $"读取放货信号为:{structs[2]}");
                    }
                }
            }
        }
        /// <summary>
        /// è¾“送线交互完成
        /// </summary>
@@ -353,5 +247,12 @@
            conveyorLine.Communicator.Write(devicePro.DeviceProAddress, true);
        }
        public async Task LogAndWarn(string deviceName, string log, string color = "red")
        {
            ConsoleHelper.WriteWarningLine(log);
            await _noticeService.Logs(userTokenIds, new { deviceName, log = log, time = DateTime.Now.ToString("G"), color = color });
            WriteInfo(deviceName, log);
        }
    }
}