1
0
Fork 0
nodyang@aliyun.com 4 weeks ago
commit 05a6e312f0

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

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

Loading…
Cancel
Save