From 5c4192f0b813d72a427eaca183d08d42046f1b41 Mon Sep 17 00:00:00 2001 From: jinxin <1013386558@qq.com> Date: 星期一, 23 六月 2025 14:43:44 +0800 Subject: [PATCH] 11 --- C#/HH.WCS.Mobox3.WeiLi/process/TaskProcess.cs | 108 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 61 insertions(+), 47 deletions(-) diff --git "a/C\043/HH.WCS.Mobox3.WeiLi/process/TaskProcess.cs" "b/C\043/HH.WCS.Mobox3.WeiLi/process/TaskProcess.cs" index c7a8396..57ffbc3 100644 --- "a/C\043/HH.WCS.Mobox3.WeiLi/process/TaskProcess.cs" +++ "b/C\043/HH.WCS.Mobox3.WeiLi/process/TaskProcess.cs" @@ -91,7 +91,7 @@ { db.Updateable<Location>().SetColumns(it => new Location() { N_CURRENT_NUM = 0 }).Where(a => a.S_CODE == mst.S_START_LOC).ExecuteCommand(); } - + LocationHelper.UnLockLoc(mst.S_START_LOC); LocationHelper.UnLockLoc(mst.S_END_LOC); @@ -136,12 +136,12 @@ db.Updateable(InWorkOrder).UpdateColumns(it => new { it.F_ACC_B_QTY }).ExecuteCommand(); } } - else + else { LogHelper.Info($"鏈壘鍒版墭鐩榹wmsTask.S_CNTR_CODE}鐨勭墿鏂欐槑缁�); } } - else + else { LogHelper.Info($"浣滀笟绫诲瀷涓簕wmsTask.S_OP_DEF_NAME} 鏃犻』闄嶉噺"); } @@ -429,47 +429,52 @@ if (codeReader != null) { LogHelper.Info($"agv={codeReader.agv},ip={codeReader.ip}"); - for (int i = 1; i <= 5; i++) + for (int i = 1; i <= 3; i++) { //try //{ //var res = OITcpHelper.HexTransit(new OITcpHelper.StrTransitData { data = "4C 4F 4E 0D", host = codeReader.ip, port = 9004 }); var res = SendHexOnce(codeReader.ip, codeReader.port, "41"); LogHelper.Info($"鎵爜杩斿洖鎶ユ枃{res}"); - if (string.IsNullOrEmpty(res)) - { - NDCApi.ChangeOrderParam(mst.S_CODE, 6, "3"); - } - else + //if (string.IsNullOrEmpty(res)) + //{ + // NDCApi.ChangeOrderParam(mst.S_CODE, 6, "3"); + //} + //else + //{ + if (res.Length >= 18) { res = res.Substring(2, 16); - var code = hexToStr(res); - Console.WriteLine(code); - LogHelper.Info($"鎵樼洏淇℃伅涓�{mst.S_CNTR_CODE},鎵爜缁撴灉涓�{code},缁撴灉锛歿mst.S_CNTR_CODE.Trim() == code.Trim()}"); - if (res != null && code.Trim() != "ERROR") + } + + + var code = hexToStr(res); + Console.WriteLine(code); + LogHelper.Info($"鎵樼洏淇℃伅涓�{mst.S_CNTR_CODE},鎵爜缁撴灉涓�{code},缁撴灉锛歿mst.S_CNTR_CODE.Trim() == code.Trim()}"); + if (!string.IsNullOrEmpty(code) && res.Trim() != "022503") + { + if (mst.S_CNTR_CODE.Trim() == code.Trim()) { - if (mst.S_CNTR_CODE.Trim() == code.Trim()) - { - NDCApi.ChangeOrderParam(mst.S_CODE, 6, "1"); - } - else - { - NDCApi.ChangeOrderParam(mst.S_CODE, 6, "2"); - } - return; + NDCApi.ChangeOrderParam(mst.S_CODE, 6, "1"); } - else if (i == 5) + else { - if (res != null) - { - NDCApi.ChangeOrderParam(mst.S_CODE, 6, "3"); - } - else - { - NDCApi.ChangeOrderParam(mst.S_CODE, 6, "4"); - } + NDCApi.ChangeOrderParam(mst.S_CODE, 6, "2"); + } + return; + } + else if (i == 3) + { + if (!string.IsNullOrEmpty(code)) + { + NDCApi.ChangeOrderParam(mst.S_CODE, 6, "3"); + } + else + { + NDCApi.ChangeOrderParam(mst.S_CODE, 6, "4"); } } + //} //} //catch (Exception ex) @@ -496,28 +501,37 @@ private static string SendHexOnce(string ip, int port, string hex) { var res = string.Empty; - Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - client.Connect(ip, port); - client.ReceiveTimeout = 2000; - if (client.Connected) + try { - client.Send(Hex2Bytes(hex)); - byte[] buffer = new byte[1024]; - try + Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + //client.Connect(ip, port); + IAsyncResult connectResult = client.BeginConnect(ip, port, null, null); + if (!connectResult.AsyncWaitHandle.WaitOne(5000)) { + client.Close(); + return ""; + } + client.ReceiveTimeout = 2000; + if (client.Connected) + { + client.Send(Hex2Bytes(hex)); + byte[] buffer = new byte[1024]; + var length = client.Receive(buffer, SocketFlags.None); byte[] data = new byte[length]; Array.Copy(buffer, data, length); res = BitConverter.ToString(data).Replace("-", ""); + + + client.Disconnect(true); + client.Dispose(); } - catch (Exception ex) - { - LogHelper.Error(ex.Message, ex); - } - client.Disconnect(true); - client.Dispose(); + client = null; } - client = null; + catch (Exception ex) + { + LogHelper.Error(ex.Message, ex); + } return res; } @@ -931,12 +945,12 @@ } var wmsTask = db.Queryable<WMSTask>().Where(a => a.S_CODE == mst.S_OP_CODE).First(); - if (wmsTask != null && wmsTask.N_TRAY_WEIGHT > 0) + if (wmsTask != null && wmsTask.N_TRAY_WEIGHT > 0) { // 1000 2000 3000 4000 5000 Trow = (wmsTask.N_TRAY_WEIGHT * 4096).ToString(); } - + Console.WriteLine($"SendTask {mst.S_CODE}"); Console.WriteLine("start=" + start); -- Gitblit v1.9.1