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 [ VB.NET: IntPtr ] [ C, C++: modbus_t * ] [ C#: IntPtr ] [ Python: ctypes.c_int ]
Specify the pointer to the libmodbus structure.
addr [ VB.NET: Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]
Specify the start address to write.
nb [ VB.NET: Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]
Specify the number of registers to write.
data [ VB.NET: Ushort() ] [ C, C++: uint16_t * ] [ C#: ushort[] ] [ Python: ctypes.POINTER(ctypes.c_uint16) ]
Specify the start address of the array that has stored the data to be written.
Return values
ret [ VB.NET:Integer ] [ C, C++: int ] [ 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.
VB.NET |
Dim ret As Integer Dim ctx As IntPtr Dim data(8) As Ushort Dim i As Short For i = 0 To 7 data(i) = &H55 Next ret = modbus_write_registers(ctx, 0, 8, data)
|
C, 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 );
|
C# |
int ret; IntPtr ctx; ushort data = new ushort[8]; short i; for( i = 0 ; i < 8 ; i++ ){ data[i] = 0x55; } ret = modbus.WriteRegisters(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)
|