Function libmodbus_rs::prelude::set_bits_from_bytes [] [src]

pub fn set_bits_from_bytes(
    dest: &mut [u8],
    index: u16,
    num_bit: u16,
    bytes: &[u8]
)

set_bits_from_bytes - set many bits from an array of bytes

The set_bits_from_bytes() 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

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_bytes(modbus_mapping.get_input_bits_mut(), 0, 2, &[0b0000_1111]);

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