[−][src]Trait libmodbus::ModbusServer
The server is waiting for request from clients and must answer when it is concerned by the request. The libmodbus offers the following functions to handle requests:
- Receive
- Reply
Required methods
fn receive(&self, request: &mut [u8]) -> Result<i32, Error>
fn reply(
&self,
request: &[u8],
request_len: i32,
modbus_mapping: &ModbusMapping
) -> Result<i32, Error>
&self,
request: &[u8],
request_len: i32,
modbus_mapping: &ModbusMapping
) -> Result<i32, Error>
Implementors
impl ModbusServer for Modbus
[src]
fn receive(&self, request: &mut [u8]) -> Result<i32, Error>
[src]
receive
- receive an indication request
The receive()
function shall receive an indication request from the socket of the context
ctx.
This function is used by Modbus slave/server to receive and analyze indication request sent by the
masters/clients.
If you need to use another socket or file descriptor than the one defined in the context ctx, see the function
set_socket()
.
Examples
use libmodbus::{Modbus, ModbusServer, ModbusTCP}; let modbus = Modbus::new_tcp("127.0.0.1", 1502).unwrap(); let mut query = vec![0; Modbus::MAX_ADU_LENGTH as usize]; assert!(modbus.receive(&mut query).is_ok());
fn reply(
&self,
request: &[u8],
request_len: i32,
modbus_mapping: &ModbusMapping
) -> Result<i32, Error>
[src]
&self,
request: &[u8],
request_len: i32,
modbus_mapping: &ModbusMapping
) -> Result<i32, Error>
modbus_reply
- send a reponse to the received request
The reply()
function shall send a response to received request. The request req given in
argument is analyzed, a response is then built and sent by using the information of the modbus context ctx.
If the request indicates to read or write a value the operation will done in the modbus mapping mb_mapping
according to the type of the manipulated data.
If an error occurs, an exception response will be sent.
This function is designed for Modbus server.
Examples
use libmodbus::{Modbus, ModbusServer, ModbusTCP}; let modbus = Modbus::new_tcp("127.0.0.1", 1502).unwrap(); let mut query = vec![0; Modbus::MAX_ADU_LENGTH as usize]; assert!(modbus.receive(&mut query).is_ok());