This commit is contained in:
parallelbgls
2017-05-19 10:42:40 +08:00
parent 189dff08a7
commit 84e144f15b

View File

@@ -85,13 +85,16 @@ namespace Modbus.Net
{
if (Protocals.ContainsKey(protocalName))
protocalUnitReturn = Protocals[protocalName];
//自动寻找存在的协议并将其加载
var protocalUnit =
Activator.CreateInstance(type.GetTypeInfo().Assembly.GetType(protocalName)) as TProtocalUnit;
if (protocalUnit == null)
throw new InvalidCastException($"No ProtocalUnit {nameof(TProtocalUnit)} implemented");
protocalUnit.Endian = Endian;
Register(protocalUnit);
else
{
//自动寻找存在的协议并将其加载
var protocalUnit =
Activator.CreateInstance(type.GetTypeInfo().Assembly.GetType(protocalName)) as TProtocalUnit;
if (protocalUnit == null)
throw new InvalidCastException($"No ProtocalUnit {nameof(TProtocalUnit)} implemented");
protocalUnit.Endian = Endian;
Register(protocalUnit);
}
}
return protocalUnitReturn ?? Protocals[protocalName];
}