Skip to main content

FunctionCode

Enum FunctionCode 

Source
#[repr(u8)]
pub enum FunctionCode {
Show 20 variants Default = 0, ReadCoils = 1, ReadDiscreteInputs = 2, WriteSingleCoil = 5, WriteMultipleCoils = 15, ReadHoldingRegisters = 3, ReadInputRegisters = 4, WriteSingleRegister = 6, WriteMultipleRegisters = 16, MaskWriteRegister = 22, ReadWriteMultipleRegisters = 23, ReadFifoQueue = 24, ReadFileRecord = 20, WriteFileRecord = 21, ReadExceptionStatus = 7, Diagnostics = 8, GetCommEventCounter = 11, GetCommEventLog = 12, ReportServerId = 17, EncapsulatedInterfaceTransport = 43,
}
Expand description

Modbus Public Function Codes.

These are the standardized function codes defined in the Modbus Application Protocol Specification V1.1b3.

See:

  • Section 5.1 Public Function Code Definition
  • Section 6.x for individual function behaviors

Reference: :contentReference[oaicite:1]{index=1}

Variants§

§

Default = 0

0x00 — Undefined This value is not defined in the specification and can be used as a placeholder for uninitialized or unknown function codes. It is not a valid function code for actual Modbus transactions.

§

ReadCoils = 1

0x01 — Read Coils

Reads the ON/OFF status of discrete output coils. Section 6.1

§

ReadDiscreteInputs = 2

0x02 — Read Discrete Inputs

Reads the ON/OFF status of discrete input contacts. Section 6.2

§

WriteSingleCoil = 5

0x05 — Write Single Coil

Forces a single coil to ON (0xFF00) or OFF (0x0000). Section 6.5

§

WriteMultipleCoils = 15

0x0F — Write Multiple Coils

Forces multiple coils to ON/OFF. Section 6.11

§

ReadHoldingRegisters = 3

0x03 — Read Holding Registers

Reads one or more 16-bit holding registers. Section 6.3

§

ReadInputRegisters = 4

0x04 — Read Input Registers

Reads one or more 16-bit input registers. Section 6.4

§

WriteSingleRegister = 6

0x06 — Write Single Register

Writes a single 16-bit holding register. Section 6.6

§

WriteMultipleRegisters = 16

0x10 — Write Multiple Registers

Writes multiple 16-bit holding registers. Section 6.12

§

MaskWriteRegister = 22

0x16 — Mask Write Register

Performs a bitwise mask write on a single register. Section 6.16

§

ReadWriteMultipleRegisters = 23

0x17 — Read/Write Multiple Registers

Reads and writes multiple registers in a single transaction. Section 6.17

§

ReadFifoQueue = 24

0x18 — Read FIFO Queue

Reads the contents of a FIFO queue. Section 6.18

§

ReadFileRecord = 20

0x14 — Read File Record

Reads structured file records. Section 6.14

§

WriteFileRecord = 21

0x15 — Write File Record

Writes structured file records. Section 6.15

§

ReadExceptionStatus = 7

0x07 — Read Exception Status (Serial Line Only)

Returns 8-bit exception status. Section 6.7

§

Diagnostics = 8

0x08 — Diagnostics (Serial Line Only)

Provides diagnostic and loopback tests. Requires sub-function codes. Section 6.8

§

GetCommEventCounter = 11

0x0B — Get Communication Event Counter (Serial Line Only)

Returns communication event counter. Section 6.9

§

GetCommEventLog = 12

0x0C — Get Communication Event Log (Serial Line Only)

Returns communication event log. Section 6.10

§

ReportServerId = 17

0x11 — Report Server ID (Serial Line Only)

Returns server identification. Section 6.13

§

EncapsulatedInterfaceTransport = 43

0x2B — Encapsulated Interface Transport

Used for:

  • CANopen General Reference (Sub-function 0x0D)
  • Read Device Identification (Sub-function 0x0E)

Section 6.19, 6.20, 6.21

Trait Implementations§

Source§

impl Clone for FunctionCode

Source§

fn clone(&self) -> FunctionCode

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 FunctionCode

Source§

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

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

impl Default for FunctionCode

Source§

fn default() -> FunctionCode

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

impl PartialEq for FunctionCode

Source§

fn eq(&self, other: &FunctionCode) -> 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 TryFrom<u8> for FunctionCode

Source§

type Error = MbusError

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

fn try_from(value: u8) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for FunctionCode

Source§

impl Eq for FunctionCode

Source§

impl StructuralPartialEq for FunctionCode

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, 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.