Skip to content

Latest commit

 

History

History
 
 

RTU

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

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.

Modbus RTU Specific API

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 port
  • txPin RX/TX control pin. Not assigned (assume auto RX/TX) by default
  • direct 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.

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.