1
0
Fork 0

test - 添加测试代码 准备合并

master
SoulStar 4 weeks ago
parent 57cc190a41
commit d97b3ee3da

@ -36,31 +36,37 @@ namespace HighWayIot.Plc
SocketKeepAliveTime = -1, SocketKeepAliveTime = -1,
IsPersistentConnection = true, IsPersistentConnection = true,
}; };
plc.ConnectServer(); var a = plc.ConnectServer();
logHelper.Info($"Plc连接 信息:[{a.Message}] 是否成功:[{a.IsSuccess.ToString()}] 错误代码:[{a.ErrorCode}]");
} }
catch (Exception ex) catch (Exception ex)
{ {
logHelper.Error("初始化PLC服务器发生错误", ex); logHelper.Error("初始化PLC服务器发生错误", ex);
} }
//string s = IsConnect ? "成功" : "失败";
//logHelper.Info($"PLC连接{s}");
return plc; return plc;
} }
/// <summary> ///// <summary>
/// plc 是不是保持链接 ///// plc 是不是保持链接
/// </summary> ///// </summary>
public static bool IsConnect //public static bool IsConnect
//{
// get
// {
// if (MelsecInstance == null) return false;
// var result = MelsecInstance.ReadPlcType();
// logHelper.Info($"PLC型号{result.Content}");
// return result.IsSuccess;
// }
//}
public static int Test()
{ {
get return MelsecInstance.ReadInt16("D1").Content;
{
if (MelsecInstance == null) return false;
var result = MelsecInstance.ReadPlcType();
logHelper.Info($"PLC型号{result.Content}");
return result.IsSuccess;
}
} }
/// <summary> /// <summary>

@ -48,8 +48,8 @@ namespace HighWayIot.Winform.UserControlPages
private void button2_Click(object sender, EventArgs e) private void button2_Click(object sender, EventArgs e)
{ {
SqlLogHelper.AddLog("wdas", 7, 1231535246, 9); var res = PlcConnect.Test();
SqlLogHelper.AddErrorLog("wocasda", 4, 5, 6); PlcShowValue.Text = res.ToString();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save