modbus_write_bit


 

Function

 

Uses the function code Write Coil (code 05) to write 1 bit to the Coil area.

 

Format

 

ret = modbus_write_bit( ctx , addr , status )

 

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.

 

status [ VB.NET: Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]

Specify 0 or 1 for the data to be written.

 

Return values

 

ret [ VB.NET:Integer ] [ C, C++: int ] [ C#: int ] [ Python: ctypes.c_int ]

 

If the function succeeds, 0 is returned.

If the function fails, -1 is returned.

 

Remarks

 

Uses the function code Write Coil (code 05) to write 1 bit to the Coil area.

 

Example

 

Writes 1 to the bit at address 0.

 

VB.NET

Dim ret As Integer

Dim ctx As IntPtr

ret = modbus_write_bit(ctx, 0, 1)

 

C, C++

int ret;

modbus_t *ctx;

ret = modbus_write_bit( ctx, 0, 1 );

 

C#

int ret;

IntPtr ctx;

ret = modbus.WriteBit(ctx, 0, 1);

 

Python

ret = ctypes.c_int

ctx = ctypes.POINTER(modbus_t)

ret = modbus.modbus_write_bit(ctx, 0, 1)