Skip to content

Add "scalar" float to mb_parameter_opt_t struct (IDFGH-14796) #102

@OllieKrause

Description

@OllieKrause

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Described the feature in detail and justified the reason for the request.
  • Provided specific use cases and examples.

Feature description

Many of the Modbus registers I am reading need to be multiplied by a specified scaling factor to determine their true value. For example, 0x0050 holds an input voltage but its raw value is in decivolts and thus must be multiplied by a 0.1 scaling factor to convert back to volts (see attached image). It seems the most logical place to include this scaling factor would be as a new float within the mb_parameter_opt_t struct (this would represent opt4).

Image

Use cases

Often values like voltage (eg. 12.56V) are stored as unsigned integers multiplied by some scaling factor specified in the datasheet. The useful value is obtained by multiplying the raw value at the register address by this scaling factor. See the attached datasheet for a meanwell NTN-5K inverter.

Mean Well NTN-5K-E Manual.pdf

Alternatives

I have considered solving this problem by defining a new struct extended_mb_parameter_descriptor_t that appends the scaling factor.

typedef struct { mb_parameter_descriptor_t base; float scale_factor; } extended_mb_parameter_descriptor_t;

This isn't exactly a clean solution though.

Additional context

I'm fairly new to modbus so please forgive me if there is a easier solution to this issue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions