Exception

Enum Exception 

Source
#[repr(u8)]
pub enum Exception { Undefined(u8), IllegalFunction = 1, IllegalDataAddress = 2, IllegalDataValue = 3, DeviceFailure = 4, Acknowledge = 5, DeviceBusy = 6, MemoryParityError = 8, GatewayPathUnavailable = 10, GatewayTargetDeviceFailedToRespond = 11, }
Expand description

Enumerates the Modbus application exceptions returned by a slave device, including a catch-all for codes not defined by the specification.

Variants§

§

Undefined(u8)

Exception code not defined by this crate; preserves the raw value for diagnostics.

§

IllegalFunction = 1

Exception code 0x01: the function is not supported or the device state does not allow the requested operation (for example an unconfigured unit asked to return registers).

§

IllegalDataAddress = 2

Exception code 0x02: the combination of starting address and length extends beyond the valid data range implemented by the device.

§

IllegalDataValue = 3

Exception code 0x03: a value in the request payload is not acceptable to the device, or the payload structure is inconsistent (for example an incorrect implied length).

§

DeviceFailure = 4

Exception code 0x04: an unrecoverable fault occurred while the device attempted the requested action.

§

Acknowledge = 5

Exception code 0x05: the device accepted the request but needs a long interval to finish; the client should poll later (e.g., Poll Program Complete).

§

DeviceBusy = 6

Exception code 0x06: the device is busy processing a long-duration command and cannot handle the new request yet; the client should retry later.

§

MemoryParityError = 8

Exception code 0x08: while accessing extended file records (function codes 20/21, reference type 6) the device detected a memory parity error.

§

GatewayPathUnavailable = 10

Exception code 0x0A: a gateway could not allocate an internal path between the input and output ports, often due to misconfiguration or overload.

§

GatewayTargetDeviceFailedToRespond = 11

Exception code 0x0B: a gateway forwarded the request but received no response from the target device, which may be offline or unreachable.

Implementations§

Source§

impl Exception

Source

pub const fn as_code(&self) -> u8

Returns the Modbus exception code associated with this variant.

§Examples
use modbus_rtu::Exception;

assert_eq!(Exception::Undefined(0x7F).as_code(), 0x7F);
assert_eq!(Exception::IllegalDataAddress.as_code(), 0x02);
assert_eq!(Exception::DeviceBusy.as_code(), 0x06);
Source

pub fn from_code(code: u8) -> Self

Converts a Modbus exception code into its corresponding Exception variant. Undefined codes are wrapped in Exception::Undefined.

§Examples
use modbus_rtu::Exception;

assert_eq!(Exception::from_code(0x05), Exception::Acknowledge);
assert_eq!(Exception::from_code(0xFF), Exception::Undefined(0xFF));

Trait Implementations§

Source§

impl Clone for Exception

Source§

fn clone(&self) -> Exception

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 Exception

Source§

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

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

impl Display for Exception

Source§

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

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

impl PartialEq for Exception

Source§

fn eq(&self, other: &Exception) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Exception

Source§

impl Eq for Exception

Source§

impl StructuralPartialEq for Exception

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.