ModbusMaster  v2.0.1
Arduino library for communicating with Modbus slaves over RS232/485 (via RTU protocol).
ModbusMaster Object Instantiation/Initialization

Functions

 ModbusMaster::ModbusMaster ()
 Constructor. More...
 
void ModbusMaster::begin (uint8_t, Stream &serial)
 Initialize class object. More...
 

Detailed Description

Function Documentation

§ ModbusMaster()

ModbusMaster::ModbusMaster ( void  )

Constructor.

Creates class object; initialize it using ModbusMaster::begin().

45 {
46  _idle = 0;
47  _preTransmission = 0;
48  _postTransmission = 0;
49 }

§ begin()

void ModbusMaster::begin ( uint8_t  slave,
Stream &  serial 
)

Initialize class object.

Assigns the Modbus slave ID and serial port. Call once class has been instantiated, typically within setup().

Parameters
slaveModbus slave ID (1..255)
&serialreference to serial port object (Serial, Serial1, ... Serial3)
Examples:
examples/Basic/Basic.pde, examples/PhoenixContact_nanoLC/PhoenixContact_nanoLC.pde, and examples/RS485_HalfDuplex/RS485_HalfDuplex.ino.
62 {
63 // txBuffer = (uint16_t*) calloc(ku8MaxBufferSize, sizeof(uint16_t));
64  _u8MBSlave = slave;
65  _serial = &serial;
66  _u8TransmitBufferIndex = 0;
67  u16TransmitBufferLength = 0;
68 
69 #if __MODBUSMASTER_DEBUG__
70  pinMode(__MODBUSMASTER_DEBUG_PIN_A__, OUTPUT);
71  pinMode(__MODBUSMASTER_DEBUG_PIN_B__, OUTPUT);
72 #endif
73 }
Stream * _serial
reference to serial port object
Definition: ModbusMaster.h:221
uint8_t _u8MBSlave
Modbus slave (1..255) initialized in begin()
Definition: ModbusMaster.h:222