Class ModbusUtils

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

public class ModbusUtils extends Object
  • Constructor Details

    • ModbusUtils

      public ModbusUtils()
  • Method Details

    • retryOnNull

      public static <T> boolean retryOnNull(Task.ExecuteState executeState, T value)
      Predefined `retryPredicate` that triggers a retry whenever `value` is null, i.e. on any error.
      Type Parameters:
      T - the Type of the element
      Parameters:
      executeState - the Task Task.ExecuteState
      value - the value
      Returns:
      true for retry
    • doNotRetry

      public static <T> boolean doNotRetry(Task.ExecuteState executeState, T value)
      Predefined `retryPredicate` that never retries.
      Type Parameters:
      T - the Type of the element
      Parameters:
      executeState - the Task Task.ExecuteState
      value - the value
      Returns:
      always false
    • readElementOnce

      public static <T> CompletableFuture<T> readElementOnce(ModbusProtocol modbusProtocol, BiPredicate<Task.ExecuteState,T> retryPredicate, ModbusRegisterElement<?,T> element)
      Reads given Element once from Modbus.
      Type Parameters:
      T - the Type of the element
      Parameters:
      modbusProtocol - the ModbusProtocol, that is linked with a BridgeModbus
      retryPredicate - yield true to retry reading values; false otherwise. Parameters are the Task.ExecuteState of the entire task and the individual element value
      element - the ModbusRegisterElement
      Returns:
      a future value, e.g. a Integer or null (if tryAgainOnError is false)
    • readElementsOnce

      @SafeVarargs public static <T> CompletableFuture<ModbusUtils.ReadElementsResult<T>> readElementsOnce(ModbusProtocol modbusProtocol, BiPredicate<Task.ExecuteState,T> retryPredicate, ModbusRegisterElement<?,T>... elements)
      Reads given Elements once from Modbus.
      Type Parameters:
      T - the Type of the elements
      Parameters:
      modbusProtocol - the ModbusProtocol, that is linked with a BridgeModbus
      retryPredicate - yield true to retry reading values. Parameters are the Task success state and individual element value
      elements - the ModbusRegisterElements
      Returns:
      a future array of values, e.g. Integer[] or null. If an array is returned, it is guaranteed to have the same length as `elements`
    • 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