public class WriteMultipleCoilsRequest extends ModbusRequest
Coils are understood as bits that can be manipulated (i.e. set or cleared).
| Constructor and Description |
|---|
WriteMultipleCoilsRequest()
Constructs a new WriteMultipleCoilsRequest instance.
|
WriteMultipleCoilsRequest(int ref,
BitVector bv)
Constructs a new WriteMultipleCoilsRequest instance with the
given reference and coil values.
|
WriteMultipleCoilsRequest(int ref,
int count)
Constructs a new WriteMultipleCoilsRequest instance with a given
reference and count of coils to be written, followed by the actual byte
count, and then count number of bytes.
|
| Modifier and Type | Method and Description |
|---|---|
ModbusResponse |
createResponse(AbstractModbusListener listener)
Returns the ModbusResponse that represents the answer to this
ModbusRequest.
|
int |
getBitCount()
getBitCount - Returns the number of coils written with the request.
|
int |
getByteCount()
getByteCount - Returns the number of bytes required for packing the
coils.
|
BitVector |
getCoils()
getCoils - Returns the BitVector instance holding coil status
information.
|
boolean |
getCoilStatus(int index)
getCoilStatus - Returns the status of the specified coil.
|
byte[] |
getMessage()
Returns the raw message as an array of bytes.
|
int |
getReference()
getReference - Returns the reference of the coil to to start writing to
with this WriteMultipleCoilsRequest.
|
ModbusResponse |
getResponse()
Returns the ModbusResponse that correlates with this
ModbusRequest.
|
void |
readData(DataInput din)
Reads the subclass specific data from the given DataInput instance.
|
void |
setCoils(BitVector bv)
setCoils - Sets the BitVector instance holding coil status
information.
|
void |
setCoilStatus(int index,
boolean b)
setCoilStatus - Sets the status of the specified coil.
|
void |
setReference(int ref)
setReference - Sets the reference of the coil to start writing to with
this WriteMultipleCoilsRequest.
|
void |
writeData(DataOutput dout)
Writes the subclass specific data to the given DataOutput.
|
createExceptionResponse, createModbusRequestgetDataLength, getFunctionCode, getHexMessage, getOutputLength, getProtocolID, getTransactionID, getUnitID, isHeadless, readFrom, setDataLength, setHeadless, setHeadless, setProtocolID, setTransactionID, setUnitID, writeTopublic WriteMultipleCoilsRequest(int ref,
BitVector bv)
ref - the index of the first coil to be written.bv - the coil values to be written.public WriteMultipleCoilsRequest(int ref,
int count)
ref - the index of the first coil to be written.count - the number of coils to be written.public WriteMultipleCoilsRequest()
A minimal message contains the reference to the first coil as a short, the number of coils as a short, and not less than one byte of coil data.
public ModbusResponse getResponse()
ModbusRequestThe response must include the unit number, function code, as well as any transport-specific header information.
This method is used to create an empty response which must be populated by the caller. It is commonly used to un-marshal responses from Modbus slaves.
getResponse in class ModbusRequestpublic ModbusResponse createResponse(AbstractModbusListener listener)
ModbusRequestThe implementation should take care about assembling the reply to this ModbusRequest.
This method is used to create responses from the process image associated with the listener. It is commonly used to implement Modbus slave instances.
createResponse in class ModbusRequestlistener - Listener that received the requestpublic int getReference()
public void setReference(int ref)
ref - the reference of the coil to start writing to.public int getBitCount()
public int getByteCount()
public boolean getCoilStatus(int index)
throws IndexOutOfBoundsException
index - the index of the coil to be tested.IndexOutOfBoundsException - if the given index is out of bounds.public void setCoilStatus(int index,
boolean b)
throws IndexOutOfBoundsException
index - the index of the coil to be set/reset.b - true if to be set, false for reset.IndexOutOfBoundsException - if the given index is out of bounds.public BitVector getCoils()
public void setCoils(BitVector bv)
bv - a BitVector instance holding coil status info.public void writeData(DataOutput dout) throws IOException
ModbusMessageImplwriteData in class ModbusMessageImpldout - the DataOutput to be written to.IOException - if an I/O related error occurs.public void readData(DataInput din) throws IOException
ModbusMessageImplreadData in class ModbusMessageImpldin - the DataInput to read from.IOException - if an I/O related error occurs.public byte[] getMessage()
ModbusMessageCopyright © 2025. All Rights Reserved.