pub enum Request<'a> {
ReadCoils {
start: u16,
quantity: u16,
},
ReadDiscreteInputs {
start: u16,
quantity: u16,
},
ReadHoldingRegisters {
start: u16,
quantity: u16,
},
ReadInputRegisters {
start: u16,
quantity: u16,
},
WriteSingleCoil {
address: u16,
on: bool,
},
WriteSingleRegister {
address: u16,
value: u16,
},
WriteMultipleCoils {
start: u16,
values: Coils<'a>,
},
WriteMultipleRegisters {
start: u16,
values: Registers<'a>,
},
}Expand description
A request as a device reads it, checked against the limits the specification sets.
parse follows the order of the specification’s state diagrams: a
function the device does not serve is refused with
IllegalFunction, and a quantity, a byte count, or a coil
value outside what the function allows with IllegalDataValue.
Whether the addresses exist is the device’s own question, answered with
IllegalDataAddress once the request has parsed.
§Examples
use pamoja_modbus::{Exception, Pdu, Request};
let pdu = Pdu::read_holding_registers(0x006B, 3);
assert_eq!(
Request::parse(pdu.as_bytes()),
Ok(Request::ReadHoldingRegisters { start: 0x006B, quantity: 3 })
);
// 126 registers is one more than a reply can carry.
let greedy = Pdu::read_holding_registers(0, 126);
assert_eq!(Request::parse(greedy.as_bytes()), Err(Exception::IllegalDataValue));Variants§
ReadCoils
Read coils, function 0x01.
ReadDiscreteInputs
Read discrete inputs, function 0x02.
ReadHoldingRegisters
Read holding registers, function 0x03.
ReadInputRegisters
Read input registers, function 0x04.
WriteSingleCoil
Write one coil, function 0x05.
WriteSingleRegister
Write one holding register, function 0x06.
WriteMultipleCoils
Write a run of coils, function 0x0F.
Fields
WriteMultipleRegisters
Write a run of holding registers, function 0x10.
Implementations§
Source§impl<'a> Request<'a>
impl<'a> Request<'a>
Sourcepub fn parse(pdu: &'a [u8]) -> Result<Request<'a>, Exception>
pub fn parse(pdu: &'a [u8]) -> Result<Request<'a>, Exception>
Reads a request PDU, checking it the way the specification’s state diagrams do.
§Arguments
pdu- the request: a function code followed by its data.
§Returns
The request.
§Errors
Exception::IllegalFunction for an empty PDU or a function this type does not
name, and Exception::IllegalDataValue for a PDU too short for its function, a
quantity outside the function’s range, a byte count that does not match the
quantity, or a single coil written with anything but 0x0000 or 0xFF00.