Package net.wimpi.modbus.util

Examples of net.wimpi.modbus.util.BitVector


   *
   * @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);
  }//setBitCount
View Full Code Here


        if (msm.writeCoil(slaveId, 4, true) == true) {
          System.out.println("Set output 5 to true");
        } else {
          System.err.println("Error setting slave " + slaveId + " output 5");
        }
        BitVector coils = msm.readCoils(slaveId, 0, 8);
        if (coils != null) {
          System.out.print("Coils:");
          for (int i = 0; i < coils.size(); i++) {
            System.out.print(" " + i + ": " + coils.getBit(i));
          }
          System.out.println();

          try {
            msm.writeMultipleCoils(slaveId, 0, coils);
          } catch (ModbusException ex) {
            System.out.println("Error writing coils: " + result);
          }
        } else {
          System.out.println("Outputs: null");
          msm.disconnect();
          System.exit(-1);
        }


        BitVector digInp = msm.readInputDiscretes(slaveId, 0, 8);

        if (digInp != null) {
          System.out.print("Digital Inputs:");
          for (int i = 0; i < digInp.size(); i++) {
            System.out.print(" " + i + ": " + digInp.getBit(i));
          }
          System.out.println();
          System.out.println("Inputs: " + ModbusUtil.toHex(digInp.getBytes()));
        } else {
          System.out.println("Inputs: null");
          msm.disconnect();
          System.exit(-1);
        }
View Full Code Here

   * <b>
   * @param count the number of bits to be read.
   */
  public ReadCoilsResponse(int count) {
    super();
    m_Coils = new BitVector(count);
    setDataLength(m_Coils.byteSize() + 1);
  }//constructor(int)
View Full Code Here

    m_ReadCoilsRequest.setUnitID(unitid);
    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;
  }//readCoils
View Full Code Here

    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;
  }//readInputDiscretes
View Full Code Here

      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;
  }//readCoils
View Full Code Here

      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;
  }//readInputDiscretes
View Full Code Here

      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;
  }//readCoils
View Full Code Here

      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;
  }//readInputDiscretes
View Full Code Here

      do {
        trans.execute();

        res = (ReadInputDiscretesResponse) trans.getResponse();
        if (Modbus.debug) System.out.println("Response: " + res.getHexMessage());
        BitVector inputs = res.getDiscretes();
        byte ret[] = new byte[inputs.size()];
        for (int i = 0; i < count; i++) {
          System.out.println("Bit " + i + " = " + inputs.getBit(i));
        }

        k++;
      } while (k < repeat);
View Full Code Here

TOP

Related Classes of net.wimpi.modbus.util.BitVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.