[][src]Function libmodbus::get_byte_from_bits

pub fn get_byte_from_bits(src: &[u8], index: u8, num_bit: u16) -> u8

get_byte_from_bits - get the value from many bit

The get_byte_from_bits() function shall extract a value from many bits. All num_bit bits from src at position index will be read as a single value. To obtain a full byte, set num_bit to 8.

Return value

The function shall return a byte containing the bits read.

Parameters

  • src - bits source
  • index - starting position where the bit will be read
  • num_bit - All num_bit bits from src at position index will be read as a single value. To obtain a full byte, set num_bit to 8.

Examples

use libmodbus::{Modbus, ModbusMapping, ModbusTCP};
use libmodbus::prelude::*;
let modbus = Modbus::new_tcp("127.0.0.1", 1502).unwrap();
let modbus_mapping = ModbusMapping::new(5, 5, 5, 5).unwrap();

assert_eq!(get_byte_from_bits(&[0b1111_1111], 0 ,8), 255);