using System; using System.Threading; namespace CellStepSender { internal class StepSender { /// /// 发送测试数据 /// /// IP /// 端口 /// 炉下标 /// 穴位下标 /// 测试项 /// 测试值 /// 上限 /// 下限 /// 单位 /// 测试结果 /// 测试时间 /// 异常信息 /// 是否发送成功 public static bool SendStep( string ip, int port, int ovenIndex, int cellIndex, string step, string value, string limitUp, string limitDown, string unit, string result, string updateTime, out string errorMsg) { errorMsg = null; TcpClientTool3 client = null; try { client = new TcpClientTool3(ip, port); string res = null; client.ExecuteMessageChanged += (sender, data) => { res = data; }; client.Connect(); string msg = $"{ovenIndex};{cellIndex};{step},{value},{limitUp},{limitDown},{unit},{result},{updateTime}\n"; client.Send(msg); int time = 1; while (res == null && time <= 50) { Thread.Sleep(100); time++; } if (res == null) { errorMsg = "Time Out"; } return res == "1"; } catch (Exception ex) { errorMsg = ex.Message; return false; } finally { client?.Disconnect(); } } } }