modbus-arduino  1.0.0
Modbus library for Arduino
ModbusSerial Class Reference

Modbus over serial line Class. More...

#include <ModbusSerial.h>

Inheritance diagram for ModbusSerial:
Inheritance graph

Public Member Functions

bool config (HardwareSerial *port, long baud, byte parity=MB_PARITY_EVEN, int txenPin=-1)
 Connect an ModbusSerial object to a hardware serial port. More...
 
bool config (SoftwareSerial *port, long baud, int txenPin=-1)
 Connect an ModbusSerial object to a software serial port. More...
 
bool config (Serial_ *port, long baud, byte parity=MB_PARITY_EVEN, int txenPin=-1)
 Connect an ModbusSerial object to a hardware serial port Variant in the case of an ATMEGA32U4 (Leonardo). More...
 
byte getSlaveId ()
 Return slave identifier. More...
 
 ModbusSerial ()
 Default constructor. More...
 
bool setSlaveId (byte slaveId)
 Change the value of slave identifier. More...
 
void task ()
 Task that performs all operations on MODBUS. More...
 
- Public Member Functions inherited from Modbus
void addCoil (word offset, bool value=false)
 Add a coil. More...
 
void addHreg (word offset, word value=0)
 Add a holding register to the list. More...
 
void addIreg (word offset, word value=0)
 Add a input register. More...
 
void addIsts (word offset, bool value=false)
 Add a discrete input. More...
 
bool Coil (word offset, bool value)
 Change the value of a coil This value will be returned when bus read, the master can also modify it. More...
 
bool Coil (word offset)
 Return the value of a coil. More...
 
bool Hreg (word offset, word value)
 Change the value of a holding register This value will be returned when bus read, the master can also modify it. More...
 
word Hreg (word offset)
 Return the value of a holding register. More...
 
bool Ireg (word offset, word value)
 Change the value of an input register This value will be returned when bus read. More...
 
word Ireg (word offset)
 Return the value of an input register. More...
 
bool Ists (word offset, bool value)
 Change the value of a discrete input This value will be returned when bus read,. More...
 
bool Ists (word offset)
 Return the value of a discrete input. More...
 
 Modbus ()
 Default constructor. More...
 

Protected Member Functions

bool receive (byte *frame)
 
bool send (byte *frame)
 
bool sendPDU (byte *pduframe)
 

Detailed Description

Modbus over serial line Class.

Definition at line 54 of file ModbusSerial.h.

Constructor & Destructor Documentation

ModbusSerial::ModbusSerial ( )

Default constructor.

Member Function Documentation

bool ModbusSerial::config ( HardwareSerial *  port,
long  baud,
byte  parity = MB_PARITY_EVEN,
int  txenPin = -1 
)

Connect an ModbusSerial object to a hardware serial port.

Parameters
portpointer on serial port to use, &Serial most of the time, or &Serial1, &Serial2 ... if available
baudbaudrate
parityparity
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.
Returns
true, false if error occured
bool ModbusSerial::config ( SoftwareSerial *  port,
long  baud,
int  txenPin = -1 
)

Connect an ModbusSerial object to a software serial port.

Warning
The SoftwareSerial use 8N1 format, this does not respect the MODBUS RTU specifications (2 stop bits if no parity)...
Parameters
portpointer on serial port to use
baudbaudrate
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.
Returns
true, false if error occured
bool ModbusSerial::config ( Serial_ *  port,
long  baud,
byte  parity = MB_PARITY_EVEN,
int  txenPin = -1 
)

Connect an ModbusSerial object to a hardware serial port Variant in the case of an ATMEGA32U4 (Leonardo).

Parameters
portpointer on serial port to use, &Serial most of the time, or &Serial1, &Serial2 ... if available
baudbaudrate
parityparity
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.
Returns
true, false if error occured
byte ModbusSerial::getSlaveId ( )

Return slave identifier.

bool ModbusSerial::receive ( byte *  frame)
protected
bool ModbusSerial::send ( byte *  frame)
protected
bool ModbusSerial::sendPDU ( byte *  pduframe)
protected
bool ModbusSerial::setSlaveId ( byte  slaveId)

Change the value of slave identifier.

Parameters
slaveIdidentifier 1-247
Returns
true, false if error occured
void ModbusSerial::task ( )

Task that performs all operations on MODBUS.

Call once inside loop(), all magic here !