From fee025c0d4fb4fd41d9dbf81b6435fd8e6229d5c Mon Sep 17 00:00:00 2001
From: cjs <2216046164@qq.com>
Date: 星期一, 16 六月 2025 17:33:05 +0800
Subject: [PATCH] 11111

---
 ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs |  399 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 376 insertions(+), 23 deletions(-)

diff --git a/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs b/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
index d79d552..8a086bc 100644
--- a/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
+++ b/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
@@ -29,6 +29,7 @@
 using System.Globalization;
 using static Hanhe.iWCS.JingmenGEMTwoProtocol.PLCControl;
 using Hanhe.iWCS.DeviceDriver;
+using System.Data.OleDb;
 
 namespace Hanhe.iWCS.JingmenGEMTwoProtocol
 {
@@ -128,7 +129,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 +184,15 @@
                                                 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")
                                                                 {
@@ -713,16 +733,31 @@
             var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
             if (plc != null)
             {
-                //鍐欏叆鍖呰鏈�-瀹夊叏闂ㄥ叧闂ㄦ寚浠�-                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                if (plc.location.Contains("FLZT"))
                 {
-                    host = ip,
-                    addr = plc.writeAddr + 1,
-                    data = 3,
-                    port = plc.port
-                });
-                CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 1}閲岄潰鏁版嵁涓�.");
-                //Console.WriteLine($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 1}閲岄潰鏁版嵁涓�.");
+                    //鍐欏叆杩旀枡绔欏彴--鍙栬揣瀹屾垚
+                    var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                    {
+                        host = ip,
+                        addr = plc.writeAddr,
+                        data = 1,
+                        port = plc.port
+                    });
+                    CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr}閲岄潰鏁版嵁涓�.");
+                }
+                else
+                {
+                    //鍐欏叆鍖呰鏈�-瀹夊叏闂ㄥ叧闂ㄦ寚浠�+                    var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                    {
+                        host = ip,
+                        addr = plc.writeAddr + 1,
+                        data = 3,
+                        port = plc.port
+                    });
+                    CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 1}閲岄潰鏁版嵁涓�.");
+                }
+
             }
             else CMMLog.Debug($"鍖呰涓嬬嚎锛�锛宨p=null!");
         }
@@ -981,7 +1016,7 @@
 
                         if (req)
                         {
-                            ProcessHelper.deleteInfo(plc.location + "-澶嶇О鍏ョ紦瀛樻灦");
+                            ProcessHelper.deleteInfo(plc.location + "-澶嶇О涓嬬嚎");
                             var queryList = MongoDBSingleton.Instance.Find<packageInfoModel>(Query.And(Query.EQ("machineNo", model.machince), Query.EQ("trayCode", model.ext2), Query.EQ("weight2", "")), "packageInfoModel");
                             if (queryList.Count > 0)
                             {
@@ -1027,6 +1062,10 @@
                                 MongoDBSingleton.Instance.Update<ProductList>(Query.And(Query.EQ("Date", DateTime.Now.ToString("yyyy-MM-dd")), Query.EQ("machine", model.machince)), Update.Set("percentOfPass", proInfo.percentOfPass).Set("qualifiedQuantity", proInfo.qualifiedQuantity), UpdateFlags.None);
                             }
                         }
+                        else
+                        {
+                            ProcessHelper.recordInfo(plc.location + "-澶嶇О涓嬬嚎", "褰撳墠鍗婃垚鍝佸簱鍖烘湭鑾峰彇鍒板彲鐢ㄨ揣浣嶏紝妫�煡鏄惁宸叉弧");
+                        }
 
                     }
                     if (result.result[2] == 2)
@@ -1037,7 +1076,7 @@
                         req = WMSHelper.WMSIn(plc.location, model.ext2, ref wmstaskno, ref traycode, timeStamp);
                         if (req)
                         {
-                            ProcessHelper.deleteInfo(plc.location + "-澶嶇О鍏ョ紦瀛樻灦");
+                            ProcessHelper.deleteInfo(plc.location + "-澶嶇О涓嬬嚎");
                             var wirte = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                             {
                                 addr = plc.writeAddr + 3,
@@ -1083,7 +1122,11 @@
                                 else CMMLog.Debug($"packageInfoModel鏈壘鍒版暟鎹紝machineNo:{model.machince},trayCode:{model.ext2}");
                             }
                         }
-                        else CMMLog.Debug($"澶嶇О鍏ョ紦瀛樻灦NG娴佺▼锛歐MS鐢熸垚浠诲姟澶辫触锛�);
+                        else
+                        {
+                            ProcessHelper.recordInfo("澶嶇О涓嬬嚎", "褰撳墠NG搴撳尯鏈幏鍙栧埌鍙敤璐т綅锛屾鏌ユ槸鍚﹀凡婊�);
+                            CMMLog.Debug($"澶嶇О鍏ョ紦瀛樻灦NG娴佺▼锛歐MS鐢熸垚浠诲姟澶辫触锛�);
+                        }
                     }
                     string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "2").FirstOrDefault().location;
                     UpdateBuilder update = Update.Set("ng", result.result[2]);
@@ -1501,6 +1544,7 @@
                             string ChangeBit = WMSHelper.WmsUpdateWay(taskInfo.CN_S_SOURCE_NO, plc.Extend);
                             if (!string.IsNullOrEmpty(ChangeBit))
                             {
+                                ProcessHelper.deleteInfo("鍙犲寘NG");
                                 CMMLog.Info($"璧风偣锛歿taskInfo.CN_S_END_BIT}");
                                 CMMLog.Info($"缁堢偣锛歿ChangeBit}");
                                 int[] parms = { StockInstance.Instance.GetAGVCodeForBitCode(taskInfo.CN_S_END_BIT), StockInstance.Instance.GetAGVCodeForBitCode(ChangeBit) };
@@ -1511,12 +1555,15 @@
                                 TSHelper.GoToAGV(taskNo, 10, 8);
 
                                 MongoDBSingleton.Instance.Update<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), Update.Set("CN_S_END_BIT", ChangeBit).Set("CN_S_START_BIT", taskInfo.CN_S_END_BIT), "TN_I_TASK_MST", UpdateFlags.None);
-                                
+
                                 MongoDBSingleton.Instance.Remove<WMSInfo>(Query.EQ("trayCode", taskInfo.CN_S_BATCH_NO), RemoveFlags.Single);
 
                             }
-                            else CMMLog.Debug($"璋冪敤WMS鏀归亾鎺ュ彛锛屾湭鑾峰彇鍒板彲鐢ㄧ偣浣嶃�");
-                            //Console.WriteLine($"璇荤爜淇℃伅姣斿缁撴灉锛氭潯鐮佷笌浼犻�鐨勬暟鎹笉涓�嚧");
+                            else
+                            {
+                                CMMLog.Debug($"璋冪敤WMS鏀归亾鎺ュ彛锛屾湭鑾峰彇鍒板彲鐢ㄧ偣浣嶃�");
+                                ProcessHelper.recordInfo("鍙犲寘NG","NG搴撳尯鏈幏鍙栧埌鍙敤璐т綅锛屾鏌G搴撳尯鏄惁宸叉弧");
+                            }
                         }
                         
                     }
@@ -1863,8 +1910,16 @@
                             string wmstaskno = "";
                             string traycode = "";
                             bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
-                            if (req) CMMLog.Debug($"璋冪敤WMS鑾峰彇涓夋ゼ鍙犵洏鏈虹敓鎴愪换鍔℃垚鍔燂紒");
-                            else CMMLog.Debug($"璋冪敤WMS鑾峰彇涓夋ゼ鍙犵洏鏈虹敓鎴愪换鍔″け璐ワ紒");
+                            if (req)
+                            {
+                                CMMLog.Debug($"璋冪敤WMS鑾峰彇涓夋ゼ鍙犵洏鏈虹敓鎴愪换鍔℃垚鍔燂紒");
+                                ProcessHelper.deleteInfo("鍙犵洏涓嬬嚎");
+                            }
+                            else
+                            {
+                                ProcessHelper.recordInfo("鍙犵洏涓嬬嚎", "鍙犵洏鏈轰笅绾垮簱鍖烘湭鏌ヨ鍒板彲鐢ㄨ揣浣嶏紝妫�煡鍙犵洏鏈轰笅绾垮簱鍖烘槸鍚﹀凡婊�);
+                                CMMLog.Debug($"璋冪敤WMS鑾峰彇涓夋ゼ鍙犵洏鏈虹敓鎴愪换鍔″け璐ワ紒");
+                            }
                         }
                     }
                 }
@@ -2211,7 +2266,6 @@
                                 //鍙敓鎴愪换鍔�                                 var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList();
                                 if (CBInfo != null && timecuo != null)
-                                //if (CBInfo != null)
                                 {
                                     string timeStamp = timecuo.data.First().timeStamp.ToString();
                                     foreach (var a in CBInfo)
@@ -2727,7 +2781,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($"杩涘叆鏁版嵁澶勭悊娴佺▼锛�);
@@ -2735,6 +2789,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
@@ -3923,6 +3978,38 @@
             }
         }
 
+        /// <summary>
+        /// 鍥涢挻鎺ラ┏浣嶅叆绔嬪簱浠诲姟
+        /// </summary>
+        /// <param name="locCode"></param>
+        internal static void DGInWarehouse(string locCode)
+        {
+            try
+            {
+                var locInfo = MongoDBSingleton.Instance.FindOne<DGConnectingBits>(Query.EQ("Bit", locCode), "DGConnectingBits");
+                if (locInfo != null)
+                {
+                    if (locInfo.state == "1")
+                    {
+                        CMMLog.Info("DGInWarehouse:" + JsonConvert.SerializeObject(locInfo));
+                        string wmstaskno = "";
+                        string trayCode = "";
+                        bool req = WMSHelper.WMSIn(locCode, "鐢甸挻鎵撳寘涓嬬嚎", ref wmstaskno, ref trayCode, "", "CKHJ");
+                        if (req)
+                        {
+                            CMMLog.Info($"鐢甸挻鎺ラ┏浣嶅叆绔嬪簱娴佺▼锛歐MS鐢熸垚浠诲姟鎴愬姛锛�);
+                            MongoDBSingleton.Instance.Update<DGConnectingBits>(Query.EQ("Bit", locCode), Update.Set("state", "2"), "DGConnectingBits", UpdateFlags.None);
+                        }
+                        else CMMLog.Info($"鐢甸挻鎺ラ┏浣嶅叆绔嬪簱娴佺▼锛歐MS鐢熸垚浠诲姟澶辫触锛�);
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                CMMLog.Info("DGInWarehouse" + ex.Message);
+            }
+        }
+
         internal static void outWare(string taskNo,bool flage)
         {
             var plc = Settings.GetPlcInfo().Where(a => a.Extend == "2" && a.enable == 1).FirstOrDefault();
@@ -4437,6 +4524,272 @@
             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}");
+                }
+            }
+        }
+
+        internal static void DGMachine(Settings.PlcInfo plc, string taskNo, bool action)
+        {
+            if (action)
+            {
+                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                {
+                    host = plc.ip,
+                    addr = plc.writeAddr + 2,
+                    data = 1,
+                    port = plc.port
+                });
+                CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 2}閲岄潰鏁版嵁涓�.");
+                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
+                {
+                    dataNum = 1,
+                    addr = plc.readAddr + 2,
+                    host = plc.ip,
+                    port = plc.port
+                });
+                CMMLog.Debug($"鏌ヨ璁惧{plc.location}閫氶亾{plc.readAddr + 2}閲岄潰鏁版嵁涓簕JsonConvert.SerializeObject(result)}.");
+                if (result != null && result.errCode == 0)
+                {
+                    if (result.result[0] == 1)
+                    {
+                        //鎺ㄩ�灏忚溅杩涘叆
+                        TSHelper.GoToAGV(taskNo, 10, 3);
+                        writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                        {
+                            host = plc.ip,
+                            addr = plc.writeAddr + 2,
+                            data = 0,
+                            port = plc.port
+                        });
+                        CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 2}閲岄潰鏁版嵁涓�.");
+                    }
+                }
+            }
+            else
+            {
+                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                {
+                    host = plc.ip,
+                    addr = plc.writeAddr + 3,
+                    data = 1,
+                    port = plc.port
+                });
+                CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 3}閲岄潰鏁版嵁涓�.");
+            }
+        }
+
+        internal static void DGMachineTwo(Settings.PlcInfo plc, string taskNo, bool action)
+        {
+            if (action)
+            {
+                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                {
+                    host = plc.ip,
+                    addr = plc.writeAddr,
+                    data = 1,
+                    port = plc.port
+                });
+                CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr}閲岄潰鏁版嵁涓�.");
+                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
+                {
+                    dataNum = 1,
+                    addr = plc.readAddr + 1,
+                    host = plc.ip,
+                    port = plc.port
+                });
+                CMMLog.Debug($"鏌ヨ璁惧{plc.location}閫氶亾{plc.readAddr + 1}閲岄潰鏁版嵁涓簕JsonConvert.SerializeObject(result)}.");
+                if (result != null && result.errCode == 0)
+                {
+                    if (result.result[0] == 1)
+                    {
+                        //鎺ㄩ�灏忚溅杩涘叆
+                        TSHelper.GoToAGV(taskNo, 10, 3);
+                        writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                        {
+                            host = plc.ip,
+                            addr = plc.writeAddr,
+                            data = 0,
+                            port = plc.port
+                        });
+                        CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr}閲岄潰鏁版嵁涓�.");
+                    }
+                }
+            }
+            else
+            {
+                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
+                {
+                    host = plc.ip,
+                    addr = plc.writeAddr + 1,
+                    data = 1,
+                    port = plc.port
+                });
+                CMMLog.Debug($"鍐欏叆璁惧{plc.location}閫氶亾{plc.writeAddr + 1}閲岄潰鏁版嵁涓�.");
+            }
+        }
+
+        internal static void DMachine(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)
+                        {
+                            //鎴愬搧涓嬬嚎浠诲姟鐢熸垚鍒版帴椹冲钩鍙�+                            string traycode = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
+                            //鍙敓鎴愪换鍔�+                            var CBInfo = Settings.GetDGConnectingbitsList().Where(a => a.enable == 1).ToList();
+                            if (CBInfo != null)
+                            {
+                                //string timeStamp = timecuo.data.First().timeStamp.ToString();
+                                string timeStamp = "";
+                                foreach (var a in CBInfo)
+                                {
+                                    if (!string.IsNullOrEmpty(a.locCode))
+                                    {
+                                        //鍦ㄤ腑闂磋〃涓煡鎵剧偣浣�+                                        var CBTable = MongoDBSingleton.Instance.FindOne<DGConnectingBits>(Query.EQ("Bit", a.locCode), "DGConnectingBits");
+                                        if (CBTable != null)
+                                        {
+                                            if (string.IsNullOrEmpty(CBTable.trayCode))
+                                            {
+                                                //鐢熸垚浠诲姟锛屽苟涓斿皢鐐逛綅鍐欏叆涓棿琛�+                                                var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "鍖呰鏈烘弧鎵樹笅绾�, 0, traycode);
+                                                if (amsResult.success)
+                                                {
+                                                    CMMLog.Debug($"鍖呰鏈烘弧鎵樹笅绾匡細AMS璋冪敤API鎴愬姛锛�);
+                                                    MongoDBSingleton.Instance.Update<DGConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", traycode).Set("timeCuo", timeStamp), UpdateFlags.None);
+
+                                                    break;
+                                                }
+                                                else CMMLog.Debug($"鍖呰鏈烘弧鎵樹笅绾匡細AMS璋冪敤API澶辫触锛屽紑濮嬮噸鏂拌皟鐢紒");
+                                            }
+                                        }
+                                        else
+                                        {
+                                            //鐢熸垚浠诲姟锛屽苟涓斿皢鐐逛綅鍐欏叆涓棿琛�+                                            var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "鍖呰鏈烘弧鎵樹笅绾�, 0, traycode);
+                                            if (amsResult.success)
+                                            {
+                                                CMMLog.Debug($"鍖呰鏈烘弧鎵樹笅绾匡細AMS璋冪敤API鎴愬姛锛�);
+                                                //鎵撳寘涓嬬嚎浠诲姟鐢熸垚鎴愬姛锛屽悜涓棿琛ㄦ彃鍏ユ暟鎹�+
+                                                MongoDBSingleton.Instance.Insert<DGConnectingBits>(new DGConnectingBits { Bit = a.locCode, trayCode = traycode, state = "0", timeCuo = timeStamp });
+                                                break;
+                                            }
+                                            else CMMLog.Debug($"鍖呰鏈烘弧鎵樹笅绾匡細AMS璋冪敤API澶辫触锛屽紑濮嬮噸鏂拌皟鐢紒");
+                                        }
+                                    }
+                                    else CMMLog.Debug("鎵撳寘涓嬬嚎鍙f帴椹充綅鐐逛綅鏈厤缃�);
+                                }
+                            }
+                            else CMMLog.Debug("鎵撳寘涓嬬嚎鍙f帴椹充綅鏈厤缃�);
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    CMMLog.Info($"鍥涢挻C璁惧 err:{ex.Message}");
+                }
+            }
+        }
+
         #endregion
 
         public class WMS_STOCK_VIEW

--
Gitblit v1.9.1