Modbus-Serial
ModbusSerial

Modbus over serial line Class. More...

Inherits Modbus.

Public Member Functions

 ModbusSerial (Stream &port, byte slaveId, int txenPin=-1)
 Constructor. More...
 
void config (unsigned long baud)
 Configure ModbusSerial object. More...
 
void task ()
 Task that performs all operations on MODBUS. More...
 
void setSlaveId (byte slaveId)
 Change the value of slave identifier. More...
 
byte getSlaveId ()
 Return slave identifier.
 

Static Public Attributes

static const byte BroadcastAddress = 0
 Broadcast address.
 

Detailed Description

Modbus over serial line Class.

Constructor & Destructor Documentation

◆ ModbusSerial()

ModbusSerial::ModbusSerial ( Stream &  port,
byte  slaveId,
int  txenPin = -1 
)

Constructor.

Parameters
portserial port to use
txenPinif an RS485 circuit is used, this corresponds to the pin number connected to the transmit enable (DE) and receive disable (/RE) pin. -1 if not used.

Member Function Documentation

◆ config()

void ModbusSerial::config ( unsigned long  baud)

Configure ModbusSerial object.

configures txenPin on output if necessary and calculates the times of the RTU frame.

Warning
the begin() function of the serial port passed to the constructor must be called BEFORE calling this function.
Parameters
baudbaudrate in accordance with that used by the serial port

◆ setSlaveId()

void ModbusSerial::setSlaveId ( byte  slaveId)

Change the value of slave identifier.

Parameters
slaveIdidentifier 1-247

◆ task()

void ModbusSerial::task ( )

Task that performs all operations on MODBUS.

Call once inside loop(), all magic here !