Skip to content

Decode 8 bit not possible #2668

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

Closed
hasenradball opened this issue May 14, 2025 · 8 comments
Closed

Decode 8 bit not possible #2668

hasenradball opened this issue May 14, 2025 · 8 comments

Comments

@hasenradball
Copy link

Dear pymodbus team,

with version 3.6.6 it was possible to decode 8 bit values.
But with version 3.9.2 this is no possible anymore, because the DATATYPE.UINT8 and DATATYPE.INT8 are missing.

Could you provide also these datatypes for backward compatiliby?

I used the following function:

def decode_register_readings(self, readings, datatype, count) -> list:
        """Decode the register readings 
        
        Decode readings depending on datatype given
        -----
        Args:
            readings: dats read from register
            datatype: U16, U32 , etc...
            count: number of datatypes to be converted
        
        Returns:
            data: list of decoded values
        """
        decoder = BinaryPayloadDecoder.fromRegisters(readings.registers, \
            byteorder=Endian.BIG, wordorder=Endian.BIG)
        #print(f'decoder : {decoder}')
        data = []
        if datatype == 'U8':
            data = [decoder.decode_8bit_uint() for i in range(count)]
        elif datatype == 'U16':
            data = [decoder.decode_16bit_uint() for i in range(count)]
        elif datatype == 'U32':
            data = [decoder.decode_32bit_uint() for i in range(count)]
        elif datatype == 'U64':
            data = [decoder.decode_64bit_uint() for i in range(count)]
        elif datatype == 'S8':
            data = [decoder.decode_8bit_int() for i in range(count)]
        elif datatype == 'S16':
            data = [decoder.decode_16bit_int() for i in range(count)]
        elif datatype == 'S32':
            data = [decoder.decode_32bit_int() for i in range(count)]
        elif datatype == 'S64':
            data = [decoder.decode_64bit_int() for i in range(count)]
        return data
@janiversen
Copy link
Collaborator

janiversen commented May 14, 2025

Binary payload have not been changed for ages, so if it worked in 3.6.6 it still works.

It is correct that client.fromRegisters (replacement for payload in 4.0) do not have UINT8 and INT8, which is because all modbus data calls deliver minimum 16bit.

DATATYPE is part of client.fromRegisters and not payload, and have never supported 8bit as far as I remember. Your example do not use DATATYPE but only payload, so I do not understand what your problem ?

@hasenradball
Copy link
Author

@janiversen

I got the following warning:

BinaryPayloadDecoder is deprecated and will be removed in v3.9.0 ! Please use "client.convert_from_registers()" or "client.convert_to_registers" See documentation: "https://pymodbus.readthedocs.io/en/latest/source/client.html#pymodbus.client.mixin.ModbusClientMixin.convert_from_registers"

@hasenradball
Copy link
Author

There are some devices on the market which use 8 bit values.

@janiversen
Copy link
Collaborator

that still have nothing to do with missing entries in DATATYPE.

We will not add INT8 and UINT8 as a modbus device cannot return an 8 bit values, so if you need that you have to decode it in the app.

As I wrote payload will be removed in v4.0 we postponed it from v3.9.0, so you have time.

@janiversen
Copy link
Collaborator

How can a modbus device return 8bit, that is really non standard. Modbus devices always return registers which are defined to be 16bit!

@janiversen
Copy link
Collaborator

If you receive a register (16bit) from your device via pymodbus, and for any reason want to split it into 2 bytes, then use the builtin python functions, it really is outside the scope of pymodbus.

@janiversen
Copy link
Collaborator

Closing as this is not a pymodbus problem.

@janiversen janiversen closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2025
@hasenradball
Copy link
Author

Ok Thank you for the feedback.

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

2 participants