Skip to main content

DiscreteInputResponse

Trait DiscreteInputResponse 

Source
pub trait DiscreteInputResponse {
    // Required methods
    fn read_multiple_discrete_inputs_response(
        &mut self,
        txn_id: u16,
        unit_id_slave_addr: UnitIdOrSlaveAddr,
        discrete_inputs: &DiscreteInputs,
    );
    fn read_single_discrete_input_response(
        &mut self,
        txn_id: u16,
        unit_id_slave_addr: UnitIdOrSlaveAddr,
        address: u16,
        value: bool,
    );
}
Expand description

Defines callbacks for handling responses to Modbus discrete input-related requests.

Implementors of this trait can process the data received from a Modbus server and update their application state accordingly.

§When Each Callback Is Fired

  • read_multiple_discrete_inputs_response: after successful FC 0x02 with quantity > 1.
  • read_single_discrete_input_response: convenience callback when quantity was 1.

§Data Semantics

  • DiscreteInputs stores bit-packed values; use helper methods on the type instead of manually decoding bit offsets in application code.

Required Methods§

Source

fn read_multiple_discrete_inputs_response( &mut self, txn_id: u16, unit_id_slave_addr: UnitIdOrSlaveAddr, discrete_inputs: &DiscreteInputs, )

Handles a response for a Read Discrete Inputs (FC 0x02) request.

§Parameters
  • txn_id: Transaction ID of the original request. While Modbus Serial (RTU/ASCII) does not natively use transaction IDs, the stack preserves the ID provided in the request and returns it here to allow for asynchronous tracking.
  • unit_id_slave_addr: The unit ID of the device that responded.
    • unit_id: if transport is tcp
    • slave_addr: if transport is serial
  • discrete_inputs: A DiscreteInputs struct containing the states of the read inputs.
Source

fn read_single_discrete_input_response( &mut self, txn_id: u16, unit_id_slave_addr: UnitIdOrSlaveAddr, address: u16, value: bool, )

Handles a response for a single discrete input read request.

§Parameters
  • txn_id: Transaction ID of the original request. While Modbus Serial (RTU/ASCII) does not natively use transaction IDs, the stack preserves the ID provided in the request and returns it here to allow for asynchronous tracking.
  • unit_id_slave_addr: The unit ID of the device that responded.
    • unit_id: if transport is tcp
    • slave_addr: if transport is serial
  • address: The address of the input that was read.
  • value: The boolean state of the read input.

Implementors§