Search in sources :

Example 6 with ReadInputDiscretesResponse

use of net.wimpi.modbus.msg.ReadInputDiscretesResponse in project openhab1-addons by openhab.

the class ModbusSerialMaster method readInputDiscretes.

// writeMultipleCoils
/**
     * Reads a given number of input discrete states from the slave.
     * <p/>
     * Note that the number of bits in the bit vector will be
     * forced to the number originally requested.
     *
     * @param unitid the slave unit id.
     * @param ref the offset of the input discrete to start reading from.
     * @param count the number of input discrete states to be read.
     * @return a <tt>BitVector</tt> instance holding the received input discrete
     *         states.
     * @throws ModbusException if an I/O error, a slave exception or
     *             a transaction error occurs.
     */
public synchronized BitVector readInputDiscretes(int unitid, int ref, int count) throws ModbusException {
    m_ReadInputDiscretesRequest.setUnitID(unitid);
    m_ReadInputDiscretesRequest.setReference(ref);
    m_ReadInputDiscretesRequest.setBitCount(count);
    m_Transaction.setRequest(m_ReadInputDiscretesRequest);
    m_Transaction.execute();
    BitVector bv = ((ReadInputDiscretesResponse) m_Transaction.getResponse()).getDiscretes();
    bv.forceSize(count);
    return bv;
}
Also used : BitVector(net.wimpi.modbus.util.BitVector) ReadInputDiscretesResponse(net.wimpi.modbus.msg.ReadInputDiscretesResponse)

Example 7 with ReadInputDiscretesResponse

use of net.wimpi.modbus.msg.ReadInputDiscretesResponse in project openhab1-addons by openhab.

the class ModbusTCPMaster method readInputDiscretes.

// writeMultipleCoils
/**
     * Reads a given number of input discrete states from the slave.
     * <p/>
     * Note that the number of bits in the bit vector will be
     * forced to the number originally requested.
     *
     * @param ref the offset of the input discrete to start reading from.
     * @param count the number of input discrete states to be read.
     * @return a <tt>BitVector</tt> instance holding the received input discrete
     *         states.
     * @throws ModbusException if an I/O error, a slave exception or
     *             a transaction error occurs.
     */
public synchronized BitVector readInputDiscretes(int ref, int count) throws ModbusException {
    m_ReadInputDiscretesRequest.setReference(ref);
    m_ReadInputDiscretesRequest.setBitCount(count);
    m_Transaction.setRequest(m_ReadInputDiscretesRequest);
    m_Transaction.execute();
    BitVector bv = ((ReadInputDiscretesResponse) m_Transaction.getResponse()).getDiscretes();
    bv.forceSize(count);
    return bv;
}
Also used : BitVector(net.wimpi.modbus.util.BitVector) ReadInputDiscretesResponse(net.wimpi.modbus.msg.ReadInputDiscretesResponse)

Aggregations

ReadInputDiscretesResponse (net.wimpi.modbus.msg.ReadInputDiscretesResponse)7 ReadInputDiscretesRequest (net.wimpi.modbus.msg.ReadInputDiscretesRequest)4 BitVector (net.wimpi.modbus.util.BitVector)4 InetAddress (java.net.InetAddress)2 ModbusException (net.wimpi.modbus.ModbusException)1 ModbusSerialTransaction (net.wimpi.modbus.io.ModbusSerialTransaction)1 ModbusTCPTransaction (net.wimpi.modbus.io.ModbusTCPTransaction)1 ModbusUDPTransaction (net.wimpi.modbus.io.ModbusUDPTransaction)1 ModbusRequest (net.wimpi.modbus.msg.ModbusRequest)1 ReadCoilsRequest (net.wimpi.modbus.msg.ReadCoilsRequest)1 ReadCoilsResponse (net.wimpi.modbus.msg.ReadCoilsResponse)1 ReadInputRegistersRequest (net.wimpi.modbus.msg.ReadInputRegistersRequest)1 ReadInputRegistersResponse (net.wimpi.modbus.msg.ReadInputRegistersResponse)1 ReadMultipleRegistersRequest (net.wimpi.modbus.msg.ReadMultipleRegistersRequest)1 ReadMultipleRegistersResponse (net.wimpi.modbus.msg.ReadMultipleRegistersResponse)1 SerialConnection (net.wimpi.modbus.net.SerialConnection)1 TCPMasterConnection (net.wimpi.modbus.net.TCPMasterConnection)1 UDPMasterConnection (net.wimpi.modbus.net.UDPMasterConnection)1 SerialParameters (net.wimpi.modbus.util.SerialParameters)1