#[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.
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
impl Exception
Sourcepub const fn as_code(&self) -> u8
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);Sourcepub fn from_code(code: u8) -> Self
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));