From b8f0938c46299b821eb73b3b4aec9fc807178354 Mon Sep 17 00:00:00 2001
From: cjs <2216046164@qq.com>
Date: 星期二, 10 六月 2025 17:33:09 +0800
Subject: [PATCH] 11

---
 ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs |  121 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 116 insertions(+), 5 deletions(-)

diff --git a/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs b/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
index b6de37b..890bb65 100644
--- a/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
+++ b/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
@@ -128,7 +128,8 @@
                                                     if (trayCode.errCode == 0 && trayCode.result.Length == 80)
                                                     {
                                                         //鑾峰彇鎵樼洏鐮佺瓑淇℃伅  璇诲彇閫氶亾 10銆�1銆�2鐨勬暟鎹綔涓烘墭鐩樼爜   璇诲彇鍏跺畠閫氶亾 閲嶉噺 鍙犲寘绛変俊鎭�鎵�湁鏁版嵁瀛樺叆MachineInfo琛�-                                                        GetMachineData(pmInfo, trayCode.result);
+                                                        string location = "";
+                                                        GetMachineData(pmInfo,ref location, trayCode.result);
                                                         var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
                                                         if (tray != null && tray.addState == 0)
                                                         {
@@ -182,7 +183,16 @@
                                                 if (trayCode.errCode == 0 && trayCode.result.Length == 95)
                                                 {
                                                     //鑾峰彇鎵樼洏鐮佺瓑淇℃伅  璇诲彇閫氶亾 11銆�2銆�3鐨勬暟鎹綔涓烘墭鐩樼爜   璇诲彇鍏跺畠閫氶亾 閲嶉噺 鍙犲寘绛変俊鎭�鎵�湁鏁版嵁瀛樺叆MachineInfo琛�-                                                    GetMachineData(pmInfo, trayCode.result, false, "1");
+
+                                                    string flLoc = "";
+                                                    string location = "";
+                                                    GetMachineData(pmInfo,ref location, trayCode.result, false, "1");
+                                                    if (pmInfo.location.Contains("FLZT"))
+                                                    {
+                                                        flLoc = pmInfo.location;
+                                                        pmInfo.location = location;
+                                                    }
+
                                                     var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
                                                     if (tray != null)
                                                     {
@@ -219,6 +229,7 @@
                                                             {
                                                                 CMMLog.Info($"鐗╂枡缂栫爜锛歿tray.materialCode}锛屾壒娆″彿锛歿tray.lotNo}");
                                                                 string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1);
+                                                                pmInfo.location = !string.IsNullOrEmpty(flLoc) ? flLoc : pmInfo.location;
                                                                 HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3妤煎寘瑁呭彇鏂�, 0, tray.trayCode, timeStamp);
                                                                 ProcessHelper.deleteInfo(pmInfo.location + "-鍖呰涓嬬嚎");
                                                                 //鍖呰鍙栨枡鍗歌揣瀹屾垚锛岃澶囩敓浜ф暟閲忓姞涓�@@ -378,7 +389,8 @@
                                                     if (trayCode.errCode == 0 && trayCode.result.Length == 80)
                                                     {
                                                         //鑾峰彇鎵樼洏鐮佺瓑淇℃伅  璇诲彇閫氶亾 10銆�1銆�2鐨勬暟鎹綔涓烘墭鐩樼爜   璇诲彇鍏跺畠閫氶亾 閲嶉噺 鍙犲寘绛変俊鎭�鎵�湁鏁版嵁瀛樺叆MachineInfo琛�-                                                        GetMachineData(pmInfo, trayCode.result);
+                                                        string location = "";
+                                                        GetMachineData(pmInfo,ref location, trayCode.result);
                                                         var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
                                                         if (tray != null && tray.addState == 0)
                                                         {
@@ -432,7 +444,14 @@
                                                 if (trayCode.errCode == 0 && trayCode.result.Length == 95)
                                                 {
                                                     //鑾峰彇鎵樼洏鐮佺瓑淇℃伅  璇诲彇閫氶亾 11銆�2銆�3鐨勬暟鎹綔涓烘墭鐩樼爜   璇诲彇鍏跺畠閫氶亾 閲嶉噺 鍙犲寘绛変俊鎭�鎵�湁鏁版嵁瀛樺叆MachineInfo琛�-                                                    GetMachineData(pmInfo, trayCode.result, false, "2");
+                                                    string flLoc = "";
+                                                    string location = "";
+                                                    GetMachineData(pmInfo,ref location, trayCode.result, false, "2");
+                                                    if (pmInfo.location.Contains("FLZT"))
+                                                    {
+                                                        flLoc = pmInfo.location;
+                                                        pmInfo.location = location;
+                                                    }
                                                     var tray = MongoDBSingleton.Instance.FindOne<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo");
                                                     if (tray != null)
                                                     {
@@ -468,6 +487,7 @@
                                                             {
                                                                 CMMLog.Info($"鐗╂枡缂栫爜锛歿tray.materialCode}锛屾壒娆″彿锛歿tray.lotNo}");
                                                                 string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1);
+                                                                pmInfo.location = !string.IsNullOrEmpty(flLoc) ? flLoc : pmInfo.location;
                                                                 HHAmsExecuteResult req;
                                                                 if (pmInfo.deviceType == "22")
                                                                 {
@@ -2747,7 +2767,7 @@
         /// <param name="info"></param>
         /// <param name="result"></param>
         /// <param name="noPack">true : MES浜や簰鏂瑰紡  false : 鏃燤ES浜や簰鏂瑰紡</param>
-        private static void GetMachineData(Settings.PlcInfo pmInfo,int[] result ,bool noPack = true,string isOne = "")
+        private static void GetMachineData(Settings.PlcInfo pmInfo, ref string loc, int[] result ,bool noPack = true,string isOne = "")
         {
             //Console.WriteLine($"杩涘叆鏁版嵁澶勭悊娴佺▼锛�);
             CMMLog.Info($"杩涘叆鏁版嵁澶勭悊娴佺▼锛�);
@@ -2755,6 +2775,7 @@
             string empCode = RemoveNull(GetTrayCode(result.Take(5).ToArray()));//鍛樺伐缂栫爜
             string trayCode = RemoveNull(GetTrayCode(result.Skip(5).Take(3).ToArray()));//鎵樼洏鐮�             string location = RemoveNull(GetTrayCode(result.Skip(8).Take(1).ToArray()));//璁惧璐т綅缂栫爜
+            loc = location;
             #region 2024-12-30 鍙樻洿 鍔犲叆mes鐢熶骇璁㈠崟缂栧彿 鍒嗗綍ID   鍙樻洿娉ㄩ噴
             string orderCode = ""; //鐢熶骇璁㈠崟缂栧彿
             int fEntryID = 0; //鍒嗗綍ID
@@ -4457,6 +4478,96 @@
             CMMLog.Info($"鍦ㄩ�閬搟plc.writeAddr + 2}涓啓鍏JsonConvert.SerializeObject(num)}锛宨p锛歿plc.ip}锛岀鍙o細{plc.port}");
         }
 
+        /// <summary>
+        /// 鍥涢挻A锛堟礂鏉跨儤骞叉満缁勶級璁惧涓婄┖涓嬫弧
+        /// </summary>
+        /// <param name="plc"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        internal static void AMachine(Settings.PlcInfo plc)
+        {
+            if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
+            {
+                try
+                {
+                    var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
+                    {
+                        dataNum = 1,
+                        addr = plc.readAddr,
+                        host = plc.ip,
+                        port = plc.port
+                    });
+                    if (result != null && result.errCode == 0)
+                    {
+                        if (result.result[0] == 1)
+                        {
+                            //閫佺┖
+                            bool req = WMSHelper.WMSOut(plc.location, "", "");
+                            if (req) CMMLog.Debug($"鍥涢挻A璁惧 璋冪敤WMS鑾峰彇绌烘墭鍑哄簱鐢熸垚浠诲姟鎴愬姛锛�);//鐜板湪浠诲姟鐢盬MS鑷繁涓嬪彂锛孉MS鍋氭嫤鎴鐞嗭紙鏌ヨext1閲岄潰瀵瑰簲鐨勪换鍔$被鍨嬶紝骞舵洿鏀逛换鍔$被鍨嬶級
+                            else CMMLog.Debug($"鍥涢挻A璁惧 璋冪敤WMS鑾峰彇绌烘墭鍑哄簱鐢熸垚浠诲姟澶辫触锛�);
+                        }
+                        if (result.result[0] == 2)
+                        {
+                            //鍙栨弧
+                            string wmstaskno = "";
+                            string traycode = "";
+                            bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
+                            if (req) CMMLog.Debug($"鍥涢挻A璁惧 璋冪敤WMS鑾峰彇婊℃墭鍏ュ簱鐢熸垚浠诲姟鎴愬姛锛�);//鐜板湪浠诲姟鐢盬MS鑷繁涓嬪彂锛孉MS鍋氭嫤鎴鐞嗭紙鏌ヨext1閲岄潰瀵瑰簲鐨勪换鍔$被鍨嬶紝骞舵洿鏀逛换鍔$被鍨嬶級
+                            else CMMLog.Debug($"鍥涢挻A璁惧 璋冪敤WMS鑾峰彇婊℃墭鍏ュ簱鐢熸垚浠诲姟澶辫触锛�);
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    CMMLog.Info($"鍥涢挻A璁惧 err:{ex.Message}");
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鍥涢挻C锛堥挻鏉垮壀鍒囨満缁勶級璁惧涓婃弧涓嬬┖
+        /// </summary>
+        /// <param name="a"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        internal static void CMachine(Settings.PlcInfo plc)
+        {
+            if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
+            {
+                try
+                {
+                    var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
+                    {
+                        dataNum = 1,
+                        addr = plc.readAddr,
+                        host = plc.ip,
+                        port = plc.port
+                    });
+                    if (result != null && result.errCode == 0)
+                    {
+                        if (result.result[0] == 1)
+                        {
+                            //閫佹弧
+                            bool req = WMSHelper.WMSOut(plc.location, "", "");
+                            if (req) CMMLog.Debug($"鍥涢挻C璁惧 璋冪敤WMS鑾峰彇婊℃墭鍑哄簱鐢熸垚浠诲姟鎴愬姛锛�);//鐜板湪浠诲姟鐢盬MS鑷繁涓嬪彂锛孉MS鍋氭嫤鎴鐞嗭紙鏌ヨext1閲岄潰瀵瑰簲鐨勪换鍔$被鍨嬶紝骞舵洿鏀逛换鍔$被鍨嬶級
+                            else CMMLog.Debug($"鍥涢挻C璁惧 璋冪敤WMS鑾峰彇婊℃墭鍑哄簱鐢熸垚浠诲姟澶辫触锛�);
+                        }
+                        if (result.result[0] == 2)
+                        {
+                            //鍙栫┖
+                            string wmstaskno = "";
+                            string traycode = "";
+                            bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
+                            if (req) CMMLog.Debug($"鍥涢挻C璁惧 璋冪敤WMS鑾峰彇绌烘墭鍏ュ簱鐢熸垚浠诲姟鎴愬姛锛�);//鐜板湪浠诲姟鐢盬MS鑷繁涓嬪彂锛孉MS鍋氭嫤鎴鐞嗭紙鏌ヨext1閲岄潰瀵瑰簲鐨勪换鍔$被鍨嬶紝骞舵洿鏀逛换鍔$被鍨嬶級
+                            else CMMLog.Debug($"鍥涢挻C璁惧 璋冪敤WMS鑾峰彇绌烘墭鍏ュ簱鐢熸垚浠诲姟澶辫触锛�);
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    CMMLog.Info($"鍥涢挻C璁惧 err:{ex.Message}");
+                }
+            }
+        }
+
         #endregion
 
         public class WMS_STOCK_VIEW

--
Gitblit v1.9.1