pub struct CustomFunctionCode {
pub fc: u8,
pub predict_request_length: Arc<dyn Fn(&[u8]) -> CustomFcPredict + Send + Sync + 'static>,
pub predict_response_length: Arc<dyn Fn(&[u8]) -> CustomFcPredict + Send + Sync + 'static>,
pub handle: Option<CustomFcHandler>,
}Expand description
Defines a non-standard / user-defined Modbus function code. Mirrors
njs-modbus CustomFunctionCode.
Registration paths:
crate::layers::application::RtuApplicationLayer::add_custom_function_code— framing only.crate::slave::ModbusSlave::add_custom_function_code— framing + slave-side dispatch.crate::master::ModbusMaster::add_custom_function_code+send_custom_fc— framing + request issuance.
The two predict_* callbacks declare how to derive the total RTU frame
length (PDU + 2-byte CRC) from leading bytes; they are required so the
framing FSM can advance without the deleted sliding-window CRC fallback.
Fields§
§fc: u8Function code value (must fit in u8).
predict_request_length: Arc<dyn Fn(&[u8]) -> CustomFcPredict + Send + Sync + 'static>Predict total RTU frame length for an incoming request (slave-side framing).
predict_response_length: Arc<dyn Fn(&[u8]) -> CustomFcPredict + Send + Sync + 'static>Predict total RTU frame length for an incoming response (master-side framing).
handle: Option<CustomFcHandler>Slave-side handler. Returning Err is turned into a Modbus exception
response by the slave. If handle is None, the slave returns an
ILLEGAL_FUNCTION exception for this FC.
Trait Implementations§
Source§impl Clone for CustomFunctionCode
impl Clone for CustomFunctionCode
Source§fn clone(&self) -> CustomFunctionCode
fn clone(&self) -> CustomFunctionCode
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CustomFunctionCode
impl !RefUnwindSafe for CustomFunctionCode
impl Send for CustomFunctionCode
impl Sync for CustomFunctionCode
impl Unpin for CustomFunctionCode
impl UnsafeUnpin for CustomFunctionCode
impl !UnwindSafe for CustomFunctionCode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more