Function libmodbus_rs::prelude::set_bits_from_byte [] [src]

pub fn set_bits_from_byte(dest: &mut [u8], index: u32, value: u8)

set_bits_from_byte - set many bits from a single byte value

The set_bits_from_byte() function shall set many bits from a single byte. All 8 bits from the byte value will be written to dest array starting at index position.

Parameters

  • dest - destination slice
  • index - starting position where the bit should written
  • value - set many bits from a single byte. All 8 bits from the byte value will be written to dest slice starting at index position.

Examples

use libmodbus_rs::{Modbus, ModbusMapping, ModbusTCP};
use libmodbus_rs::prelude::*;

let modbus = Modbus::new_tcp("127.0.0.1", 1502).unwrap();
let modbus_mapping = ModbusMapping::new(5, 5, 5, 5).unwrap();
// before
assert_eq!(modbus_mapping.get_input_bits_mut(), [0u8, 0, 0, 0, 0]);

set_bits_from_byte(modbus_mapping.get_input_bits_mut(), 2, 0b1111_1111);

// after
assert_eq!(modbus_mapping.get_input_bits_mut(), [0u8, 0, 1, 1, 1]);