zhangchengsong
3 天以前 0e450768c357b45701a2e5ed162f4e93b3dd617c
ÏîÄ¿´úÂë/WIDESEAWCS_Server/WIDESEAWCS_Tasks/StackerCraneJob/CommonStackerCraneJob.cs
@@ -1,4 +1,5 @@
using Autofac.Core;
using HslCommunication;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Hosting;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
@@ -7,9 +8,12 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Eventing.Reader;
using System.DirectoryServices.Protocols;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Reflection.Metadata;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
@@ -17,6 +21,7 @@
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -28,6 +33,7 @@
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Tasks
@@ -50,13 +56,16 @@
            _DtPlatformStationService= dt_PlatformStationService;
        }
        public Task Execute(IJobExecutionContext context)
        public  Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonStackerCrane commonStackerCrane = (CommonStackerCrane)context.JobDetail.JobDataMap.Get("JobParams");
                if (commonStackerCrane != null)
                {
                    UpdateHandShake(commonStackerCrane.CurrentTaskNum, commonStackerCrane.StackerCraneWorkStatusDes);
                    //任务完成StackerCraneWorkStatus
                    if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.WorkCompleted)
                    {
@@ -64,23 +73,22 @@
                        Dt_Task? currtask = _taskService.CurrtaskInfo(commonStackerCrane.CurrentTaskNum);
                        if(currtask != null)
                        {
                            string PalletCode = "";
                            //判断任务类型
                            if(currtask.TaskType==  (int)TaskTypeEnum.Inventorybound)
                            if (currtask.TaskType==  (int)TaskTypeEnum.Inventorybound)
                            {
                                //读取条码,进行配对
                                DeviceProDTO? deviceProDTO = commonStackerCrane.DeviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == "SCBarcode");
                                byte[] bytes = commonStackerCrane.Communicator.Read(deviceProDTO.DeviceProAddress, 64);
                                string result = Encoding.ASCII.GetString(bytes).Replace(" ", "");
                                bool pandianBort = false;
                                if(currtask.PalletCode== result) pandianBort= true;
                                //读取的托盘条码
                                PalletCode = Encoding.ASCII.GetString(bytes).Replace(" ", "");
                            }
                            WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum);
                            WebResponseContent webResponse = _taskService.StackCraneTaskCompleted(commonStackerCrane.CurrentTaskNum, PalletCode);
                            if (webResponse.Status)
                            {
                                WriteLog.Write_Log("堆垛机任务上报完成信息", "堆垛机任务上报完成信息", $"【{commonStackerCrane.DeviceCode}】库堆垛机上报任务号:【{commonStackerCrane.CurrentTaskNum}】完成信号!");
                                bool ddjfk = commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                            }
@@ -90,9 +98,11 @@
                    if (commonStackerCrane.StackerCraneAutoStatusValue == StackerCraneAutoStatus.Automatic && commonStackerCrane.StackerCraneStatusValue == StackerCraneStatus.Normal)
                    {
                        if (commonStackerCrane.StackerCraneWorkStatusValue == StackerCraneWorkStatus.Standby)
                        {
                            Console.WriteLine("进行获取任务");
                            Dt_Task? task = GetTask(commonStackerCrane);
                            if (task != null)
                            {
@@ -115,6 +125,8 @@
            catch (Exception ex)
            {
                Console.WriteLine(nameof(CommonStackerCraneJob) + ":" + ex.ToString());
                WriteLog.Write_Log("堆垛机报错信息", "堆垛机报错信息", $"堆垛机报错信息:【{ex.ToString()}】");
            }
            return Task.CompletedTask;
        }
@@ -132,7 +144,7 @@
                if (commonStackerCrane.GetValue<StackerCraneDBName, short>(StackerCraneDBName.WorkType) != 5 && e.TaskNum !=0)
                {
                    //Console.Out.WriteLine("TaskCompleted" + e.TaskNum);
                    _taskService.StackCraneTaskCompleted(e.TaskNum);
                    //_taskService.StackCraneTaskCompleted(e.TaskNum,);
                    commonStackerCrane.SetValue(StackerCraneDBName.WorkType, 5);
                }
            }
@@ -199,6 +211,9 @@
                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                    WriteLog.Write_Log("出库库口状态信息", "出库库口状态信息", $"库口是【{NextAddress}】,申请状态地址:【{HandShakeprodto.DeviceProAddress}】,读取的数据:【{HandShake}】\n" +
                         $"库口是否有货状态地址:【{deviceProDTO.DeviceProAddress}】,读取的数据【{StationNum}】");
                    if (StationNum == 0 && HandShake == 0 && Roadway == "C")
                    {
                        return true;
@@ -215,6 +230,9 @@
                    int StationNum = conveyorLine.Communicator.Read<ushort>(deviceProDTO.DeviceProAddress);
                    int HandShake = conveyorLine.Communicator.Read<ushort>(HandShakeprodto.DeviceProAddress);
                    WriteLog.Write_Log("出库库口状态信息", "出库库口状态信息", $"库口是【{NextAddress}】,申请状态地址:【{HandShakeprodto.DeviceProAddress}】,读取的数据:【{HandShake}】\n" +
                        $"库口是否有货状态地址:【{deviceProDTO.DeviceProAddress}】,读取的数据【{StationNum}】");
                    if ((StationNum == 1 && HandShake == 0 && Roadway == "B") || (StationNum == 0 && HandShake == 0 && Roadway != "B"))
                    {
                        return true;
@@ -240,16 +258,34 @@
        {
            StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand();
            stackerCraneTaskCommand.Barcode = task.PalletCode;
            stackerCraneTaskCommand.TaskNum = task.TaskNum;
            stackerCraneTaskCommand.WorkType = 1;
            stackerCraneTaskCommand.TrayType = 0;
            if (task.Roadway == "B" || task.Roadway == "C")
            {
                //判断 task.PalletCode æ˜¯ä¸æ˜¯ä¸€ä¸ªæœ‰æ•ˆçš„ GUID
                stackerCraneTaskCommand.Barcode = stackerCraneTaskCommand.Barcode = Guid.TryParse(task.PalletCode, out var guid) ? guid.ToString("N")[0..6] : task.PalletCode;
            }
            else if (task.Roadway == "G" )
            {
                if (Guid.TryParse(task.PalletCode, out var palletGuid))
                {
                    stackerCraneTaskCommand.Barcode = palletGuid.ToString("N")[0..6];
                    // æ ‡å‡†GUID就是36位,所以直接判断长度即可
                    stackerCraneTaskCommand.TrayType = (short)(task.PalletCode.Length == 36 ? 1 : 2);
                }
                else
                {
                    stackerCraneTaskCommand.Barcode = task.PalletCode;
                    stackerCraneTaskCommand.TrayType = 2;
                }
            }
            if (task.TaskType == (int)TaskTypeEnum.Inbound)//判断是否是入库任务
            {
                //获取站台编号
                Dt_PlatformStation dt_Platform=_DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                Dt_PlatformStation dt_Platform = _DtPlatformStationService.getStatiomInfo(task.SourceAddress);
                string[] targetCodest = dt_Platform.Station_storey.Split("-");
                if (targetCodest.Length == 3)
                {
@@ -270,7 +306,7 @@
                    string EndRow = EndCodest[0].Substring(1);
                    string SCEndRow = LaneModification(task.Roadway, int.Parse(EndRow));
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow );
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEndRow);
                    stackerCraneTaskCommand.EndColumn = Convert.ToInt16(EndCodest[1]);
                    stackerCraneTaskCommand.EndLayer = Convert.ToInt16(EndCodest[2]);
                }
@@ -328,7 +364,7 @@
                if (EndCodest.Length == 3)
                {
                    string EndRow = EndCodest[0].Substring(1);
                   string SCEnRow=LaneModification(task.Roadway,int.Parse(EndRow));
                    string SCEnRow = LaneModification(task.Roadway, int.Parse(EndRow));
                    stackerCraneTaskCommand.EndRow = Convert.ToInt16(SCEnRow);
                    stackerCraneTaskCommand.EndColumn = (short)(Convert.ToInt16(EndCodest[1]) + 1);
@@ -336,13 +372,13 @@
                }
                else
                {
                    //数据配置错误
                    _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"移库任务起点错误,起点:【{task.CurrentAddress}】");
                    return null;
                }
            }
            return stackerCraneTaskCommand;
        }
@@ -361,5 +397,45 @@
                return SCRow.ToString();
            }
        }
        /// <summary>
        /// ç›‘测G库、C库出库放货时屏蔽光栅
        /// </summary>
        /// <param name="taskNum"></param>
        /// <param name="stackerCraneWorkStatusDes"></param>
        public void UpdateHandShake(int taskNum, string stackerCraneWorkStatusDes)
        {
            try
            {
                Dt_Task? dtTask = _taskRepository.QueryFirst(x => x.TaskNum == taskNum);
                if (dtTask == null) return;
                string[] targetAddresses = { "G03", "G04", "C02", "C01" };
                if (dtTask.TaskType != 100 || !targetAddresses.Contains(dtTask.TargetAddress))
                    return;
                short writeValue = stackerCraneWorkStatusDes switch
                {
                    "放货中" => 1,
                    "任务完成" => 0,
                    _ => -1
                };
                if (writeValue == -1) return;
                string deviceCode = dtTask.CurrentAddress.StartsWith("C") ? "1004" : "1003";
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceCode);
                if (device == null) return;
                CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
                DeviceProDTO? handShake = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == dtTask.TargetAddress && x.DeviceProParamName == "HandShake");
                if (handShake == null) return;
                conveyorLine.Communicator.Write<short>(handShake.DeviceProAddress, writeValue);
            }
            catch
            {
            }
        }
    }
}