Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add combined to/from registers. #2526

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions pymodbus/client/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def convert_from_registers(

:param registers: list of registers received from e.g. read_holding_registers()
:param data_type: data type to convert to
:param word_order: "big"/"little" order of words/registers
:param word_order: "big"/"little" order of words/registers (Only used for special devices)
:returns: scalar or array of "data_type"
:raises ModbusException: when size of registers is not a multiple of data_type
"""
Expand Down Expand Up @@ -742,7 +742,7 @@ def convert_to_registers(

:param value: value to be converted
:param data_type: data type to convert from
:param word_order: "big"/"little" order of words/registers
:param word_order: "big"/"little" order of words/registers (Only used for special devices)
:returns: List of registers, can be used directly in e.g. write_registers()
:raises TypeError: when there is a mismatch between data_type and value
"""
Expand Down Expand Up @@ -771,3 +771,38 @@ def convert_to_registers(
if word_order == "little":
regs.reverse()
return regs

@classmethod
def convert_combined_from_registers(
cls, registers: list[int], data_types: list[tuple[DATATYPE, int]], word_order: Literal["big", "little"] = "big"
) -> list[bool | int | float | str]:
"""Convert registers to int/float/str.

:param registers: list of registers received from e.g. read_holding_registers()
:param data_types: list of (data type, count) to convert to
:param word_order: "big"/"little" order of words/registers (Only used for special devices)
:returns: scalar or array of "data_type"
:raises ModbusException: when size of registers is not a multiple of data_type
"""
_ = registers
_ = data_types
_ = word_order
return [32]


@classmethod
def convert_combined_to_registers(
cls, values: list[bool | int | float | str] , data_types: list[DATATYPE], word_order: Literal["big", "little"] = "big"
) -> list[int]:
"""Convert int/float/str to registers (16/32/64 bit).

:param values: list of values to be converted
:param data_types: list of data types to convert from (Only used for special devices)
:param word_order: "big"/"little" order of words/registers
:returns: List of registers, can be used directly in e.g. write_registers()
:raises TypeError: when there is a mismatch between data_type and value
"""
_ = values
_ = data_types
_ = word_order
return [12]