Enum modbus_rtu::packet::Request

source ·
pub enum Request {
    ReadCoils {
        slave: u8,
        base_address: u16,
        quantity: u16,
    },
    ReadDiscreteInputs {
        slave: u8,
        base_address: u16,
        quantity: u16,
    },
    ReadHoldingRegisters {
        slave: u8,
        base_address: u16,
        quantity: u16,
    },
    ReadInputRegisters {
        slave: u8,
        base_address: u16,
        quantity: u16,
    },
    WriteSingleCoil {
        slave: u8,
        address: u16,
        data: bool,
    },
    WriteSingleRegister {
        slave: u8,
        address: u16,
        data: u16,
    },
    WriteMultipleCoils {
        slave: u8,
        base_address: u16,
        data: Vec<bool>,
    },
    WriteMultipleRegisters {
        slave: u8,
        base_address: u16,
        data: Vec<u16>,
    },
    MaskWriteRegister {
        slave: u8,
        address: u16,
        and_mask: u16,
        or_mask: u16,
    },
    ReadWriteMultipleRegisters {
        slave: u8,
        read_base_address: u16,
        read_quantity: u16,
        write_base_address: u16,
        data: Vec<u16>,
    },
}
Expand description

§Request

Modbus RTU request packet variants.

Variants§

§

ReadCoils

§ReadCoils (0x01)

Request to read multiple coils. A coil is a single-bit memory that the master can read and write.

  • slave: Address of the target device. It must not be zero.
  • base_address: Base coil address to start reading. base_address + quantity - 1 must not exceed 0xFFFF.
  • quantity: Number of coils to read. It must be less than or equal to 255 due to the response byte counter being 8-bit.

Fields

§slave: u8
§base_address: u16
§quantity: u16
§

ReadDiscreteInputs

§ReadDiscreteInputs (0x02)

Request to read multiple discrete inputs. A discrete input is a single-bit memory that the master can only read.

  • slave: Address of the target device. It must not be zero.
  • base_address: Base discrete input address to start reading. base_address + quantity - 1 must not exceed 0xFFFF.
  • quantity: Number of discrete inputs to read. It must be less than or equal to 255 due to the response byte counter being 8-bit.

Fields

§slave: u8
§base_address: u16
§quantity: u16
§

ReadHoldingRegisters

§ReadHoldingRegisters (0x03)

Request to read multiple holding registers. A holding register is a 16-bit memory that the master can read and write.

  • slave: Address of the target device. It must not be zero.
  • base_address: Base holding register address to start reading. base_address + quantity - 1 must not exceed 0xFFFF.
  • quantity: Number of holding registers to read. It must be less than or equal to 125 due to the maximum packet size of 256.

Fields

§slave: u8
§base_address: u16
§quantity: u16
§

ReadInputRegisters

§ReadInputRegisters (0x04)

Request to read multiple input registers. An input register is a 16-bit memory that the master can only read.

  • slave: Address of the target device. It must not be zero.
  • base_address: Base input register address to start reading. base_address + quantity - 1 must not exceed 0xFFFF.
  • quantity: Number of input registers to read. It must be less than or equal to 125 due to the maximum packet size of 256.

Fields

§slave: u8
§base_address: u16
§quantity: u16
§

WriteSingleCoil

§WriteSingleCoil (0x05)

Request to write a single coil. A coil is a single-bit memory that the master can read and write.

  • slave: Address of the target device.
  • address: Coil address to write to.
  • data: Data to write. true represents ON, and false represents OFF.

Fields

§slave: u8
§address: u16
§data: bool
§

WriteSingleRegister

§WriteSingleRegister (0x06)

Request to write a single holding register. A holding register is a 16-bit memory that the master can read and write.

  • slave: Address of the target device.
  • address: Holding register address to write to.
  • data: Data to write.

Fields

§slave: u8
§address: u16
§data: u16
§

WriteMultipleCoils

§WriteMultipleCoils (0x0F)

Request to write multiple coils. Coils are single-bit memory that the master can read and write.

  • slave: Address of the target device to write to.
  • base_address: Base coil address to start writing. base_address + length_of_data - 1 must not exceed 0xFFFF.
  • data: Data to write. The length of the data must be less than or equal to 1976 due to the maximum packet size of 256.

Fields

§slave: u8
§base_address: u16
§data: Vec<bool>
§

WriteMultipleRegisters

§WriteMultipleRegisters (0x10)

Request to write multiple holding registers. Holding registers are 16-bit memory that the master can read and write.

  • slave: Address of the target device.
  • base_address: Base holding register address to start writing. base_address + length_of_data - 1 must not exceed 0xFFFF.
  • data: Data to write. The length of the data must be less than or equal to 123 due to the maximum packet size of 256.

Fields

§slave: u8
§base_address: u16
§data: Vec<u16>
§

MaskWriteRegister

§MaskWriteRegister (0x16)

Request to apply AND and OR masks to a single holding register. A holding register is a 16-bit memory that the master can read and write.

  • slave: Address of the target device.
  • address: Holding register address to apply masks to.
  • and_mask: AND mask to apply.
  • or_mask: OR mask to apply.

Fields

§slave: u8
§address: u16
§and_mask: u16
§or_mask: u16
§

ReadWriteMultipleRegisters

§ReadWriteMultipleRegisters (0x17)

Request to write to multiple holding registers and read from multiple holding registers. Holding registers are 16-bit memory that the master can read and write.

  • slave: Address of the target device. It must not be zero.
  • read_base_address: Base holding register address to start reading. read_base_address + read_quantity - 1 must not exceed 0xFFFF.
  • read_quantity: Number of holding registers to read. It must be less than or equal to 125 due to the maximum packet size of 256.
  • write_base_address: Base holding register address to start writing. write_base_address + length_of_data - 1 must not exceed 0xFFFF.
  • data: Data to write. The length of the data must be less than or equal to 121 due to the maximum packet size of 256.

Fields

§slave: u8
§read_base_address: u16
§read_quantity: u16
§write_base_address: u16
§data: Vec<u16>

Implementations§

source§

impl Request

source

pub fn function_code(&self) -> u8

§function_code

Returns the function code that corresponds to the request.

source

pub fn expect_len(&self) -> usize

§expect_len

Return expect response packet size. Note that this size is in case of the slave return successfully. If slave returns expection code, you should expect for 5 bytes.

source

pub fn to_bytes(&self) -> Result<Vec<u8>, RequestError>

§to_byte

Generate actual packet to send

Trait Implementations§

source§

impl Clone for Request

source§

fn clone(&self) -> Request

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Request

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.