From e97a0f31c187e25d9b2480b6e144648239dae80d Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期一, 28 七月 2025 09:00:06 +0800 Subject: [PATCH] 1 --- HnSx/Build/Project/代码/VS自定义类/AutoThread.cs | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 105 insertions(+), 11 deletions(-) diff --git "a/HnSx/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" "b/HnSx/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" index 41dc657..a4f6721 100644 --- "a/HnSx/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" +++ "b/HnSx/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/AutoThread.cs" @@ -120,6 +120,58 @@ /// <param name="action"></param> public void ThreadSettingInit(Tag tag) { + List<Task> tasks = new List<Task>(); + tasks.Add(GetTask(wmsPrint, tag, 3000)); + + + //GZ.Modular.Redis.WriteGroupEntity group = new GZ.Modular.Redis.WriteGroupEntity(); + //group.groupName = "PLC1.ssx2Xplc"; + //group.queueStatus = 1; + //group.queueTime = DateTime.Now; + + //group.writeList = new List<GZ.Modular.Redis.ParamData>(); + //GZ.Modular.Redis.ParamData barcodeData = new GZ.Modular.Redis.ParamData(); + //barcodeData.paramName = "PLC1.Param4"; + //barcodeData.paramValue = Tag.PLC1.Param4 + 1 + ""; + + //GZ.Modular.Redis.ParamData sendData = new GZ.Modular.Redis.ParamData(); + //sendData.paramName = "PLC1.Param5"; + //sendData.paramValue = Tag.PLC1.Param5 + 2 + ""; + + //group.writeList.Add(barcodeData); + //group.writeList.Add(sendData); + //Conn.榛樿Redis.SetQueue(group, "PLC1Queue", "PLC1.Param1_LAST", "1") ? "--鎴愬姛" : "--澶辫触"; + + + + + + Task.WaitAll(tasks.ToArray()); + } + + private void wmsPrint(Tag tag) + { + HttpServer.apiHelper.WebGet($"http://{"test1.wmsdev.net:18980"}/expcenter/WebSocketPrintAction?sysType=OT01&QS01=YANGYZ&QS02={"鏃堕棿鎴�}&QS04=P4EL67LRIWWDCMP7C&clsid=export_header&method=printByWebSocket&origin=http%3A%2F%2Ftest1.wmsdev.net%3A18980&organizationId=FLUX&warehouseId=FLUXWH01&printServer=YYZ&printerName=LocalPrinter&copies=1&functionId=A2002&tableId=BAS_LOCATION&exportCode=YYZ_CN&itemObj=%0A%7B%0A++++%22bizOrgId%22%3A+%22FLUX%22%2C%0A++++%22CHECK.locationId%22%3A+%22001-001-01-01%22%2C%0A++++%22bizWarehouseId%22%3A+%22FLUXWH01%22%0A%7D%0A%0A"); + } + + private Task GetTask(Action<Tag> action, Tag tag, int i = 2500) + { + var task = Task.Run(() => + { + while (true) + { + try + { + action(tag); + } + catch (Exception ex) + { + LogHelper.Error(ex.Message, ex); + } + Thread.Sleep(i); + } + }); + return task; } public async void ThreadwebSoc() @@ -214,7 +266,7 @@ public class HttpServer { public static readonly HttpHelper apiHelper = new HttpHelper(); - System.Net.HttpListener HttpSvcHost = null; + public static System.Net.HttpListener HttpSvcHost = null; public static string _listenerPrefix = ""; public HttpServer(string ip) @@ -768,10 +820,10 @@ } else return "鍙戦�澶辫触銆�; } - else - { - return "鏈繛鎺ャ�"; - } + //else + //{ + // return "鏈繛鎺ャ�"; + //} } break; } @@ -1057,13 +1109,21 @@ public async Task<bool> SendAsync(string message) { - if (_webSocket?.State != WebSocketState.Open) + try { - throw new InvalidOperationException("WebSocket is not connected"); - } + if (_webSocket?.State != WebSocketState.Open) + { + throw new InvalidOperationException("WebSocket is not connected"); + } - var bytes = System.Text.Encoding.UTF8.GetBytes(message); - await _webSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, _cts.Token); + var bytes = System.Text.Encoding.UTF8.GetBytes(message); + await _webSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, _cts.Token); + } + catch (Exception ex) + { + LogHelper.Error(ex.Message, ex); + return false; + } return true; } } @@ -1492,8 +1552,42 @@ if (stream != null) stream.Close(); if (rsp != null) rsp.Close(); } - } + public string WebGet(string url) + { + //using (var client = new HttpClient()) { + // //璇锋眰缁撴灉 + // string result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result; + + // Console.WriteLine(result); + // return result; + + //} + //Console.WriteLine(url); + WebRequest request = WebRequest.Create(url); + request.Timeout = 6000; + request.Method = "GET"; + + try + { + WebResponse response = request.GetResponse(); + Stream dataStream = response.GetResponseStream(); + StreamReader reader = new StreamReader(dataStream); + string responseFromServer = reader.ReadToEnd(); + + reader.Close(); + dataStream.Close(); + response.Close(); + Console.WriteLine(responseFromServer); + return responseFromServer; + } + catch (Exception ex) + { + LogHelper.Error($"WebGet Error:{ex.Message}", ex); + return ""; + } + } + #endregion [鑷畾涔夌被][20250325095622918][HttpHelper] } public class Clloc -- Gitblit v1.9.1