SDK  23.9.2
For IoT System Software Development
Public Member Functions | Static Public Attributes | List of all members
ModbusMaster Class Reference

#include <ModbusMaster.hpp>

Public Member Functions

void begin (uint8_t, Stream &serial)
 
void idle (void(*)())
 
void preTransmission (void(*)())
 
void postTransmission (void(*)())
 
uint16_t getResponseBuffer (uint8_t)
 
void clearResponseBuffer ()
 
uint8_t setTransmitBuffer (uint8_t, uint16_t)
 
void clearTransmitBuffer ()
 
void beginTransmission (uint16_t)
 
uint8_t requestFrom (uint16_t, uint16_t)
 
void sendBit (bool)
 
void send (uint8_t)
 
void send (uint16_t)
 
void send (uint32_t)
 
uint8_t available (void)
 
uint16_t receive (void)
 
uint8_t readCoils (uint16_t, uint16_t)
 
uint8_t readDiscreteInputs (uint16_t, uint16_t)
 
uint8_t readHoldingRegisters (uint16_t, uint16_t)
 
uint8_t readInputRegisters (uint16_t, uint8_t)
 
uint8_t writeSingleCoil (uint16_t, uint8_t)
 
uint8_t writeSingleRegister (uint16_t, uint16_t)
 
uint8_t writeMultipleCoils (uint16_t, uint16_t)
 
uint8_t writeMultipleCoils ()
 
uint8_t writeMultipleRegisters (uint16_t, uint16_t)
 
uint8_t writeMultipleRegisters ()
 
uint8_t maskWriteRegister (uint16_t, uint16_t, uint16_t)
 
uint8_t readWriteMultipleRegisters (uint16_t, uint16_t, uint16_t, uint16_t)
 
uint8_t readWriteMultipleRegisters (uint16_t, uint16_t)
 

Static Public Attributes

static const uint8_t ku8MBIllegalFunction = 0x01
 
static const uint8_t ku8MBIllegalDataAddress = 0x02
 
static const uint8_t ku8MBIllegalDataValue = 0x03
 
static const uint8_t ku8MBSlaveDeviceFailure = 0x04
 
static const uint8_t ku8MBSuccess = 0x00
 
static const uint8_t ku8MBInvalidSlaveID = 0xE0
 
static const uint8_t ku8MBInvalidFunction = 0xE1
 
static const uint8_t ku8MBResponseTimedOut = 0xE2
 
static const uint8_t ku8MBInvalidCRC = 0xE3
 

Detailed Description

Arduino class library for communicating with Modbus slaves over RS232/485 (via RTU protocol).

Member Data Documentation

◆ ku8MBIllegalDataAddress

const uint8_t ModbusMaster::ku8MBIllegalDataAddress = 0x02
static

Modbus protocol illegal data address exception.

The data address received in the query is not an allowable address for the server (or slave). More specifically, the combination of reference number and transfer length is invalid. For a controller with 100 registers, the ADU addresses the first register as 0, and the last one as 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 4, then this request will successfully operate (address-wise at least) on registers 96, 97, 98, 99. If a request is submitted with a starting register address of 96 and a quantity of registers of 5, then this request will fail with Exception Code 0x02 "Illegal Data Address" since it attempts to operate on registers 96, 97, 98, 99 and 100, and there is no register with address

◆ ku8MBIllegalDataValue

const uint8_t ModbusMaster::ku8MBIllegalDataValue = 0x03
static

Modbus protocol illegal data value exception.

A value contained in the query data field is not an allowable value for server (or slave). This indicates a fault in the structure of the remainder of a complex request, such as that the implied length is incorrect. It specifically does NOT mean that a data item submitted for storage in a register has a value outside the expectation of the application program, since the MODBUS protocol is unaware of the significance of any particular value of any particular register.

◆ ku8MBIllegalFunction

const uint8_t ModbusMaster::ku8MBIllegalFunction = 0x01
static

Modbus protocol illegal function exception.

The function code received in the query is not an allowable action for the server (or slave). This may be because the function code is only applicable to newer devices, and was not implemented in the unit selected. It could also indicate that the server (or slave) is in the wrong state to process a request of this type, for example because it is unconfigured and is being asked to return register values.

◆ ku8MBInvalidCRC

const uint8_t ModbusMaster::ku8MBInvalidCRC = 0xE3
static

ModbusMaster invalid response CRC exception.

The CRC in the response does not match the one calculated.

◆ ku8MBInvalidFunction

const uint8_t ModbusMaster::ku8MBInvalidFunction = 0xE1
static

ModbusMaster invalid response function exception.

The function code in the response does not match that of the request.

◆ ku8MBInvalidSlaveID

const uint8_t ModbusMaster::ku8MBInvalidSlaveID = 0xE0
static

ModbusMaster invalid response slave ID exception.

The slave ID in the response does not match that of the request.

◆ ku8MBResponseTimedOut

const uint8_t ModbusMaster::ku8MBResponseTimedOut = 0xE2
static

ModbusMaster response timed out exception.

The entire response was not received within the timeout period, ModbusMaster::ku8MBResponseTimeout.

◆ ku8MBSlaveDeviceFailure

const uint8_t ModbusMaster::ku8MBSlaveDeviceFailure = 0x04
static

Modbus protocol slave device failure exception.

An unrecoverable error occurred while the server (or slave) was attempting to perform the requested action.

◆ ku8MBSuccess

const uint8_t ModbusMaster::ku8MBSuccess = 0x00
static

ModbusMaster success.

Modbus transaction was successful; the following checks were valid:

  • slave ID
  • function code
  • response code
  • data
  • CRC

The documentation for this class was generated from the following file: