Skip to content

Decode 8 bit not possible #2668

Closed as not planned
Closed as not planned
@hasenradball

Description

@hasenradball

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions