This example is introduces how to use the library for ModbusRTU (typicaly over RS-485) to act as master or slave. Additionally there is example of master device for multithread usage with ESP32.
bool begin(SoftwareSerial* port, int16_t txPin=-1, bool direct=true);
bool begin(HardwareSerial* port, int16_t txPin=-1, bool direct=true);
bool begin(Stream* port);
port
Pointer to Serial porttxPin
RX/TX control pin. Not assigned (assume auto RX/TX) by defaultdirect
Direct (true, default) or inverse (false) RX/TX pin control.
Assing Serial port. txPin controls transmit enable for MAX-485.
void setBaudrte(uint32 baud);
baud
New baudrate.
Set or override Serial baudrate. Must be called after .begin() for Non-ESP devices.
void client();
void server(uint8_t slaveId);
void slave(); // Depricated
void master(uint8_t slaveId); // Depricated
slaveId
Modbus slave id to associate to.
Select and initialize master or slave mode to work. Switching between modes is not supported. Call is not returning error in this case but behaviour is unpredictible.
uint8_t client();
uint8_t slave(); // Depricated
- Slave mode: Returns configured slave id.
- Master mode: Returns slave id for active request or 0 if no request in-progress.
(c)2020 Alexander Emelianov
The code in this repo is licensed under the BSD New License. See LICENSE.txt for more info.