ModbusMaster
v2.0.1
Arduino library for communicating with Modbus slaves over RS232/485 (via RTU protocol).
|
Functions | |
uint8_t | ModbusMaster::readCoils (uint16_t, uint16_t) |
Modbus function 0x01 Read Coils. More... | |
uint8_t | ModbusMaster::readDiscreteInputs (uint16_t, uint16_t) |
Modbus function 0x02 Read Discrete Inputs. More... | |
uint8_t | ModbusMaster::writeSingleCoil (uint16_t, uint8_t) |
Modbus function 0x05 Write Single Coil. More... | |
uint8_t | ModbusMaster::writeMultipleCoils (uint16_t, uint16_t) |
Modbus function 0x0F Write Multiple Coils. More... | |
uint8_t ModbusMaster::readCoils | ( | uint16_t | u16ReadAddress, |
uint16_t | u16BitQty | ||
) |
Modbus function 0x01 Read Coils.
This function code is used to read from 1 to 2000 contiguous status of coils in a remote device. The request specifies the starting address, i.e. the address of the first coil specified, and the number of coils. Coils are addressed starting at zero.
The coils in the response buffer are packed as one coil per bit of the data field. Status is indicated as 1=ON and 0=OFF. The LSB of the first data word contains the output addressed in the query. The other coils follow toward the high order end of this word and from low order to high order in subsequent words.
If the returned quantity is not a multiple of sixteen, the remaining bits in the final data word will be padded with zeros (toward the high order end of the word).
u16ReadAddress | address of first coil (0x0000..0xFFFF) |
u16BitQty | quantity of coils to read (1..2000, enforced by remote device) |
uint8_t ModbusMaster::readDiscreteInputs | ( | uint16_t | u16ReadAddress, |
uint16_t | u16BitQty | ||
) |
Modbus function 0x02 Read Discrete Inputs.
This function code is used to read from 1 to 2000 contiguous status of discrete inputs in a remote device. The request specifies the starting address, i.e. the address of the first input specified, and the number of inputs. Discrete inputs are addressed starting at zero.
The discrete inputs in the response buffer are packed as one input per bit of the data field. Status is indicated as 1=ON; 0=OFF. The LSB of the first data word contains the input addressed in the query. The other inputs follow toward the high order end of this word, and from low order to high order in subsequent words.
If the returned quantity is not a multiple of sixteen, the remaining bits in the final data word will be padded with zeros (toward the high order end of the word).
u16ReadAddress | address of first discrete input (0x0000..0xFFFF) |
u16BitQty | quantity of discrete inputs to read (1..2000, enforced by remote device) |
uint8_t ModbusMaster::writeSingleCoil | ( | uint16_t | u16WriteAddress, |
uint8_t | u8State | ||
) |
Modbus function 0x05 Write Single Coil.
This function code is used to write a single output to either ON or OFF in a remote device. The requested ON/OFF state is specified by a constant in the state field. A non-zero value requests the output to be ON and a value of 0 requests it to be OFF. The request specifies the address of the coil to be forced. Coils are addressed starting at zero.
u16WriteAddress | address of the coil (0x0000..0xFFFF) |
u8State | 0=OFF, non-zero=ON (0x00..0xFF) |
uint8_t ModbusMaster::writeMultipleCoils | ( | uint16_t | u16WriteAddress, |
uint16_t | u16BitQty | ||
) |
Modbus function 0x0F Write Multiple Coils.
This function code is used to force each coil in a sequence of coils to either ON or OFF in a remote device. The request specifies the coil references to be forced. Coils are addressed starting at zero.
The requested ON/OFF states are specified by contents of the transmit buffer. A logical '1' in a bit position of the buffer requests the corresponding output to be ON. A logical '0' requests it to be OFF.
u16WriteAddress | address of the first coil (0x0000..0xFFFF) |
u16BitQty | quantity of coils to write (1..2000, enforced by remote device) |