pub fn get_quantity(
function_code: u8,
request: &[u8],
) -> Result<u16, RelayError>Expand description
Extracts the quantity of coils or registers from a Modbus RTU request frame based on the function code.
This function determines the quantity of coils or registers involved in a Modbus RTU request by examining the function code and extracting the appropriate bytes from the request frame. For read functions (0x01 to 0x04) and write multiple functions (0x0F, 0x10), it extracts a 16-bit unsigned integer from bytes 4 and 5 of the request frame. For write single functions (0x05, 0x06), it returns a fixed quantity of 1. For other function codes, it defaults to a quantity of 1.
§Arguments
function_code- The Modbus function code.request- A slice of bytes representing the Modbus RTU request frame.
§Returns
A Result containing the extracted quantity as a u16 value if successful, or a RelayError if the request
slice is too short or the function code is invalid.
§Errors
Returns a RelayError with FrameErrorKind::InvalidFormat if the request slice does not contain
enough bytes to extract the quantity for the specified function code.