diff --git a/HighWayIot.Plc/HighWayIot.Plc.csproj b/HighWayIot.Plc/HighWayIot.Plc.csproj
index 1fac2c2..0dcc92f 100644
--- a/HighWayIot.Plc/HighWayIot.Plc.csproj
+++ b/HighWayIot.Plc/HighWayIot.Plc.csproj
@@ -63,8 +63,5 @@
-
-
-
\ No newline at end of file
diff --git a/HighWayIot.Plc/PlcConnect.cs b/HighWayIot.Plc/PlcConnect.cs
index d1b06e9..52fc8ef 100644
--- a/HighWayIot.Plc/PlcConnect.cs
+++ b/HighWayIot.Plc/PlcConnect.cs
@@ -48,9 +48,6 @@ namespace HighWayIot.Plc
logHelper.Error("初始化PLC服务器发生错误!", ex);
}
- //string s = IsConnect ? "成功" : "失败";
- //logHelper.Info($"PLC连接:{s}");
-
return plc;
}
@@ -62,18 +59,12 @@ namespace HighWayIot.Plc
get
{
if (MelsecInstance == null) return false;
- var result = MelsecInstance.ReadPlcType();
- logHelper.Info($"PLC型号 信息:[{result.Message}] 内容:[{result.Message}]");
- return result.IsSuccess;
+ var result = MelsecInstance.IpAddress;
+ logHelper.Info($"PLCIP:[{result}]");
+ return !string.IsNullOrEmpty(result);
}
}
- public static int Test()
- {
- var s = IsConnect;
- return MelsecInstance.ReadInt16("D1").Content;
- }
-
///
/// 写入数据
///
@@ -131,210 +122,220 @@ namespace HighWayIot.Plc
}
///
- /// 读取数据 使用泛型
+ /// 读取bool
///
- /// 读取类型
- /// 地址
- /// 数据类型
+ ///
///
- public static T PlcRead(string address, DataTypeEnum type)
+ public static bool ReadBool(string address)
{
- T result = default;
+ OperateResult result = new OperateResult();
try
{
- result = (T)Convert.ChangeType(PlcRead(address, type), typeof(T));
+ result = MelsecInstance.ReadBool(address);
}
- catch(Exception ex)
+ catch (Exception ex)
{
- logHelper.Error($"传入类型有误!", ex);
+ logHelper.Error($"PLC读取Bool发生错误!address:[{address}]", ex);
+ return default;
}
- return result;
+ if (!result.IsSuccess)
+ {
+ return default;
+ }
+ return result.Content;
}
///
- /// 读取数据 不使用泛型
+ /// 读取Int16
///
- /// 读取类型
- /// 地址
- /// 数据类型
+ ///
///
- public static object PlcRead(string address, DataTypeEnum type)
+ public static short ReadInt16(string address)
{
- object result = default;
- var oResult = new OperateResult