modbus_get_byte_from_bits


 

Function

 

Converts bit information to byte information.

 

Format

 

ret = modbus_get_byte_from_bits( src , index , nb_bits )

 

Parameters

 

src [ C : uint8_t * ] [ Python : ctypes.POINTER(ctypes.c_uint8) ]

Specify the start address of the array that has stored the bit data which is to be converted to bytes.

 

index [ C : int ] [ Python : ctypes.c_int ]

Specify the position to start byte conversion in the src array.

 

nb [ C : uint ] [ Python : ctypes.c_uint ]

Specify the number of bits to convert.

 

Return values

 

ret [ C : uint8_t ] [ Python : ctypes.c_uint8 ]

 

If the function succeeds, the byte conversion result is returned.

 

Remarks

 

Converts the given bit information to byte information.

 

Example

 

Converts the bit array [0, 1, 0, 1] to byte information (10).

 

C

uint8_t ret;

uint8_t src[] = { 0, 1, 0, 1 };

ret = modbus_get_byte_from_bits( src, 0, 4 );

 

Python

ret = ctypes.c_uint8

uint8_buff_type = ctypes.c_uint8 * 4

src = uint8_buff_type()

src[0], src[1], src[2], src[3] = (0, 1, 0, 1)

ret = modbus.modbus_get_byte_from_bits(src, 0, 4)