From 55ae035e05530817bd3b923c3d6b1ec275e47332 Mon Sep 17 00:00:00 2001
From: cjs <2216046164@qq.com>
Date: 星期四, 12 六月 2025 17:34:50 +0800
Subject: [PATCH] 111

---
 ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs |  211 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 201 insertions(+), 10 deletions(-)

diff --git a/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs b/ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
index 9c3767a..7298a28 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
 {
@@ -732,16 +733,31 @@
             var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
             if (plc != null && !plc.location.Contains("FLZT"))
             {
-                //鍐欏叆鍖呰鏈�-瀹夊叏闂ㄥ叧闂ㄦ寚浠�-                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!");
         }
@@ -2250,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)
@@ -4567,6 +4582,182 @@
             }
         }
 
+        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.GetConnectingbitsList().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<ConnectingBits>(Query.EQ("Bit", a.locCode), "ConnectingBits");
+                                        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<ConnectingBits>(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<ConnectingBits>(new ConnectingBits { 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