CZ 6 months ago
parent 8a3286edc0
commit fadf539aee

@ -11,9 +11,6 @@ public static class ModbusDecoder
public static T Decode<T>(byte[] bytes, T t) where T : class, new() public static T Decode<T>(byte[] bytes, T t) where T : class, new()
{ {
try
{
List<object?> fields = t.GetType().GetProperties() List<object?> fields = t.GetType().GetProperties()
.Where(it => it.PropertyType.GetGenericTypeDefinition() == typeof(ModbusProperty<>)) .Where(it => it.PropertyType.GetGenericTypeDefinition() == typeof(ModbusProperty<>))
.Select(p => p.GetValue(t)).ToList(); .Select(p => p.GetValue(t)).ToList();
@ -77,46 +74,41 @@ public static class ModbusDecoder
case ModbusProperty<ushort> ushortProperty: case ModbusProperty<ushort> ushortProperty:
{ {
SetPropertyValue(startRegisterNo, ushortProperty, decodeUseBytes); SetPropertyValue(startRegisterNo, ushortProperty, decodeUseBytes);
// SetPropertyValue(ushortProperty.RegisterNo, ushortProperty, decodeUseBytes); // SetPropertyValue(ushortProperty.RegisterNo, ushortProperty, decodeUseBytes);
break; break;
} }
case ModbusProperty<int> intProperty: case ModbusProperty<int> intProperty:
{ {
SetPropertyValue(startRegisterNo, intProperty, decodeUseBytes); SetPropertyValue(startRegisterNo, intProperty, decodeUseBytes);
// SetPropertyValue(intProperty.RegisterNo, intProperty, decodeUseBytes); // SetPropertyValue(intProperty.RegisterNo, intProperty, decodeUseBytes);
break; break;
} }
case ModbusProperty<uint> uintProperty: case ModbusProperty<uint> uintProperty:
{ {
SetPropertyValue(startRegisterNo, uintProperty, decodeUseBytes); SetPropertyValue(startRegisterNo, uintProperty, decodeUseBytes);
// SetPropertyValue(uintProperty.RegisterNo, uintProperty, decodeUseBytes); // SetPropertyValue(uintProperty.RegisterNo, uintProperty, decodeUseBytes);
break; break;
} }
case ModbusProperty<float> floatProperty: case ModbusProperty<float> floatProperty:
{ {
SetPropertyValue(startRegisterNo, floatProperty, decodeUseBytes); SetPropertyValue(startRegisterNo, floatProperty, decodeUseBytes);
// SetPropertyValue(floatProperty.RegisterNo, floatProperty, decodeUseBytes); // SetPropertyValue(floatProperty.RegisterNo, floatProperty, decodeUseBytes);
break; break;
} }
case ModbusProperty<double> doubleProperty: case ModbusProperty<double> doubleProperty:
{ {
SetPropertyValue(startRegisterNo, doubleProperty, decodeUseBytes); SetPropertyValue(startRegisterNo, doubleProperty, decodeUseBytes);
// SetPropertyValue(doubleProperty.RegisterNo, doubleProperty, decodeUseBytes); // SetPropertyValue(doubleProperty.RegisterNo, doubleProperty, decodeUseBytes);
break; break;
} }
case ModbusProperty<string> stringProperty: case ModbusProperty<string> stringProperty:
{ {
SetPropertyValue(startRegisterNo, stringProperty, decodeUseBytes); SetPropertyValue(startRegisterNo, stringProperty, decodeUseBytes);
// SetPropertyValue(stringProperty.RegisterNo, stringProperty, decodeUseBytes); // SetPropertyValue(stringProperty.RegisterNo, stringProperty, decodeUseBytes);
break; break;
} }
} }
}
}
catch (Exception ex)
{
} }
return t; return t;
} }

Loading…
Cancel
Save