Skip to content

Latest commit

 

History

History
 
 

RTU

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

This example 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.

Modbus RTU Specific API

bool begin(SoftwareSerial* port, int16_t txEnablePin=-1, bool txEnableDirect=true);
bool begin(HardwareSerial* port, int16_t txEnablePin=-1, bool txEnableDirect=true);
bool begin(Stream* port);
  • port Pointer to Serial port
  • txEnablePin RX/TX control pin. Not assigned (assume auto RX/TX) by default
  • txEnableDirect Direct (true, default) or inverse (false) RX/TX pin control.

Assign Serial port. txEnablePin controls transmit enable for MAX-485.

void setBaudrate(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(); // Deprecated
void master(uint8_t slaveId); // Deprecated
  • 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 unpredictable.

uint8_t client();
uint8_t slave(); // Deprecated
  • Slave mode: Returns configured slave id.
  • Master mode: Returns slave id for active request or 0 if no request in progress.

Modbus Library for Arduino

ModbusRTU, ModbusTCP and ModbusTCP Security

(c)2020 Alexander Emelianov

The code in this repo is licensed under the BSD New License. See LICENSE.txt for more info.