Skip to main content

ModbusBuilder

Struct ModbusBuilder 

Source
pub struct ModbusBuilder { /* private fields */ }
Expand description

Builder for Modbus packets.

Supports three frame types:

  • TCP (MBAP): Default. Adds a 7-byte MBAP header.
  • RTU: Binary serial framing with CRC-16 appended.
  • ASCII: Hex-encoded with ‘:’ prefix, LRC, and CRLF suffix.

Implementations§

Source§

impl ModbusBuilder

Source

pub fn new() -> Self

Create a new Modbus builder with TCP (MBAP) framing.

Source

pub fn tcp(self) -> Self

Use Modbus/TCP (MBAP) framing (default).

Source

pub fn rtu(self) -> Self

Use Modbus RTU (serial binary) framing.

Source

pub fn ascii(self) -> Self

Use Modbus ASCII (serial hex-encoded) framing.

Source

pub fn trans_id(self, id: u16) -> Self

Set the Transaction ID (MBAP only).

Source

pub fn proto_id(self, id: u16) -> Self

Set the Protocol ID (MBAP only; should be 0x0000).

Source

pub fn unit_id(self, id: u8) -> Self

Set the Unit ID / Slave Address.

Source

pub fn func_code(self, fc: u8) -> Self

Set the Function Code.

Source

pub fn start_addr(self, addr: u16) -> Self

Set the Start Address (for Read/Write requests).

Source

pub fn quantity(self, qty: u16) -> Self

Set the Quantity (for Read requests).

Source

pub fn output_value(self, val: u16) -> Self

Set the Output Value (for Write Single Coil/Register).

Source

pub fn values(self, vals: Vec<u16>) -> Self

Set register values (for Write Multiple Registers).

Source

pub fn coil_values(self, vals: Vec<bool>) -> Self

Set coil values (for Write Multiple Coils).

Source

pub fn sub_func(self, sf: u16) -> Self

Set the Sub-function code (for Diagnostics 0x08).

Source

pub fn and_mask(self, mask: u16) -> Self

Set the AND mask (for Mask Write Register 0x16).

Source

pub fn or_mask(self, mask: u16) -> Self

Set the OR mask (for Mask Write Register 0x16).

Source

pub fn pdu_data(self, data: Vec<u8>) -> Self

Set raw PDU data (after the function code). This overrides the automatic PDU building.

Source

pub fn extra_data(self, data: Vec<u8>) -> Self

Set extra data bytes (for diagnostics data field, etc.).

Source

pub fn header_size(&self) -> usize

Compute the header size for this builder.

Source

pub fn build(&self) -> Vec<u8>

Build the Modbus frame into bytes.

Trait Implementations§

Source§

impl Clone for ModbusBuilder

Source§

fn clone(&self) -> ModbusBuilder

Returns a duplicate 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 ModbusBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ModbusBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl IntoLayerStackEntry for ModbusBuilder

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V