Function
Uses the function code Write Multiple Registers (code 16) to write multiple registers to the holding register area.
Format
ret = modbus_write_registers( ctx , addr , nb , data )
Parameters
ctx [ C : modbus_t * ] [ Python : ctypes.c_int ]
Specify the pointer to the libmodbus structure.
addr [ C : int ] [ Python : ctypes.c_int ]
Specify the start address to write.
nb [ C : int ] [ Python : ctypes.c_int ]
Specify the number of registers to write.
data [ C : uint16_t * ] [ Python : ctypes.POINTER(ctypes.c_uint16) ]
Specify the start address of the array that has stored the data to be written.
Return values
ret [ C : int ] [ Python : ctypes.c_int ]
If the function succeeds, the number of registers that were successfully written is returned.
If the function fails, -1 is returned, and the following errno is set.
Definition |
Description |
EMBMDATA |
The number of request data is too large. |
Remarks
Uses the function code Write Multiple Registers (code 16) to write multiple registers to the holding register area.
Example
Writes 0x55 for 8 words from the register at address 0.
C |
int ret; modbus_t *ctx; Uint16_t status[8]; for( i = 0 ; i < 8 ; i++ ){ data[i] = 0x55; } ret = modbus_write_registers( ctx, 0, 8 , data );
|
Python |
ret = ctypes.c_int ctx = ctypes.POINTER(modbus_t) uint16_buff_type = ctypes.c_uint16 * 8 data = uint16_buff_type() for i in range(8): data[i] = 0x55 ret = modbus.modbus_write_registers(ctx, 0, 8, data)
|