net.wimpi.modbus.msg
Class WriteMultipleCoilsRequest

java.lang.Object
  extended by net.wimpi.modbus.msg.ModbusMessageImpl
      extended by net.wimpi.modbus.msg.ModbusRequest
          extended by net.wimpi.modbus.msg.WriteMultipleCoilsRequest
All Implemented Interfaces:
Transportable, ModbusMessage

public final class WriteMultipleCoilsRequest
extends ModbusRequest

Class implementing a WriteMultipleCoilsRequest. The implementation directly correlates with the class 1 function write multiple coils (FC 15). It encapsulates the corresponding request message.

Coils are understood as bits that can be manipulated (i.e. set or unset).

Version:
@version@ (@date@)
Author:
Dieter Wimberger

Constructor Summary
WriteMultipleCoilsRequest()
          Constructs a new WriteMultipleCoilsRequest instance.
WriteMultipleCoilsRequest(int ref, BitVector bv)
          Constructs a new WriteMultipleCoilsRequest instance with given reference and coil status.
WriteMultipleCoilsRequest(int ref, int count)
          Constructs a new WriteMultipleCoilsRequest instance with a given reference and count of coils (i.e.
 
Method Summary
 ModbusResponse createResponse()
          Returns the ModbusResponse that represents the answer to this ModbusRequest.
 int getBitCount()
          Returns the number of bits (i.e.
 int getByteCount()
          Returns the number of bytes required for packing the coil bits.
 BitVector getCoils()
          Returns the BitVector instance holding coil status information.
 boolean getCoilStatus(int index)
          Returns the status of the given coil.
 int getReference()
          Returns the reference of the register to to start reading from with this ReadCoilsRequest.
 void readData(DataInput din)
          Reads the subclass specific data from the given DataInput instance.
 void setCoils(BitVector bv)
          Sets the BitVector instance holding coil status information.
 void setCoilStatus(int index, boolean b)
          Sets the coil status of the given coil.
 void setReference(int ref)
          Sets the reference of the register to start reading from with this ReadCoilsRequest.
 void writeData(DataOutput dout)
          Writes the subclass specific data to the given DataOutput.
 
Methods inherited from class net.wimpi.modbus.msg.ModbusRequest
createExceptionResponse, createModbusRequest
 
Methods inherited from class net.wimpi.modbus.msg.ModbusMessageImpl
getDataLength, getFunctionCode, getHexMessage, getOutputLength, getProtocolID, getTransactionID, getUnitID, isHeadless, readFrom, setDataLength, setHeadless, setProtocolID, setTransactionID, setUnitID, writeTo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WriteMultipleCoilsRequest

public WriteMultipleCoilsRequest()
Constructs a new WriteMultipleCoilsRequest instance.


WriteMultipleCoilsRequest

public WriteMultipleCoilsRequest(int ref,
                                 int count)
Constructs a new WriteMultipleCoilsRequest instance with a given reference and count of coils (i.e. bits) to be written.

Parameters:
ref - the index of the first coil to be written.
count - the number of coils to be written.

WriteMultipleCoilsRequest

public WriteMultipleCoilsRequest(int ref,
                                 BitVector bv)
Constructs a new WriteMultipleCoilsRequest instance with given reference and coil status.

Parameters:
ref - the index of the first coil to be written.
bv - the coils to be written.
Method Detail

createResponse

public ModbusResponse createResponse()
Description copied from class: ModbusRequest
Returns the ModbusResponse that represents the answer to this ModbusRequest.

The implementation should take care about assembling the reply to this ModbusRequest.

Specified by:
createResponse in class ModbusRequest
Returns:
the corresponding ModbusResponse.

setReference

public void setReference(int ref)
Sets the reference of the register to start reading from with this ReadCoilsRequest.

Parameters:
ref - the reference of the register to start reading from.

getReference

public int getReference()
Returns the reference of the register to to start reading from with this ReadCoilsRequest.

Returns:
the reference of the register to start reading from as int.

getBitCount

public int getBitCount()
Returns the number of bits (i.e. input discretes) read with the request.

Returns:
the number of bits that have been read.

getByteCount

public int getByteCount()
Returns the number of bytes required for packing the coil bits.

Returns:
the number of bytes required for packing the coil bits.

getCoilStatus

public boolean getCoilStatus(int index)
                      throws IndexOutOfBoundsException
Returns the status of the given coil.

Parameters:
index - the index of the coil to be tested.
Returns:
true if set, false otherwise.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.

setCoilStatus

public void setCoilStatus(int index,
                          boolean b)
                   throws IndexOutOfBoundsException
Sets the coil status of the given coil.

Parameters:
index - the index of the coil to be set/reset.
b - true if to be set, false for reset.
Throws:
IndexOutOfBoundsException - if the given index is out of bounds.

getCoils

public BitVector getCoils()
Returns the BitVector instance holding coil status information.

Returns:
the coils status as BitVector instance.

setCoils

public void setCoils(BitVector bv)
Sets the BitVector instance holding coil status information.

Parameters:
bv - a BitVector instance holding coil status info.

writeData

public void writeData(DataOutput dout)
               throws IOException
Description copied from class: ModbusMessageImpl
Writes the subclass specific data to the given DataOutput.

Specified by:
writeData in class ModbusMessageImpl
Parameters:
dout - the DataOutput to be written to.
Throws:
IOException - if an I/O related error occurs.

readData

public void readData(DataInput din)
              throws IOException
Description copied from class: ModbusMessageImpl
Reads the subclass specific data from the given DataInput instance.

Specified by:
readData in class ModbusMessageImpl
Parameters:
din - the DataInput to read from.
Throws:
IOException - if an I/O related error occurs.


Copyright © 2010. All Rights Reserved.