Emergency Fix: Support .NET Core
This commit is contained in:
@@ -5,7 +5,15 @@ namespace Modbus.Net
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 基础的协议连接类
|
/// 基础的协议连接类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BaseConnector
|
public abstract class BaseConnector : BaseConnector<byte[], byte[]>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 基础的协议连接类
|
||||||
|
/// </summary>
|
||||||
|
public abstract class BaseConnector<TParamIn, TParamOut>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标识Connector的连接关键字
|
/// 标识Connector的连接关键字
|
||||||
@@ -40,27 +48,27 @@ namespace Modbus.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">需要发送的数据</param>
|
/// <param name="message">需要发送的数据</param>
|
||||||
/// <returns>是否发送成功</returns>
|
/// <returns>是否发送成功</returns>
|
||||||
public abstract bool SendMsgWithoutReturn(byte[] message);
|
public abstract bool SendMsgWithoutReturn(TParamIn message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 无返回发送数据
|
/// 无返回发送数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">需要发送的数据</param>
|
/// <param name="message">需要发送的数据</param>
|
||||||
/// <returns>是否发送成功</returns>
|
/// <returns>是否发送成功</returns>
|
||||||
public abstract Task<bool> SendMsgWithoutReturnAsync(byte[] message);
|
public abstract Task<bool> SendMsgWithoutReturnAsync(TParamIn message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 带返回发送数据
|
/// 带返回发送数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">需要发送的数据</param>
|
/// <param name="message">需要发送的数据</param>
|
||||||
/// <returns>是否发送成功</returns>
|
/// <returns>是否发送成功</returns>
|
||||||
public abstract byte[] SendMsg(byte[] message);
|
public abstract TParamOut SendMsg(TParamIn message);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 带返回发送数据
|
/// 带返回发送数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="message">需要发送的数据</param>
|
/// <param name="message">需要发送的数据</param>
|
||||||
/// <returns>是否发送成功</returns>
|
/// <returns>是否发送成功</returns>
|
||||||
public abstract Task<byte[]> SendMsgAsync(byte[] message);
|
public abstract Task<TParamOut> SendMsgAsync(TParamIn message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,8 +594,7 @@ namespace Modbus.Net
|
|||||||
if (BaseUtility is TUtilityMethod)
|
if (BaseUtility is TUtilityMethod)
|
||||||
{
|
{
|
||||||
Type t = typeof(TUtilityMethod);
|
Type t = typeof(TUtilityMethod);
|
||||||
object returnValue = t.GetMethod(methodName,
|
object returnValue = t.GetRuntimeMethod(methodName, parameters.Select(p => p.GetType()).ToArray())
|
||||||
BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
|
|
||||||
.Invoke(BaseUtility, parameters);
|
.Invoke(BaseUtility, parameters);
|
||||||
return (TReturnType) returnValue;
|
return (TReturnType) returnValue;
|
||||||
}
|
}
|
||||||
@@ -616,8 +615,7 @@ namespace Modbus.Net
|
|||||||
if (this is TMachineMethod)
|
if (this is TMachineMethod)
|
||||||
{
|
{
|
||||||
Type t = typeof(TMachineMethod);
|
Type t = typeof(TMachineMethod);
|
||||||
object returnValue = t.GetMethod(methodName,
|
object returnValue = t.GetRuntimeMethod(methodName, parameters.Select(p => p.GetType()).ToArray())
|
||||||
BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
|
|
||||||
.Invoke(this, parameters);
|
.Invoke(this, parameters);
|
||||||
return (TReturnType) returnValue;
|
return (TReturnType) returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Modbus.Net.Tests
|
|||||||
{
|
{
|
||||||
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
BaseMachine<int, int> baseMachine = new ModbusMachine<int, int>(ModbusType.Tcp, "192.168.3.12", null, true, 2, 0);
|
||||||
var utility = baseMachine.GetUtility<IUtilityTime>();
|
var utility = baseMachine.GetUtility<IUtilityTime>();
|
||||||
var methods = utility.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
var methods = utility.GetType().GetRuntimeMethods();
|
||||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetTimeAsync") != null, true);
|
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "GetTimeAsync") != null, true);
|
||||||
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "SetTimeAsync") != null, true);
|
Assert.AreEqual(methods.FirstOrDefault(method => method.Name == "SetTimeAsync") != null, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user