master
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()
{
try
{
List<object?> fields = t.GetType().GetProperties()
.Where(it => it.PropertyType.GetGenericTypeDefinition() == typeof(ModbusProperty<>))
.Select(p => p.GetValue(t)).ToList();
@ -77,46 +74,41 @@ public static class ModbusDecoder
case ModbusProperty<ushort> ushortProperty:
{
SetPropertyValue(startRegisterNo, ushortProperty, decodeUseBytes);
// SetPropertyValue(ushortProperty.RegisterNo, ushortProperty, decodeUseBytes);
// SetPropertyValue(ushortProperty.RegisterNo, ushortProperty, decodeUseBytes);
break;
}
case ModbusProperty<int> intProperty:
{
SetPropertyValue(startRegisterNo, intProperty, decodeUseBytes);
// SetPropertyValue(intProperty.RegisterNo, intProperty, decodeUseBytes);
// SetPropertyValue(intProperty.RegisterNo, intProperty, decodeUseBytes);
break;
}
case ModbusProperty<uint> uintProperty:
{
SetPropertyValue(startRegisterNo, uintProperty, decodeUseBytes);
// SetPropertyValue(uintProperty.RegisterNo, uintProperty, decodeUseBytes);
// SetPropertyValue(uintProperty.RegisterNo, uintProperty, decodeUseBytes);
break;
}
case ModbusProperty<float> floatProperty:
{
SetPropertyValue(startRegisterNo, floatProperty, decodeUseBytes);
// SetPropertyValue(floatProperty.RegisterNo, floatProperty, decodeUseBytes);
// SetPropertyValue(floatProperty.RegisterNo, floatProperty, decodeUseBytes);
break;
}
case ModbusProperty<double> doubleProperty:
{
SetPropertyValue(startRegisterNo, doubleProperty, decodeUseBytes);
// SetPropertyValue(doubleProperty.RegisterNo, doubleProperty, decodeUseBytes);
// SetPropertyValue(doubleProperty.RegisterNo, doubleProperty, decodeUseBytes);
break;
}
case ModbusProperty<string> stringProperty:
{
SetPropertyValue(startRegisterNo, stringProperty, decodeUseBytes);
// SetPropertyValue(stringProperty.RegisterNo, stringProperty, decodeUseBytes);
// SetPropertyValue(stringProperty.RegisterNo, stringProperty, decodeUseBytes);
break;
}
}
}
}
catch (Exception ex)
{
}
return t;
}

Loading…
Cancel
Save