Class ModbusUtils

java.lang.Object
io.openems.edge.bridge.modbus.api.ModbusUtils

public class ModbusUtils extends Object
  • Constructor Details

    • ModbusUtils

      public ModbusUtils()
  • Method Details

    • readELementOnce

      public static <T> CompletableFuture<T> readELementOnce(ModbusProtocol modbusProtocol, ModbusRegisterElement<?,T> element, boolean tryAgainOnError) throws OpenemsException
      Reads given Element once from Modbus.
      Type Parameters:
      T - the Type of the element
      Parameters:
      modbusProtocol - the ModbusProtocol, that is linked with a BridgeModbus
      element - the ModbusRegisterElement
      tryAgainOnError - if true, tries to read till it receives a value; if false, stops after first try and possibly return null
      Returns:
      a future value, e.g. a Integer or null (if tryAgainOnError is false)
      Throws:
      OpenemsException - on error with the ModbusProtocol object
    • readELementsOnce

      public static <T> CompletableFuture<List<T>> readELementsOnce(ModbusProtocol modbusProtocol, ModbusRegisterElement<?,T>[] elements, boolean tryAgainOnError) throws OpenemsException
      Reads given Elements once from Modbus.
      Type Parameters:
      T - the Type of the elements
      Parameters:
      modbusProtocol - the ModbusProtocol, that is linked with a BridgeModbus
      elements - the ModbusRegisterElements
      tryAgainOnError - if true, tries to read till it receives a value on first register; if false, stops after first try and possibly return null
      Returns:
      a future array of values, e.g. Integer[] or null (if tryAgainOnError is false). If an array is returned, it is guaranteed to have the same length as `elements`
      Throws:
      OpenemsException - on error with the ModbusProtocol object
    • convert

      public static Short convert(int value, int upperBytes)
      Converts upper/lower bytes to Short.
      Parameters:
      value - the int value
      upperBytes - 1 = upper two bytes, 0 = lower two bytes
      Returns:
      the Short
    • byteArrayToHexString

      public static String byteArrayToHexString(byte[] data)
      Converts a byte array to a String in the form "00C1 00B2".
      Parameters:
      data - byte array
      Returns:
      string
    • intToHexString

      public static String intToHexString(int data)
      Converts a int to a String in the form "00C1".
      Parameters:
      data - byte array
      Returns:
      string
    • registersToHexString

      public static String registersToHexString(com.ghgande.j2mod.modbus.procimg.Register... registers)
      Converts a Register array to a String in the form "00C1 00B2".
      Parameters:
      registers - Register array
      Returns:
      string
    • registersToHexString

      public static String registersToHexString(com.ghgande.j2mod.modbus.procimg.InputRegister... registers)
      Converts a InputRegister array to a String in the form "00C1 00B2".
      Parameters:
      registers - InputRegister array
      Returns:
      string