|
|
|
@ -36,31 +36,37 @@ namespace HighWayIot.Plc
|
|
|
|
|
SocketKeepAliveTime = -1,
|
|
|
|
|
IsPersistentConnection = true,
|
|
|
|
|
};
|
|
|
|
|
plc.ConnectServer();
|
|
|
|
|
var a = plc.ConnectServer();
|
|
|
|
|
logHelper.Info($"Plc连接 信息:[{a.Message}] 是否成功:[{a.IsSuccess.ToString()}] 错误代码:[{a.ErrorCode}]");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|