Skip to main content

ModbusError

Enum ModbusError 

Source
pub enum ModbusError {
Show 18 variants BroadcastUnit, ReservedUnit { unit: u8, }, EmptyRead, TooManyRegisters { count: u16, max: u16, }, PastEndOfAddressSpace { start: u16, count: u16, }, TooShort { expected: usize, found: usize, }, ProtocolId { found: u16, }, LengthOutOfRange { declared: u16, min: u16, max: u16, }, LengthMismatch { declared: u16, found: u16, }, TransactionMismatch { expected: u16, found: u16, }, UnitMismatch { expected: u8, found: u8, }, FunctionMismatch { expected: u8, found: u8, }, Exception { function: u8, code: ExceptionCode, }, ByteCountMismatch { declared: u16, expected: u16, }, InconsistentLength { declared: u16, byte_count: u8, }, WordCount { kind: &'static str, expected: u16, found: usize, }, NonFiniteScale, ZeroScale,
}
Expand description

What a Modbus read refuses, on the way out and on the way back.

Every variant names what was expected beside what was found, because the reader of this error is an operator holding a register map and a device manual, and “length mismatch” alone sends them to a packet capture.

Variants§

§

BroadcastUnit

Unit id 0 is a broadcast. No device answers a broadcast read.

§

ReservedUnit

Unit ids 248 to 254 are reserved by the specification.

Fields

§unit: u8

The reserved unit id that was refused.

§

EmptyRead

A read of zero registers asks a device for nothing.

§

TooManyRegisters

Function codes 3 and 4 answer at most MAX_REGISTERS words.

Fields

§count: u16

How many registers were asked for.

§max: u16

The protocol ceiling for this function code.

§

PastEndOfAddressSpace

The last register asked for sits past address 65 535.

Fields

§start: u16

Where the read started.

§count: u16

How many registers were asked for.

§

TooShort

The byte slice is shorter than a Modbus TCP reply needs.

Fields

§expected: usize

How many bytes this step needed.

§found: usize

How many bytes were present.

§

ProtocolId

The protocol id is not zero, so the frame is not Modbus.

Fields

§found: u16

The protocol id the frame carried.

§

LengthOutOfRange

The length field is outside what a Modbus TCP frame can carry.

Fields

§declared: u16

The length field from the header.

§min: u16

The smallest legal length.

§max: u16

The largest legal length.

§

LengthMismatch

The length field does not match the bytes that follow it.

Fields

§declared: u16

The length field from the header.

§found: u16

How many bytes followed the header.

§

TransactionMismatch

The reply echoed a different transaction id than this read used.

Fields

§expected: u16

The transaction id this read used.

§found: u16

The transaction id the reply echoed.

§

UnitMismatch

The reply came from a different unit than this read addressed.

Fields

§expected: u8

The unit id this read addressed.

§found: u8

The unit id the reply named.

§

FunctionMismatch

The reply carried a function code this read did not use.

Fields

§expected: u8

The function code this read used.

§found: u8

The function code the reply carried.

§

Exception

The device refused the read and named a reason.

Fields

§function: u8

The function code that was refused.

§code: ExceptionCode

The reason the device gave.

§

ByteCountMismatch

The reply’s byte count is not twice the register count that was asked.

Fields

§declared: u16

The byte count the reply declared.

§expected: u16

The byte count this read is owed.

§

InconsistentLength

The header length and the PDU byte count do not describe the same body.

Fields

§declared: u16

The length field from the header.

§byte_count: u8

The byte-count field from the PDU.

§

WordCount

A decoder was handed the wrong number of 16-bit words.

Fields

§kind: &'static str

The decoder’s name.

§expected: u16

How many words that decoder needs.

§found: usize

How many words were supplied.

§

NonFiniteScale

A scale factor must be a finite number.

§

ZeroScale

A scale of zero would turn every register into nothing.

Trait Implementations§

Source§

impl Clone for ModbusError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ModbusError

Source§

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

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

impl Display for ModbusError

Source§

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

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

impl Eq for ModbusError

Source§

impl Error for ModbusError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ModbusError> for ExchangeError

Source§

fn from(source: ModbusError) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ModbusError

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ModbusError

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.