• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java ReadMultipleRegistersResponse类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中net.wimpi.modbus.msg.ReadMultipleRegistersResponse的典型用法代码示例。如果您正苦于以下问题:Java ReadMultipleRegistersResponse类的具体用法?Java ReadMultipleRegistersResponse怎么用?Java ReadMultipleRegistersResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

ReadMultipleRegistersResponse类属于net.wimpi.modbus.msg包,在下文中一共展示了ReadMultipleRegistersResponse类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: decodeEnergyDecimals

点赞 3

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
/**
 * Decodes the configured number of energy digits after the decimal point. For
 * example, if the retrieved energy value is "12345678" and the decimals value
 * is 2, then the actual energy value is "123456.78".
 * 
 * @param response
 *          The response from the meter containing the power and energy
 *          format.
 * @return An int that represents the number of ending digits from the energy
 *         reading that should be considered as decimals.
 */
private int decodeEnergyDecimals(ReadMultipleRegistersResponse response) {
  if (response != null && response.getWordCount() == 1) {
    // From Shark manual, bitmap looks like this ("-" is unused bit
    // apparently):
    // ppppiinn feee-ddd
    //
    // pppp = power scale (0-unit, 3-kilo, 6-mega, 8-auto)
    // ii = power digits after decimal point (0-3),
    // applies only if f=1 and pppp is not auto
    // nn = number of energy digits (5-8 --> 0-3)
    // eee = energy scale (0-unit, 3-kilo, 6-mega)
    // f = decimal point for power
    // (0=data-dependant placement, 1=fixed placement per ii value)
    // ddd = energy digits after decimal point (0-6)

    // Get # of energy digits after decimal point by masking with 111
    return response.getRegisterValue(0) & 7;
  }
  else {
    return 0;
  }
}
 

开发者ID:wattdepot,
项目名称:wattdepot,
代码行数:34,
代码来源:SharkCollector.java

示例2: update

点赞 2

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
public void update(WagoBinding binding, String couplerName, int module) {
	if (!connect()) {
		logger.warn("coupler not connected.");
		return;
	}

	ModbusRequest request = new ReadMultipleRegistersRequest(offset, 4);
	transaction.setRequest(request);
	try {
		transaction.execute();
	} catch (Exception e) {
		logger.debug("update of channels failed: " + e.getMessage());
		return;
	}

	ReadMultipleRegistersResponse response = (ReadMultipleRegistersResponse) transaction
			.getResponse();
	if ((response.getTransactionID() != transaction.getTransactionID())
			&& !response.isHeadless()) {
		logger.debug("update of channels failed: invalid response.");
		return;
	}

	values[0] = response.getRegister(1).getValue() >> 4;
	values[1] = response.getRegister(3).getValue() >> 4;

	Collection<String> itemNames = binding.getItemNames();
	for (String itemName : itemNames) {
		binding.updateItemPWM(itemName, couplerName, module, values);
	}
}
 

开发者ID:andrey-desman,
项目名称:openhab-hdl,
代码行数:32,
代码来源:FBCoupler.java

示例3: readRegister

点赞 2

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
public static int readRegister(String ip, int port, int address,
		int slaveId) {
	int data = 0;
	try {
		InetAddress addr = InetAddress.getByName(ip);

		TCPMasterConnection con = new TCPMasterConnection(addr);

		con.setPort(port);
		con.connect();
		ReadMultipleRegistersRequest req = new ReadMultipleRegistersRequest(address, 1);
		req.setUnitID(slaveId);

		ModbusTCPTransaction trans = new ModbusTCPTransaction(con);

		trans.setRequest(req);

		trans.execute();

		ReadMultipleRegistersResponse res = (ReadMultipleRegistersResponse) trans.getResponse();
		
		data = res.getRegisterValue(0);

		con.close();
	} catch (Exception e) {
		e.printStackTrace();
	}

	return data;
}
 

开发者ID:Dn9x,
项目名称:dn-modbus,
代码行数:31,
代码来源:ModbusUtil.java

示例4: decodeEnergyMultiplier

点赞 2

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
/**
 * Decodes the energy multiplier configured on the meter, which really means
 * whether the energy value returned is in Wh, kWh, or MWh.
 * 
 * @param response
 *          The response from the meter containing the power and energy
 *          format.
 * @return A double that represents the scale which energy readings should be
 *         multiplied by, or 0 if there was some problem decoding the value.
 */
private double decodeEnergyMultiplier(ReadMultipleRegistersResponse response) {
  if (response != null && response.getWordCount() == 1) {
    // From Shark manual, bitmap looks like this ("-" is unused bit
    // apparently):
    // ppppiinn feee-ddd
    //
    // pppp = power scale (0-unit, 3-kilo, 6-mega, 8-auto)
    // ii = power digits after decimal point (0-3),
    // applies only if f=1 and pppp is not auto
    // nn = number of energy digits (5-8 --> 0-3)
    // eee = energy scale (0-unit, 3-kilo, 6-mega)
    // f = decimal point for power
    // (0=data-dependant placement, 1=fixed placement per ii value)
    // ddd = energy digits after decimal point (0-6)

    // Get energy scale by shifting off 4 bits and then mask with 111
    int energyScale = (response.getRegisterValue(0) >>> 4) & 7;
    switch (energyScale) {
    case 0:
      // watts
      return 1.0;
    case 3:
      // kilowatts
      return 1000.0;
    case 6:
      // megawatts
      return 1000000.0;
    default:
      // should never happen, according to manual, so return 0
      // System.err.println("Unknown energy scale from meter, defaulting to kWh");
      return 0.0;
    }
  }
  else {
    return 0.0;
  }
}
 

开发者ID:wattdepot,
项目名称:wattdepot,
代码行数:48,
代码来源:SharkCollector.java

示例5: extractByteArray

点赞 2

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
/**
 * Given a response with two consecutive registers, extract the values as a 4
 * byte array so they can be passed to methods in ModbusUtil. It seems like
 * there should be a better way to do this.
 * 
 * @param response
 *          The response containing the two registers
 * @return a byte[4] array or null if there is a problem with the response.
 */
private byte[] extractByteArray(ReadMultipleRegistersResponse response) {
  byte[] regBytes = new byte[4];
  if (response.getWordCount() == 2) {
    regBytes[0] = response.getRegister(0).toBytes()[0];
    regBytes[1] = response.getRegister(0).toBytes()[1];
    regBytes[2] = response.getRegister(1).toBytes()[0];
    regBytes[3] = response.getRegister(1).toBytes()[1];
    return regBytes;
  }
  else {
    return null;
  }
}
 

开发者ID:wattdepot,
项目名称:wattdepot,
代码行数:23,
代码来源:SharkCollector.java

示例6: update

点赞 2

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
@Override
public void update(WagoBinding binding, String couplerName, int module) {
    if (!connect()) {
        logger.warn("coupler not connected.");
        return;
    }

    ModbusRequest request = new ReadMultipleRegistersRequest(offset, 4);
    transaction.setRequest(request);
    try {
        transaction.execute();
    } catch (Exception e) {
        logger.debug("update of channels failed: " + e.getMessage());
        return;
    }

    ReadMultipleRegistersResponse response = (ReadMultipleRegistersResponse) transaction.getResponse();
    if ((response.getTransactionID() != transaction.getTransactionID()) && !response.isHeadless()) {
        logger.debug("update of channels failed: invalid response.");
        return;
    }

    values[0] = response.getRegister(1).getValue() >> 4;
    values[1] = response.getRegister(3).getValue() >> 4;

    Collection<String> itemNames = binding.getItemNames();
    for (String itemName : itemNames) {
        binding.updateItemPWM(itemName, couplerName, module, values);
    }
}
 

开发者ID:openhab,
项目名称:openhab1-addons,
代码行数:31,
代码来源:FBCoupler.java

示例7: getDataLength

点赞 2

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
private int getDataLength(ModbusResponse response) {
	if (response instanceof ReadCoilsResponse) {
		return ((ReadCoilsResponse)response).getBitCount();
	}
	if (response instanceof ReadInputDiscretesResponse) {
		return ((ReadInputDiscretesResponse)response).getBitCount();
	}
	if (response instanceof ReadInputRegistersResponse) {
		return ((ReadInputRegistersResponse)response).getWordCount();
	}
	if (response instanceof ReadMultipleRegistersResponse) {
		return ((ReadMultipleRegistersResponse)response).getWordCount();
	}
	return 0;
}
 

开发者ID:therealchalz,
项目名称:softlogger,
代码行数:16,
代码来源:Device.java

示例8: readMultipleRegisters

点赞 1

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
/**
 * Reads a given number of registers from the slave.
 * <p/>
 * Note that the number of registers returned (i.e. array length)
 * will be according to the number received in the slave response.
 *
 * @param unitid the slave unit id.
 * @param ref the offset of the register to start reading from.
 * @param count the number of registers to be read.
 * @return a <tt>Register[]</tt> holding the received registers.
 * @throws ModbusException if an I/O error, a slave exception or
 *             a transaction error occurs.
 */
public synchronized Register[] readMultipleRegisters(int unitid, int ref, int count) throws ModbusException {
    m_ReadMultipleRegistersRequest.setUnitID(unitid);
    m_ReadMultipleRegistersRequest.setReference(ref);
    m_ReadMultipleRegistersRequest.setWordCount(count);
    m_Transaction.setRequest(m_ReadMultipleRegistersRequest);
    m_Transaction.execute();
    return ((ReadMultipleRegistersResponse) m_Transaction.getResponse()).getRegisters();
}
 

开发者ID:openhab,
项目名称:openhab1-addons,
代码行数:22,
代码来源:ModbusSerialMaster.java

示例9: readMultipleRegisters

点赞 1

import net.wimpi.modbus.msg.ReadMultipleRegistersResponse; //导入依赖的package包/类
/**
 * Reads a given number of registers from the slave.
 * <p/>
 * Note that the number of registers returned (i.e. array length)
 * will be according to the number received in the slave response.
 *
 * @param ref the offset of the register to start reading from.
 * @param count the number of registers to be read.
 * @return a <tt>Register[]</tt> holding the received registers.
 * @throws ModbusException if an I/O error, a slave exception or
 *             a transaction error occurs.
 */
public synchronized Register[] readMultipleRegisters(int ref, int count) throws ModbusException {
    m_ReadMultipleRegistersRequest.setReference(ref);
    m_ReadMultipleRegistersRequest.setWordCount(count);
    m_Transaction.setRequest(m_ReadMultipleRegistersRequest);
    m_Transaction.execute();
    return ((ReadMultipleRegistersResponse) m_Transaction.getResponse()).getRegisters();
}
 

开发者ID:openhab,
项目名称:openhab1-addons,
代码行数:20,
代码来源:ModbusUDPMaster.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)