net.wimpi.modbus.msg
Class ReadCoilsResponse

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

public final class ReadCoilsResponse
extends ModbusResponse

Class implementing a ReadCoilsResponse. The implementation directly correlates with the class 1 function read coils (FC 1). It encapsulates the corresponding response message.

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

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

Constructor Summary
ReadCoilsResponse()
          Constructs a new ReadCoilsResponse instance.
ReadCoilsResponse(int count)
          Constructs a new ReadCoilsResponse instance with a given count of coils (i.e.
 
Method Summary
 int getBitCount()
          Returns the number of bits (i.e.
 BitVector getCoils()
          Returns the BitVector that stores the collection of bits that have been read.
 boolean getCoilStatus(int index)
          Convenience method that returns the state of the bit at the given index.
 void readData(DataInput din)
          Reads the subclass specific data from the given DataInput instance.
 void setCoilStatus(int index, boolean b)
          Sets the status of the given coil.
 void writeData(DataOutput dout)
          Writes the subclass specific data to the given DataOutput.
 
Methods inherited from class net.wimpi.modbus.msg.ModbusResponse
createModbusResponse
 
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

ReadCoilsResponse

public ReadCoilsResponse()
Constructs a new ReadCoilsResponse instance.


ReadCoilsResponse

public ReadCoilsResponse(int count)
Constructs a new ReadCoilsResponse instance with a given count of coils (i.e. bits).

Parameters:
count - the number of bits to be read.
Method Detail

getBitCount

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

Returns:
the number of bits that have been read.

getCoils

public BitVector getCoils()
Returns the BitVector that stores the collection of bits that have been read.

Returns:
the BitVector holding the bits that have been read.

getCoilStatus

public boolean getCoilStatus(int index)
                      throws IndexOutOfBoundsException
Convenience method that returns the state of the bit at the given index.

Parameters:
index - the index of the coil for which the status should be returned.
Returns:
true if set, false otherwise.
Throws:
IndexOutOfBoundsException - if the index is out of bounds

setCoilStatus

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

Parameters:
index - the index of the coil to be set.
b - true if to be set, false for reset.

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.