From ee67c9e74f6af07d3ffc09bd122a139713054727 Mon Sep 17 00:00:00 2001
From: leiqunqing <2136261457@qq.com>
Date: 星期五, 26 十二月 2025 17:09:35 +0800
Subject: [PATCH] 完善PLC

---
 代码管理/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs |  549 +++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 412 insertions(+), 137 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
index e345776..a1b8461 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_Tasks/PLCJob.cs"
@@ -1,137 +1,412 @@
-锘縰sing Autofac.Core;
-using HslCommunication;
-using HslCommunication.Core;
-using Microsoft.VisualBasic.FileIO;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
-using Quartz;
-using SixLabors.ImageSharp.PixelFormats;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using WIDESEAWCS_BasicInfoService;
-using WIDESEAWCS_Communicator;
-using WIDESEAWCS_Core.Helper;
-using WIDESEAWCS_QuartzJob;
-using WIDESEAWCS_QuartzJob.DeviceBase;
-using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
-
-namespace WIDESEAWCS_Tasks
-{
-    [DisallowConcurrentExecution]
-    public class PLCJob : JobBase, IJob
-    {
-        private readonly IBoxingService _boxingService;
-        private readonly IBoxingDetailService _boxingDetailService;
-        private readonly IFormulaService _formulaService;
-        private readonly IFormulaDetailService _formulaDetailService;
-        private readonly IProcessInfoService _processInfoService;
-        public PLCJob(IBoxingService boxingService, IBoxingDetailService boxingDetailService, IFormulaService formulaService, IFormulaDetailService formulaDetailService, IProcessInfoService processInfoService)
-        {
-            _boxingService = boxingService;
-            _boxingDetailService = boxingDetailService;
-            _formulaService = formulaService;
-            _formulaDetailService = formulaDetailService;
-            _processInfoService = processInfoService;
-        }
-        private readonly string set = "0x16,0x4D,0x0D,0x30,0x34,0x30,0x31,0x44,0x30,0x35,0x2E";//涓绘満鍙戦�佽缃壂鎻忔ā寮忎负涓绘満妯″紡鐨勫懡浠�,鎵弿鍣ㄨ繑鍥炴帴鏀跺埌鐨勫懡浠ゅ拰<ACK>锛�0x06锛夊悗锛屽皢鎵弿妯″紡鏇存敼涓轰富鏈烘ā寮�
-        private readonly string Text = "寮�鍚壂鐮�";//涓绘満鍙戦�佽缃壂鎻忔ā寮忎负涓绘満妯″紡鐨勫懡浠�,鎵弿鍣ㄨ繑鍥炴帴鏀跺埌鐨勫懡浠ゅ拰<ACK>锛�0x06锛夊悗锛屽皢鎵弿妯″紡鏇存敼涓轰富鏈烘ā寮�
-        private readonly string command = "0x16,0x54,0x0D";//鍙戦�佸紑濮嬭В鐮佸懡浠わ紱"0x16,0x55,0x0D"鍙戦�佸仠姝㈣В鐮佸懡浠�
-        SerialPortCommunicator portCommunicator1 = new SerialPortCommunicator("COM1", 9600, "涓婄嚎鎵爜鏋�");
-        static bool IsConnected1 = false;
-        SerialPortCommunicator portCommunicator2 = new SerialPortCommunicator("COM2", 9600, "涓婄嚎鎵爜鏋�");
-        static bool IsConnected2 = false;
-        public Task Execute(IJobExecutionContext context)
-        {
-
-            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
-            if (flag && value != null)
-            {
-                if (value is OtherDevice)
-                {
-                    OtherDevice device = (OtherDevice)value;
-                    try
-                    {
-
-                        var Heart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolHeart);
-                        var EMG = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolEMG);
-                        var AutoExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolAutoExecuting);
-                        var OnlineExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolOnlineExecuting);
-                        var Error = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolError);
-                        if (Heart && !EMG && AutoExecuting && OnlineExecuting && !Error)
-                        {
-                            #region 涓婄嚎鎵爜
-                            var Location1ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation1ScanStart);
-                            var Location1ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation1ScanDone);
-                            if (Location1ScanStart && !Location1ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
-                            {
-                                #region MyRegion
-                                #region 涓插彛杩炴帴
-                                if (!IsConnected1) IsConnected1 = portCommunicator1.Connect();
-                                if (!IsConnected2) IsConnected2 = portCommunicator2.Connect();
-                                byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
-                                portCommunicator1.Write(dataToSend1);
-                                string receiveData = portCommunicator2.ToString(Encoding.UTF8);
-                                //if (receiveData == "0x16,0x54,0x0D")
-                                //{
-                                //    Console.WriteLine(receiveData);
-                                byte[] dataToSend2 = Encoding.ASCII.GetBytes("PL106");//杞垚瀛楄妭鏁扮粍
-                                portCommunicator2.Write(dataToSend2);
-                                //}
-                                string PalletCode = portCommunicator1.ToString(Encoding.UTF8);
-                                if (PalletCode.IsNotEmptyOrNull())
-                                {
-                                    var boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
-                                }
-                                IsConnected1 = !portCommunicator1.Disconnect();
-                                IsConnected2 = !portCommunicator2.Disconnect();
-                                #endregion
-                                #endregion
-
-                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
-                            }
-                            else if (!Location1ScanStart && Location1ScanDone)
-                            {
-                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, false);
-                            }
-                            #endregion
-
-
-                            #region 鍘嬭鎵爜
-                            var Location2ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation2ScanStart);
-                            if (Location2ScanStart)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ鎵樼洏缁戝畾鎴愬搧鍔犲伐鎵�闇�鏁版嵁锛屽啓鍏LC
-                            {
-
-                            }
-                            #endregion
-
-                            #region 妫�娴嬫壂鐮�
-                            var Location3ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation3ScanStart);
-                            #endregion
-
-                            #region 涓嬬嚎鎵爜
-                            var Location4ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation4ScanStart);
-                            #endregion
-                        }
-
-
-                        //var a = _boxingService.Repository.QueryFirst(x => x.PalletCode == "1232123");
-                        //WriteInfo(device.DeviceName, "infoLog");
-
-                        //WriteDebug(device.DeviceName, "debugLog");
-                    }
-                    catch (Exception ex)
-                    {
-                        WriteError(device.DeviceName, "閿欒", ex);
-                    }
-                }
-            }
-            return Task.CompletedTask;
-        }
-    }
-
-
-}
+锘縰sing System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Autofac.Core;
+using HslCommunication;
+using HslCommunication.Core;
+using Microsoft.VisualBasic.FileIO;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using Quartz;
+using SixLabors.ImageSharp.PixelFormats;
+using WIDESEAWCS_BasicInfoService;
+using WIDESEAWCS_Communicator;
+using WIDESEAWCS_Core.BaseRepository;
+using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Model.Models;
+using WIDESEAWCS_QuartzJob;
+using WIDESEAWCS_QuartzJob.DeviceBase;
+using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
+
+namespace WIDESEAWCS_Tasks
+{
+    [DisallowConcurrentExecution]
+    public class PLCJob : JobBase, IJob
+    {
+        private readonly IBoxingService _boxingService;
+        private readonly IBoxingDetailService _boxingDetailService;
+        private readonly IFormulaService _formulaService;
+        private readonly IFormulaDetailService _formulaDetailService;
+        private readonly IProcessInfoService _processInfoService;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
+        public PLCJob(IBoxingService boxingService, IBoxingDetailService boxingDetailService, IFormulaService formulaService, IFormulaDetailService formulaDetailService, IProcessInfoService processInfoService, IUnitOfWorkManage unitOfWorkManage)
+        {
+            _boxingService = boxingService;
+            _boxingDetailService = boxingDetailService;
+            _formulaService = formulaService;
+            _formulaDetailService = formulaDetailService;
+            _processInfoService = processInfoService;
+            _unitOfWorkManage = unitOfWorkManage;
+        }
+        private readonly string set = "0x16,0x4D,0x0D,0x30,0x34,0x30,0x31,0x44,0x30,0x35,0x2E";//涓绘満鍙戦�佽缃壂鎻忔ā寮忎负涓绘満妯″紡鐨勫懡浠�,鎵弿鍣ㄨ繑鍥炴帴鏀跺埌鐨勫懡浠ゅ拰<ACK>锛�0x06锛夊悗锛屽皢鎵弿妯″紡鏇存敼涓轰富鏈烘ā寮�
+        private readonly string Text = "寮�鍚壂鐮�";//涓绘満鍙戦�佽缃壂鎻忔ā寮忎负涓绘満妯″紡鐨勫懡浠�,鎵弿鍣ㄨ繑鍥炴帴鏀跺埌鐨勫懡浠ゅ拰<ACK>锛�0x06锛夊悗锛屽皢鎵弿妯″紡鏇存敼涓轰富鏈烘ā寮�
+        private readonly string command = "0x16,0x54,0x0D";//鍙戦�佸紑濮嬭В鐮佸懡浠わ紱"0x16,0x55,0x0D"鍙戦�佸仠姝㈣В鐮佸懡浠�
+        SerialPortCommunicator portCommunicator1 = new SerialPortCommunicator("COM1", 9600, "涓婄嚎鎵爜鏋�");
+        static bool IsConnected1 = false;
+        SerialPortCommunicator portCommunicator2 = new SerialPortCommunicator("COM2", 9600, "涓婄嚎鎵爜鏋�");
+        static bool IsConnected2 = false;
+        SerialPortCommunicator portCommunicator17 = new SerialPortCommunicator("COM17", 9600, "鍘嬭鎵爜鏋�");
+        static bool IsConnected17 = false;
+        SerialPortCommunicator portCommunicator18 = new SerialPortCommunicator("COM18", 9600, "鍘嬭鎵爜鏋�");
+        static bool IsConnected18 = false;
+        SerialPortCommunicator portCommunicator19 = new SerialPortCommunicator("COM19", 9600, "鍘嬭鎵爜鏋�");
+        static bool IsConnected19 = false;
+        SerialPortCommunicator portCommunicator20 = new SerialPortCommunicator("COM20", 9600, "鍘嬭鎵爜鏋�");
+        static bool IsConnected20 = false;
+        public Task Execute(IJobExecutionContext context)
+        {
+
+            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
+            if (flag && value != null)
+            {
+                if (value is OtherDevice)
+                {
+                    OtherDevice device = (OtherDevice)value;
+                    try
+                    {
+
+                        var Heart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolHeart);
+                        var EMG = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolEMG);
+                        var AutoExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolAutoExecuting);
+                        var OnlineExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolOnlineExecuting);
+                        var Error = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolError);
+                        if (Heart && !EMG && AutoExecuting && OnlineExecuting && !Error)
+                        {
+                            #region 涓婄嚎鎵爜
+                            HandleOnlineScan(device);
+                            #endregion
+
+                            #region 鍘嬭鎵爜
+                            HandlePressScan(device);
+                            #endregion
+
+                            #region 妫�娴嬫壂鐮�
+                            HandleDetectScan(device);
+                            #endregion
+
+                            #region 涓嬬嚎鎵爜
+                            HandleOfflineScan(device);
+
+                            #endregion
+                        }
+
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteError(device.DeviceName, "閿欒", ex);
+                    }
+                }
+            }
+            return Task.CompletedTask;
+        }
+
+        /// <summary>
+        /// 涓婄嚎鎵爜
+        /// </summary>
+        /// <param name="device"></param>
+        private void HandleOnlineScan(OtherDevice device)
+        {
+            var Location1ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation1ScanStart);
+            var Location1ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation1ScanDone);
+            if (Location1ScanStart && !Location1ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
+            {
+                #region 涓插彛杩炴帴
+                if (!IsConnected1) IsConnected1 = portCommunicator1.Connect();
+                if (!IsConnected2) IsConnected2 = portCommunicator2.Connect();
+                byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
+                portCommunicator1.Write(dataToSend1);
+                string receiveData = portCommunicator2.ToString(Encoding.UTF8);
+                //if (receiveData == "0x16,0x54,0x0D")
+                //{
+                //    Console.WriteLine(receiveData);
+                byte[] dataToSend2 = Encoding.ASCII.GetBytes("PL106");//杞垚瀛楄妭鏁扮粍
+                portCommunicator2.Write(dataToSend2);
+                //}
+                string PalletCode = portCommunicator1.ToString(Encoding.UTF8);
+                using (var uow = _unitOfWorkManage.CreateUnitOfWork())
+                {
+                    try
+                    {
+                        if (PalletCode.IsNotEmptyOrNull())
+                        {
+                            var boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
+                            if (boxing == null)
+                            {
+                                WriteInfo(device.DeviceName, "绌烘墭鐩�");
+                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+                                return;
+                            }
+                            List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == boxing.Id);
+                            Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == boxing.ProductCode);
+                            if (dt_Formula == null)
+                            {
+                                WriteError(device.DeviceName, "鏃犳垚鍝侀厤鏂�");
+                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+                                return;
+                            }
+                            List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == dt_Formula.Id);
+                            //姣旇緝闆朵欢鏄惁榻愬叏
+                            if (!_boxingDetailService.IsComponentCodesEqual(dt_BoxingDetails, dt_FormulaDetails))
+                            {
+                                WriteError(device.DeviceName, "闆朵欢鏈夐棶棰橈紝璇峰鐞�");
+                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+                                return;
+                            }
+                        }
+                        //鎻愪氦浜嬪姟
+                        uow.Commit();
+
+                        IsConnected1 = !portCommunicator1.Disconnect();
+                        IsConnected2 = !portCommunicator2.Disconnect();
+                        #endregion
+                        device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+                        
+
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteError(device.DeviceName, "涓婄嚎鎵爜娴佺▼鎵ц寮傚父", ex);
+                    }
+                }
+            }
+            else if (!Location1ScanStart && Location1ScanDone)
+            {
+                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, false);
+            }
+        }
+
+        /// <summary>
+        /// 鍘嬭鎵爜
+        /// </summary>
+        /// <param name="device"></param>
+        private void HandlePressScan(OtherDevice device)
+        {
+            var Location2ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation2ScanStart);
+            var Location2ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation2ScanDone);
+            if (Location2ScanStart && !Location2ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ鎵樼洏缁戝畾鎴愬搧鍔犲伐鎵�闇�鏁版嵁锛屽啓鍏LC
+            {
+                #region MyRegion
+                #region 涓插彛杩炴帴
+                if (!IsConnected17) IsConnected17 = portCommunicator17.Connect();
+                if (!IsConnected18) IsConnected18 = portCommunicator18.Connect();
+                byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
+                portCommunicator17.Write(dataToSend1);
+                string receiveData = portCommunicator18.ToString(Encoding.UTF8);
+                byte[] dataToSend2 = Encoding.ASCII.GetBytes("PL106");//杞垚瀛楄妭鏁扮粍
+                portCommunicator18.Write(dataToSend2);
+                //}
+                string PalletCode = portCommunicator17.ToString(Encoding.UTF8);
+                using (var uow = _unitOfWorkManage.CreateUnitOfWork())
+                {
+                    try
+                    {
+                        if (PalletCode.IsNotEmptyOrNull())
+                        {
+                            Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
+                            if (dt_Boxing == null)
+                            {
+                                WriteInfo(device.DeviceName, "绌烘墭鐩�");
+                                device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
+                                return;
+                            }
+                            Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
+                            //鍐欏叆PLC
+                            device.SetValue(W_PLCDBName.wrealProductLength, dt_Formula.ProductLength);
+                            device.SetValue(W_PLCDBName.wrealProductWidth, dt_Formula.ProductWidth);
+                            device.SetValue(W_PLCDBName.wrealProductHeight, dt_Formula.ProductHeight);
+                            device.SetValue(W_PLCDBName.wrealScrewDownsetDistance, dt_Formula.ScrewDownsetDistance);
+                            device.SetValue(W_PLCDBName.wrealScrewTorqueOutput, dt_Formula.ScrewTorqueOutput);
+                            device.SetValue(W_PLCDBName.wDintAutoScrewOn, dt_Formula.DintAutoScrewOn);
+
+                            //鍘嬭鎵爜瀹屾垚
+                            device.SetValue(W_PLCDBName.wboolLocation2ScanDone, true);
+
+                            //鎺ユ敹鏁版嵁
+                            float PressHeight = device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectPressHeight);
+                            float ScrewTorque = device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectScrewTorque);
+                            float ScrewAngle = device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectScrewAngle);
+
+                            //娣诲姞鍒版暟鎹簱
+                            Dt_ProcessInfo dt_ProcessInfo = new Dt_ProcessInfo()
+                            {
+                                PalletCode = PalletCode,
+                                ProductCode = dt_Formula.ProductCode,
+                                ProductName = dt_Formula.ProductName,
+                                PressHeight = PressHeight,
+                                ScrewTorque = ScrewTorque,
+                                ScrewAngle = ScrewAngle
+
+                            };
+                            _processInfoService.Repository.AddData(dt_ProcessInfo);
+                        }
+                        //鎻愪氦浜嬪姟
+                        uow.Commit();
+
+                        IsConnected17 = !portCommunicator17.Disconnect();
+                        IsConnected18 = !portCommunicator18.Disconnect();
+                        #endregion
+                        #endregion
+
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteError(device.DeviceName, "鍘嬭鎵爜娴佺▼鎵ц寮傚父", ex);
+                    }
+                }
+            }
+            else if (!Location2ScanStart && Location2ScanDone)
+            {
+                device.SetValue(W_PLCDBName.wboolLocation2ScanDone, false);
+            }
+        }
+
+        /// <summary>
+        /// 妫�娴嬫壂鐮�
+        /// </summary>
+        /// <param name="device"></param>
+        private void HandleDetectScan(OtherDevice device)
+        {
+            var Location3ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation3ScanStart);
+            var Location3ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation3ScanDone);
+            if (Location3ScanStart && !Location3ScanDone)
+            {
+                #region MyRegion
+                #region 涓插彛杩炴帴
+                if (!IsConnected19) IsConnected19 = portCommunicator19.Connect();
+                if (!IsConnected20) IsConnected20 = portCommunicator20.Connect();
+                byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
+                portCommunicator19.Write(dataToSend1);
+                string receiveData = portCommunicator20.ToString(Encoding.UTF8);
+                byte[] dataToSend2 = Encoding.ASCII.GetBytes("PL106");//杞垚瀛楄妭鏁扮粍
+                portCommunicator20.Write(dataToSend2);
+                //}
+                string PalletCode = portCommunicator19.ToString(Encoding.UTF8);
+
+                using (var uow = _unitOfWorkManage.CreateUnitOfWork())
+                {
+                    try
+                    {
+                        if (PalletCode.IsNotEmptyOrNull())
+                        {
+                            Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
+                            if (dt_Boxing == null)
+                            {
+                                WriteInfo(device.DeviceName, "绌烘墭鐩�");
+                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+                                return;
+                            }
+                            Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_Boxing.ProductCode);
+                            //鍐欏叆PLC
+                            device.SetValue(W_PLCDBName.wrealXDirectionDistance1, dt_Formula.XDirectionDistance1);
+                            device.SetValue(W_PLCDBName.wrealYDirectionHeight1, dt_Formula.YDirectionHeight1);
+                            device.SetValue(W_PLCDBName.wrealXDirectionDistance2, dt_Formula.XDirectionDistance2);
+                            device.SetValue(W_PLCDBName.wrealYDirectionHeight2, dt_Formula.YDirectionHeight2);
+                            device.SetValue(W_PLCDBName.wrealXDirectionDistance3, dt_Formula.XDirectionDistance3);
+                            device.SetValue(W_PLCDBName.wrealYDirectionHeight3, dt_Formula.YDirectionHeight3);
+
+                            //妫�娴嬫壂鐮佸畬鎴�
+                            device.SetValue(W_PLCDBName.wboolLocation3ScanDone, true);
+
+                            //鎺ユ敹鏁版嵁
+                            float Height1 = device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight1);
+                            float Height2 = device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight2);
+                            float Height3 = device.GetValue<R_PLCDBName, float>(R_PLCDBName.rrealDetectHeight3);
+
+                            Dt_ProcessInfo dt_ProcessInfo = _processInfoService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
+                            if (dt_ProcessInfo == null)
+                            {
+                                WriteInfo(device.DeviceName, "鎴愬搧鏈帇瑁�");
+                                device.SetValue(W_PLCDBName.wboolLocation1ScanDone, true);
+                                return;
+                            }
+                            dt_ProcessInfo.Height1 = Height1;
+                            dt_ProcessInfo.Height2 = Height2;
+                            dt_ProcessInfo.Height3 = Height3;
+                            _processInfoService.Repository.UpdateData(dt_ProcessInfo);
+
+                        }
+                        //鎻愪氦浜嬪姟
+                        uow.Commit();
+
+                        IsConnected19 = !portCommunicator19.Disconnect();
+                        IsConnected20 = !portCommunicator20.Disconnect();
+                        #endregion
+                        #endregion
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteError(device.DeviceName, "妫�娴嬫壂鐮佹祦绋嬫墽琛屽紓甯�", ex);
+                    }
+                }
+            }
+            else if (!Location3ScanStart && Location3ScanDone)
+            {
+                device.SetValue(W_PLCDBName.wboolLocation3ScanDone, false);
+            }
+
+        }
+
+        /// <summary>
+        /// 涓嬬嚎鎵爜
+        /// </summary>
+        /// <param name="device"></param>
+        private void HandleOfflineScan(OtherDevice device)
+        {
+            var Location4ScanStart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolLocation4ScanStart);
+            var Location4ScanDone = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolLocation4ScanDone);
+            if (Location4ScanStart && !Location4ScanDone)//鎺у埗鎵爜鏋壂鎻忔墭鐩樼爜锛屾牴鎹墭鐩樼爜鏌ヨ缁勭洏鏁版嵁锛屽垽鏂墭鐩樼粦瀹氭垚鍝佹槸鍚﹀凡缁戝畾鎵�鏈夋墍闇�闆朵欢
+            {
+                if (!IsConnected17) IsConnected17 = portCommunicator17.Connect();
+                if (!IsConnected18) IsConnected18 = portCommunicator18.Connect();
+                byte[] dataToSend1 = Encoding.ASCII.GetBytes(command);//杞垚瀛楄妭鏁扮粍
+                portCommunicator17.Write(dataToSend1);
+                string receiveData = portCommunicator18.ToString(Encoding.UTF8);
+                byte[] dataToSend2 = Encoding.ASCII.GetBytes("PL106");//杞垚瀛楄妭鏁扮粍
+                portCommunicator18.Write(dataToSend2);
+                //}
+                string PalletCode = portCommunicator17.ToString(Encoding.UTF8);
+                using (var uow = _unitOfWorkManage.CreateUnitOfWork())
+                {
+                    try
+                    {
+                        if (PalletCode.IsNotEmptyOrNull())
+                        {
+                            Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
+                            if (dt_Boxing == null)
+                            {
+                                WriteInfo(device.DeviceName, "璇ユ墭鐩樹负绌烘墭鐩�");
+                                device.SetValue(W_PLCDBName.wboolLocation4ScanDone, true);
+                                return;
+                            }
+
+                            _boxingService.Repository.DeleteData(dt_Boxing);
+                            List<Dt_BoxingDetail> dt_BoxingDetails = _boxingDetailService.Repository.QueryData(x => x.BoxingId == dt_Boxing.Id);
+                            foreach (Dt_BoxingDetail dt_BoxingDetail in dt_BoxingDetails)
+                            {
+                                _boxingDetailService.Repository.DeleteDataById(dt_BoxingDetail.Id);
+                            }
+                            uow.Commit();
+                            //涓嬬嚎鎵爜瀹屾垚
+                            device.SetValue(W_PLCDBName.wboolLocation4ScanDone, true);
+                        }
+                        IsConnected17 = !portCommunicator17.Disconnect();
+                        IsConnected18 = !portCommunicator18.Disconnect();
+                    }
+                    catch (Exception ex)
+                    {
+                        WriteError(device.DeviceName, "涓嬬嚎鎵爜娴佺▼鎵ц寮傚父", ex);
+                    }
+                }
+            }
+            else if (!Location4ScanStart && Location4ScanDone)
+            {
+                device.SetValue(W_PLCDBName.wboolLocation2ScanDone, false);
+            }
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3