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

Functions

uint16_t ModbusMaster::getResponseBuffer (uint8_t)
 Retrieve data from response buffer. More...
 
void ModbusMaster::clearResponseBuffer ()
 Clear Modbus response buffer. More...
 
uint8_t ModbusMaster::setTransmitBuffer (uint8_t, uint16_t)
 Place data in transmit buffer. More...
 
void ModbusMaster::clearTransmitBuffer ()
 Clear Modbus transmit buffer. More...
 

Detailed Description

Function Documentation

§ getResponseBuffer()

uint16_t ModbusMaster::getResponseBuffer ( uint8_t  u8Index)

Retrieve data from response buffer.

See also
ModbusMaster::clearResponseBuffer()
Parameters
u8Indexindex of response buffer array (0x00..0x3F)
Returns
value in position u8Index of response buffer (0x0000..0xFFFF)
Examples:
examples/Basic/Basic.pde, examples/PhoenixContact_nanoLC/PhoenixContact_nanoLC.pde, and examples/RS485_HalfDuplex/RS485_HalfDuplex.ino.
229 {
230  if (u8Index < ku8MaxBufferSize)
231  {
232  return _u16ResponseBuffer[u8Index];
233  }
234  else
235  {
236  return 0xFFFF;
237  }
238 }
static const uint8_t ku8MaxBufferSize
size of response/transmit buffers
Definition: ModbusMaster.h:223
uint16_t _u16ResponseBuffer[ku8MaxBufferSize]
buffer to store Modbus slave response; read via GetResponseBuffer()
Definition: ModbusMaster.h:226

§ clearResponseBuffer()

void ModbusMaster::clearResponseBuffer ( )

Clear Modbus response buffer.

See also
ModbusMaster::getResponseBuffer(uint8_t u8Index)
248 {
249  uint8_t i;
250 
251  for (i = 0; i < ku8MaxBufferSize; i++)
252  {
253  _u16ResponseBuffer[i] = 0;
254  }
255 }
static const uint8_t ku8MaxBufferSize
size of response/transmit buffers
Definition: ModbusMaster.h:223
uint16_t _u16ResponseBuffer[ku8MaxBufferSize]
buffer to store Modbus slave response; read via GetResponseBuffer()
Definition: ModbusMaster.h:226

§ setTransmitBuffer()

uint8_t ModbusMaster::setTransmitBuffer ( uint8_t  u8Index,
uint16_t  u16Value 
)

Place data in transmit buffer.

See also
ModbusMaster::clearTransmitBuffer()
Parameters
u8Indexindex of transmit buffer array (0x00..0x3F)
u16Valuevalue to place in position u8Index of transmit buffer (0x0000..0xFFFF)
Returns
0 on success; exception number on failure
Examples:
examples/Basic/Basic.pde, and examples/PhoenixContact_nanoLC/PhoenixContact_nanoLC.pde.
268 {
269  if (u8Index < ku8MaxBufferSize)
270  {
271  _u16TransmitBuffer[u8Index] = u16Value;
272  return ku8MBSuccess;
273  }
274  else
275  {
277  }
278 }
static const uint8_t ku8MBIllegalDataAddress
Modbus protocol illegal data address exception.
Definition: ModbusMaster.h:112
static const uint8_t ku8MaxBufferSize
size of response/transmit buffers
Definition: ModbusMaster.h:223
static const uint8_t ku8MBSuccess
ModbusMaster success.
Definition: ModbusMaster.h:152
uint16_t _u16TransmitBuffer[ku8MaxBufferSize]
buffer containing data to transmit to Modbus slave; set via SetTransmitBuffer()
Definition: ModbusMaster.h:229

§ clearTransmitBuffer()

void ModbusMaster::clearTransmitBuffer ( )

Clear Modbus transmit buffer.

See also
ModbusMaster::setTransmitBuffer(uint8_t u8Index, uint16_t u16Value)
288 {
289  uint8_t i;
290 
291  for (i = 0; i < ku8MaxBufferSize; i++)
292  {
293  _u16TransmitBuffer[i] = 0;
294  }
295 }
static const uint8_t ku8MaxBufferSize
size of response/transmit buffers
Definition: ModbusMaster.h:223
uint16_t _u16TransmitBuffer[ku8MaxBufferSize]
buffer containing data to transmit to Modbus slave; set via SetTransmitBuffer()
Definition: ModbusMaster.h:229