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 [ VB.NET: IntPtr ] [ C, C++: modbus_t * ] [ C#: IntPtr ] [ Python: ctypes.POINTER(modbus_t) ]
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 bits to write.
data [ VB.NET:Byte() ] [ C, C++: uint8_t * ] [ C#: byte[] ] [ Python: ctypes.POINTER(ctypes.c_uint8) ]
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 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.
VB.NET |
Dim ret As Integer Dim ctx As IntPtr Dim data(8) As Byte Dim i As Short For i = 0 To 7 data(i) = 1 Next i ret = modbus_write_bits(ctx, 0, 8, data)
|
C, 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 );
|
C# |
int ret; IntPtr ctx; byte[] data = new byte[8]; short i; for( i = 0 ; i < 8 ; i++ ){ data[i] = 1; } ret = modbus.WriteBits(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)
|