wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
wcs-server-hbf/WIDESEA_WCS/JobsPart/AGV/UpdateAgvTask.cs
@@ -14,17 +14,21 @@
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
namespace WIDESEA_WCS.SchedulerExecute.AGV
namespace WIDESEA_WCS.JobsPart.AGV
{
    public partial class AGVSchedulerExecute
    public partial class AGVServer
    {
        private static int _readUpdateAGVTaskSignalsotask = 0;
        public static void UpdateAgvTask(PLCClient plcClient)
        private static int _readUpdateAGVTaskSignalso = 0;
        public void UpdateAgvTask(PLCClient plcClient)
        {
            if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotask, 1) == 0)
            if (Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 1) == 0)
            {
                try
                {
                    if (plcClient == null)
                    {
                        return;
                    }
                    VOLContext context = new VOLContext();
                    Idt_task_numberRepository tasknumberRep = new dt_task_numberRepository(context);
                    Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
@@ -43,10 +47,8 @@
                    if (1 == taskFbInteractive && taskFbInteractiveW == 0)
                    {
                        string taskId = plcClient.ReadValue(TaskDBName.taskIDFb.ToString()).ToString();//任务ID
                        if (taskId.Contains("\b")) { taskId = taskId.Remove(0, 1); }
                        int taskState = int.Parse(plcClient.ReadValue(TaskDBName.taskStatusFb.ToString()).ToString());//1起点执行中,2起点已完成,3终点执行中,4终点已完成
                        WriteLog.GetLog().Write($"{plcClient.PLCName}开始:" + taskId + "任务状态:"+ taskState + "{DateTime.Now}", "AGV更新任务状态测试");
                        if (0 == taskState)//无含义
                            return;
                        WriteLog.GetLog().Write($"{plcClient.PLCName}任务号" + taskId + "任务状态" + taskState + $"   {DateTime.Now}", "AGV更新任务状态");
@@ -64,7 +66,6 @@
                                }
                                #region 编写对应项目的业务逻辑
                                Task task = Task.Run(() =>
                                {
                                    if (null == agvTask)
@@ -75,6 +76,7 @@
                                        //throw new Exception("起点执行失败未找到任务,ID:" + taskId);
                                    }
                                    agvTask.agv_taskstate = AGVTaskStateEnum.Executing.ToString();
                                    agvTask.agv_realesstime = DateTime.Now;
                                    int isOk = agvtaskRepository.Update(agvTask, true);
                                    if (isOk == 0)
                                    {
@@ -128,9 +130,6 @@
                        {
                            if (agvTask != null)
                            {
                                Task.Run(() =>
                                {
                                    WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈2");
                                    if (agvTask.agv_taskstate == AGVTaskStateEnum.Complete.ToString())
                                    {
@@ -139,6 +138,8 @@
                                    }
                                    #region 编写对应项目的业务逻辑
                                Task.Run(() =>
                                {
                                    if (null == agvTask)
                                    {
                                        plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
@@ -240,13 +241,13 @@
                        }
                        else if (3 == taskState)//任务终点执行中
                        {
                            if (agvTask != null)
                            {
                                WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈3");
                                #region 编写对应项目的业务逻辑
                                Task.Run(() =>
                                {
                                    WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈3");
                                    if (agvTask.agv_taskstate == AGVTaskStateEnum.Executing1.ToString())
                                    {
                                        plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
@@ -296,6 +297,8 @@
                                        }
                                    }
                                });
                                #endregion
                                plcClient.WriteValue(TaskDBName.taskFbInteractiveW.ToString(), 1);
@@ -340,9 +343,9 @@
                            {
                                WriteLog.GetLog().Write($"任务号:{agvTask.agv_tasknum},起点地址:{agvTask.agv_fromaddress},终点地址:{agvTask.agv_toaddress} 时间: {DateTime.Now}", "AGV任务反馈4");
                                #region 编写对应项目的业务逻辑
                                Task.Run(() =>
                                {
                                    agvTask.agv_taskstate = AGVTaskStateEnum.Complete1.ToString();
                                    int isOk = agvtaskRepository.Update(agvTask, true);
                                    if (isOk == 0)
@@ -820,7 +823,6 @@
                            WriteLog.GetLog().Write("WCS写入AGV任务号" + taskId + DateTime.Now + "任务异常状态确认1", "AGV更新任务状态");
                            agvtaskRepository.Delete(agvTask, true);
                        }
                        WriteLog.GetLog().Write($"{plcClient.PLCName}结束:" + taskId + "{DateTime.Now}", "AGV更新任务状态测试");
                    }
                    if (taskFbInteractive == 0 && taskFbInteractiveW == 1)
                    {
@@ -839,6 +841,7 @@
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
@@ -846,10 +849,9 @@
                }
                finally
                {
                    Interlocked.Exchange(ref _readUpdateAGVTaskSignalsotask, 0);
                    Interlocked.Exchange(ref _readUpdateAGVTaskSignalso, 0);
                }
            }
        }
    }
}