using System;
|
using System.Threading;
|
|
namespace CellStepSender
|
{
|
internal class StepSender
|
{
|
/// <summary>
|
/// 发送测试数据
|
/// </summary>
|
/// <param name="ip">IP</param>
|
/// <param name="port">端口</param>
|
/// <param name="ovenIndex">炉下标</param>
|
/// <param name="cellIndex">穴位下标</param>
|
/// <param name="step">测试项</param>
|
/// <param name="value">测试值</param>
|
/// <param name="limitUp">上限</param>
|
/// <param name="limitDown">下限</param>
|
/// <param name="unit">单位</param>
|
/// <param name="result">测试结果</param>
|
/// <param name="updateTime">测试时间</param>
|
/// <param name="errorMsg">异常信息</param>
|
/// <returns>是否发送成功</returns>
|
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();
|
}
|
}
|
}
|
}
|