modbus_object.WriteSingleCoil Method

Writes a single output to a MODBUS slave.
modbus_object. WriteSingleCoil(coil, value)

Prerequisites

None

Parameters

coil

A required Integer expression that specifies the number of the coil to be written.

value

A required Boolean expression that determines the output to be written.  Any non-zero value is considered True.

Remarks

This method issues a MODBUS/TCP Write Single Coil request (function 5). If more than one coil is to be changed, it is much more efficient to use the WriteMultipleCoils method than multiple WriteSingleCoil methods. A new connection to the MODBUS slave is made if none currently existsIf any network errors occur, this method throws an exception.

Examples

Dim ep As New IPEndPoint("192.168.0.150")
Dim mb As New Modbus(ep)
mb.WriteSingleCoil(1, True) ' Turn on coil 1
mb.WriteSingleCoil(2, False) ' Turn off coil 2

See Also

Modbus Class |modbus_object.WriteMultipleCoils