Search in sources :

Example 6 with BitVector

use of net.wimpi.modbus.util.BitVector 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 BitVector

use of net.wimpi.modbus.util.BitVector 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)

Example 8 with BitVector

use of net.wimpi.modbus.util.BitVector in project openhab1-addons by openhab.

the class ModbusTCPMaster method readCoils.

// isReconnecting
/**
     * Reads a given number of coil 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 coil to start reading from.
     * @param count the number of coil states to be read.
     * @return a <tt>BitVector</tt> instance holding the
     *         received coil states.
     * @throws ModbusException if an I/O error, a slave exception or
     *             a transaction error occurs.
     */
public synchronized BitVector readCoils(int ref, int count) throws ModbusException {
    m_ReadCoilsRequest.setReference(ref);
    m_ReadCoilsRequest.setBitCount(count);
    m_Transaction.setRequest(m_ReadCoilsRequest);
    m_Transaction.execute();
    BitVector bv = ((ReadCoilsResponse) m_Transaction.getResponse()).getCoils();
    bv.forceSize(count);
    return bv;
}
Also used : BitVector(net.wimpi.modbus.util.BitVector) ReadCoilsResponse(net.wimpi.modbus.msg.ReadCoilsResponse)

Example 9 with BitVector

use of net.wimpi.modbus.util.BitVector in project openhab1-addons by openhab.

the class ReadInputDiscretesResponse method setBitCount.

// getBitCount
/**
     * Sets the number of bits in this response.
     *
     * @param count the number of response bits as int.
     */
public void setBitCount(int count) {
    m_BitCount = count;
    m_Discretes = new BitVector(count);
    // set correct length, without counting unitid and fc
    setDataLength(m_Discretes.byteSize() + 1);
}
Also used : BitVector(net.wimpi.modbus.util.BitVector)

Aggregations

BitVector (net.wimpi.modbus.util.BitVector)9 ReadInputDiscretesResponse (net.wimpi.modbus.msg.ReadInputDiscretesResponse)4 ReadCoilsResponse (net.wimpi.modbus.msg.ReadCoilsResponse)3 SerialParameters (net.wimpi.modbus.util.SerialParameters)2 ModbusException (net.wimpi.modbus.ModbusException)1 ModbusSerialMaster (net.wimpi.modbus.facade.ModbusSerialMaster)1 ModbusSerialTransaction (net.wimpi.modbus.io.ModbusSerialTransaction)1 ReadInputDiscretesRequest (net.wimpi.modbus.msg.ReadInputDiscretesRequest)1 SerialConnection (net.wimpi.modbus.net.SerialConnection)1 InputRegister (net.wimpi.modbus.procimg.InputRegister)1 Register (net.wimpi.modbus.procimg.Register)1