| | |
| | | using System.ComponentModel; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Linq; |
| | | using System.Net.Sockets; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | public WebResponseContent LedShowTask(string stationCode, string palletCode, int taskType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string ledApiAddress = AppSettings.Get("LEDApiAddress"); |
| | | if (string.IsNullOrEmpty(ledApiAddress)) |
| | | { |
| | | return WebResponseContent.Instance.Error("未找到LED服务地址"); |
| | | } |
| | | string ipAddress = ledApiAddress; |
| | | int port = 8888; // 默认端口 |
| | | string sendData = $"{stationCode}|{palletCode}|{taskType}"; |
| | | |
| | | using (TcpClient tcpClient = new TcpClient()) |
| | | { |
| | | tcpClient.ReceiveTimeout = 5000; |
| | | tcpClient.SendTimeout = 5000; |
| | | |
| | | tcpClient.Connect(ipAddress, port); |
| | | |
| | | NetworkStream stream = tcpClient.GetStream(); |
| | | byte[] data = Encoding.UTF8.GetBytes(sendData); |
| | | stream.Write(data, 0, data.Length); |
| | | stream.Flush(); |
| | | |
| | | Console.WriteLine($"✅ TCP数据发送成功:{sendData}"); |
| | | } |
| | | |
| | | } |
| | | catch (SocketException socketEx) |
| | | { |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"LED推送失败:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任务手动完成 |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | public async Task<WebResponseContent> ManualTaskCompleted(int taskNum) |
| | | { |
| | | try |
| | | { |
| | | string url = "http://localhost:9290"; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return await Task.FromResult(WebResponseContent.Instance.Error($"未找到WCSApi地址,请检查配置文件")); |
| | | } |
| | | string response = HttpHelper.Post($"{url}/api/Task/TaskCompleted?taskNum=" + taskNum,taskNum.ToString()); |
| | | |
| | | return await Task.FromResult(JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误")); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | } |
| | | } |
| | | } |