| | |
| | | /// <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() |
| | |
| | | //å°æ°æ®ç¼åå°å
åã |
| | | try |
| | | { |
| | | return; |
| | | Thread.Sleep(1000); |
| | | while (true) |
| | | { |
| | |
| | | new HttpServer(ip.ToString()).HttpServerRun(); |
| | | //new TcpServer(ip.ToString()); |
| | | //var server = new EnhancedWebSocketServer($"http://{ip.ToString()}:8809/").StartAsync(); http://10.20.66.121:18080 |
| | | new WebSocketClientWithReconnect($"ws://10.20.66.121:20001/socket").StartAsync(); |
| | | //new WebSocketClientWithReconnect($"ws://10.20.66.121:20001/socket").StartAsync(); |
| | | new WebSocketClientWithReconnect($"ws://10.20.66.121:20001/datahubjson/websocket/").StartAsync(); |
| | | //new WebSocketClientWithReconnect($"ws://{ip.ToString()}:8809/socket").StartAsync(); |
| | | WebSocketClientWithReconnect.Instance.OnMessageReceived += (msg) => |
| | | { |
| | | //reportWeightinfo.channel.Writer.TryWrite(JsonConvert.DeserializeObject<ReportWeightInfoResponse>(msg)); |
| | | reportWeightinfo.channel.Writer.TryWrite(new ReportWeightInfoResponse |
| | | { |
| | | Response = new ReportWeightInfoResponseData |
| | | { |
| | | Return = new ReportWeightInfoReturnInfo |
| | | { |
| | | returnCode = "0000", |
| | | sortingChute = msg |
| | | } |
| | | } |
| | | }); |
| | | reportWeightinfo.channel.Writer.TryWrite(msg); |
| | | //reportWeightinfo.channel.Writer.TryWrite(new ReportWeightInfoResponse |
| | | //{ |
| | | // Response = new ReportWeightInfoResponseData |
| | | // { |
| | | // Return = new ReportWeightInfoReturnInfo |
| | | // { |
| | | // returnCode = "0000", |
| | | // sortingChute = msg |
| | | // } |
| | | // } |
| | | //}); |
| | | }; |
| | | break; |
| | | } |
| | |
| | | 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) |
| | |
| | | Return = new ReturnInfo |
| | | { |
| | | returnCode = "0000", |
| | | returnDesc = "", |
| | | returnDesc = "ok", |
| | | returnFlag = "1" |
| | | } |
| | | } |
| | |
| | | { |
| | | returnCode = "0000", |
| | | returnFlag = "1", |
| | | returnDesc="ok" |
| | | returnDesc = "ok" |
| | | } |
| | | } |
| | | }); |
| | |
| | | Return = new PutConveyorTaskReturnInfo |
| | | { |
| | | returnCode = "0000", |
| | | returnDesc="ok", |
| | | returnDesc = "ok", |
| | | returnFlag = "1" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }; |
| | | string requeeee = string.IsNullOrEmpty(requestJson) ? JsonConvert.SerializeObject(req) : requestJson; |
| | | //Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss.fff")}>>>GGG{i}"); |
| | | LogHelper.Info(JsonConvert.SerializeObject(req)); |
| | | var b = WebSocketClientWithReconnect.Instance?.SendAsync(JsonConvert.SerializeObject(req)).Result; |
| | | LogHelper.Info(requeeee); |
| | | var b = WebSocketClientWithReconnect.Instance?.SendAsync(requeeee).Result; |
| | | Console.WriteLine(req.data.header.deliveryNo + "åé宿ï¼ï¼" + b); |
| | | if (b == true) |
| | | { |
| | |
| | | } |
| | | else return "åé失败ã"; |
| | | } |
| | | //else |
| | | //{ |
| | | // return "æªè¿æ¥ã"; |
| | | //} |
| | | } |
| | | break; |
| | | } |
| | |
| | | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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 |
| | |
| | | /// <summary> |
| | | /// è¿åæè¿° |
| | | /// </summary> |
| | | public string returnDesc { get; set; } |
| | | public string returnDesc { get; set; } = "ok"; |
| | | |
| | | /// <summary> |
| | | /// è¿åæ è®° - 1:æå, 0:失败 |
| | |
| | | } |
| | | public class reportWeightinfo |
| | | { |
| | | public static Channel<ReportWeightInfoResponse> channel = Channel.CreateUnbounded<ReportWeightInfoResponse>(); |
| | | public static Channel<string> channel = Channel.CreateUnbounded<string>(); |
| | | |
| | | internal static async Task<ReportWeightInfoReturnInfo> GetChinnnl() |
| | | internal static async Task<string> GetChinnnl() |
| | | { |
| | | //var response = await reportWeightinfo.channel.Reader.ReadAllAsync();// foreach (var response in reportWeightinfo.channel.Reader.ReadAllAsync()) |
| | | //{ |
| | |
| | | { |
| | | while (reportWeightinfo.channel.Reader.TryRead(out var response)) |
| | | { |
| | | return response?.Response?.Return ?? new ReportWeightInfoReturnInfo { returnCode = "0001", sortingChute = "0", returnDesc = "è¿å为空ã" }; |
| | | return response;/// response?.Response?.Return ?? new ReportWeightInfoReturnInfo { returnCode = "0001", sortingChute = "0", returnDesc = "è¿å为空ã" }; |
| | | } |
| | | } |
| | | return new ReportWeightInfoReturnInfo { returnCode = "0001", sortingChute = "0", returnDesc = "è¿å为空ã" }; |
| | | return "è¿å为空"; new ReportWeightInfoReturnInfo { returnCode = "0001", sortingChute = "0", returnDesc = "è¿å为空ã" }; |
| | | } |
| | | |
| | | /// <summary> |