Modbus TCP 0.1.0

Functions
Modbus Function Codes for Holding/Input Registers

## Functions
uint8_t | ModbusTCP::readHoldingRegisters (uint16_t, uint16_t)
uint8_t | ModbusTCP::readInputRegisters (uint16_t, uint8_t)
uint8_t | ModbusTCP::writeSingleRegister (uint16_t, uint16_t)
uint8_t | ModbusTCP::writeMultipleRegisters (uint16_t, uint16_t)
uint8_t | ModbusTCP::maskWriteRegister (uint16_t, uint16_t, uint16_t)
uint8_t | ModbusTCP::readWriteMultipleRegisters (uint16_t, uint16_t, uint16_t, uint16_t)

## Detailed Description

## Function Documentation

## ◆ maskWriteRegister()

uint8_t ModbusTCP::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))

Parameters

  u16WriteAddress | address of the holding register (0x0000..0xFFFF)
  u16AndMask | AND mask (0x0000..0xFFFF)
  u16OrMask | OR mask (0x0000..0xFFFF)

Returns
  0 on success; exception number on failure

## ◆ readHoldingRegisters()

uint8_t ModbusTCP::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.

Parameters

  u16ReadAddress | address of the first holding register (0x0000..0xFFFF)
  u16ReadQty | quantity of holding registers to read (1..125, enforced by remote device)

Returns
  0 on success; exception number on failure

## ◆ readInputRegisters()

uint8_t ModbusTCP::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.

Parameters

  u16ReadAddress | address of the first input register (0x0000..0xFFFF)
  u16ReadQty | quantity of input registers to read (1..125, enforced by remote device)

Returns
  0 on success; exception number on failure

## ◆ readWriteMultipleRegisters()

uint8_t ModbusTCP::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.

Parameters

  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)

Returns
  0 on success; exception number on failure

## ◆ writeMultipleRegisters()

uint8_t ModbusTCP::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.

Parameters

  u16WriteAddress | address of the holding register (0x0000..0xFFFF)
  u16WriteQty | quantity of holding registers to write (1..123, enforced by remote device)

Returns
  0 on success; exception number on failure

## ◆ writeSingleRegister()

uint8_t ModbusTCP::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.

Parameters

  u16WriteAddress | address of the holding register (0x0000..0xFFFF)
  u16WriteValue | value to be written to holding register (0x0000..0xFFFF)

Returns
  0 on success; exception number on failure