ModbusMaster
v2.0.1
Arduino library for communicating with Modbus slaves over RS232/485 (via RTU protocol).
|
Functions | |
uint8_t | ModbusMaster::readHoldingRegisters (uint16_t, uint16_t) |
Modbus function 0x03 Read Holding Registers. More... | |
uint8_t | ModbusMaster::readInputRegisters (uint16_t, uint8_t) |
Modbus function 0x04 Read Input Registers. More... | |
uint8_t | ModbusMaster::writeSingleRegister (uint16_t, uint16_t) |
Modbus function 0x06 Write Single Register. More... | |
uint8_t | ModbusMaster::writeMultipleRegisters (uint16_t, uint16_t) |
Modbus function 0x10 Write Multiple Registers. More... | |
uint8_t | ModbusMaster::maskWriteRegister (uint16_t, uint16_t, uint16_t) |
Modbus function 0x16 Mask Write Register. More... | |
uint8_t | ModbusMaster::readWriteMultipleRegisters (uint16_t, uint16_t, uint16_t, uint16_t) |
Modbus function 0x17 Read Write Multiple Registers. More... | |
uint8_t ModbusMaster::readHoldingRegisters | ( | uint16_t | u16ReadAddress, |
uint16_t | u16ReadQty | ||
) |
Modbus function 0x03 Read Holding Registers.
This function code is used to read the contents of a contiguous block of holding registers in a remote device. The request specifies the starting register address and the number of registers. Registers are addressed starting at zero.
The register data in the response buffer is packed as one word per register.
u16ReadAddress | address of the first holding register (0x0000..0xFFFF) |
u16ReadQty | quantity of holding registers to read (1..125, enforced by remote device) |
uint8_t ModbusMaster::readInputRegisters | ( | uint16_t | u16ReadAddress, |
uint8_t | u16ReadQty | ||
) |
Modbus function 0x04 Read Input Registers.
This function code is used to read from 1 to 125 contiguous input registers in a remote device. The request specifies the starting register address and the number of registers. Registers are addressed starting at zero.
The register data in the response buffer is packed as one word per register.
u16ReadAddress | address of the first input register (0x0000..0xFFFF) |
u16ReadQty | quantity of input registers to read (1..125, enforced by remote device) |
uint8_t ModbusMaster::writeSingleRegister | ( | uint16_t | u16WriteAddress, |
uint16_t | u16WriteValue | ||
) |
Modbus function 0x06 Write Single Register.
This function code is used to write a single holding register in a remote device. The request specifies the address of the register to be written. Registers are addressed starting at zero.
u16WriteAddress | address of the holding register (0x0000..0xFFFF) |
u16WriteValue | value to be written to holding register (0x0000..0xFFFF) |
uint8_t ModbusMaster::writeMultipleRegisters | ( | uint16_t | u16WriteAddress, |
uint16_t | u16WriteQty | ||
) |
Modbus function 0x10 Write Multiple Registers.
This function code is used to write a block of contiguous registers (1 to 123 registers) in a remote device.
The requested written values are specified in the transmit buffer. Data is packed as one word per register.
u16WriteAddress | address of the holding register (0x0000..0xFFFF) |
u16WriteQty | quantity of holding registers to write (1..123, enforced by remote device) |
uint8_t ModbusMaster::maskWriteRegister | ( | uint16_t | u16WriteAddress, |
uint16_t | u16AndMask, | ||
uint16_t | u16OrMask | ||
) |
Modbus function 0x16 Mask Write Register.
This function code is used to modify the contents of a specified holding register using a combination of an AND mask, an OR mask, and the register's current contents. The function can be used to set or clear individual bits in the register.
The request specifies the holding register to be written, the data to be used as the AND mask, and the data to be used as the OR mask. Registers are addressed starting at zero.
The function's algorithm is:
Result = (Current Contents && And_Mask) || (Or_Mask && (~And_Mask))
u16WriteAddress | address of the holding register (0x0000..0xFFFF) |
u16AndMask | AND mask (0x0000..0xFFFF) |
u16OrMask | OR mask (0x0000..0xFFFF) |
uint8_t ModbusMaster::readWriteMultipleRegisters | ( | uint16_t | u16ReadAddress, |
uint16_t | u16ReadQty, | ||
uint16_t | u16WriteAddress, | ||
uint16_t | u16WriteQty | ||
) |
Modbus function 0x17 Read Write Multiple Registers.
This function code performs a combination of one read operation and one write operation in a single MODBUS transaction. The write operation is performed before the read. Holding registers are addressed starting at zero.
The request specifies the starting address and number of holding registers to be read as well as the starting address, and the number of holding registers. The data to be written is specified in the transmit buffer.
u16ReadAddress | address of the first holding register (0x0000..0xFFFF) |
u16ReadQty | quantity of holding registers to read (1..125, enforced by remote device) |
u16WriteAddress | address of the first holding register (0x0000..0xFFFF) |
u16WriteQty | quantity of holding registers to write (1..121, enforced by remote device) |