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

modbus little endian #80

Open
patfrench opened this issue Jul 31, 2023 · 0 comments
Open

modbus little endian #80

patfrench opened this issue Jul 31, 2023 · 0 comments

Comments

@patfrench
Copy link

patfrench commented Jul 31, 2023

Description

modbus little endian

Hi,

Your library works perfectly! But I have a device that uses the "little endian byteorder".

How to add :

if lsb_first:
        formatcode = "<" # Little-endian
    else:
        formatcode = ">" # Big-endian

I think I'd have to add a constant for decoding

def read_holding_registers(starting_address: int, quantity: int) -> bytes:
    """
    Create Modbus Protocol Data Unit for reading holding registers.

    :param      starting_address:  The starting address
    :type       starting_address:  int
    :param      quantity:          Quantity of coils
    :type       quantity:          int

    :returns:   Packed Modbus message
    :rtype:     bytes
    """
    if not (1 <= quantity <= 125):
        raise ValueError('Invalid number of holding registers')

    return struct.pack('>BHH',
                       Const.READ_HOLDING_REGISTERS,
                       starting_address,
                       quantity)

I'd like to do it but I'm not sure of my abilities !

Thank you

Reproduction steps

juste a question

MicroPython version

v1.20

MicroPython board

ESP32

MicroPython Modbus version

v2.3.7

Relevant log output

"

User code

"

Additional informations

"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant