Function
Uses the function code Write Multiple Coils (code 15) to write multiple bits to the Coil area.
Format
ret = modbus_write_bits( ctx , addr , nb , data )
Parameters
ctx [ C : modbus_t * ] [ Python : ctypes.POINTER(modbus_t) ]
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 bits to write.
data [ C : uint8_t * ] [ Python : ctypes.POINTER(ctypes.c_uint8) ]
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 bits 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 Coils (code 15) to write multiple bits to the Coil area.
Example
Writes 1 for 8 bits from address 0.
C |
int ret; modbus_t *ctx; uint8_t data[8]; short i; for( i = 0 ; i < 8 ; i++ ){ data[i] = 1; } ret = modbus_write_bits( ctx, 0, 8 , data );
|
Python |
ret = ctypes.c_int ctx = ctypes.POINTER(modbus_t) uint8_buff_type = ctypes.c_uint8 * 8 data = uint8_buff_type() for i in range(8): data[i] = 1 ret = modbus.modbus_write_bits(ctx, 0, 8, data)
|