Class ModbusUtils
java.lang.Object
io.openems.edge.bridge.modbus.api.ModbusUtils
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
doNotRetry
(Task.ExecuteState executeState, T value) Predefined `retryPredicate` that never retries.static String
intToHexString
(int data) Converts a int to a String in the form "00C1".static <T> CompletableFuture
<T> readElementOnce
(ModbusProtocol modbusProtocol, BiPredicate<Task.ExecuteState, T> retryPredicate, ModbusRegisterElement<?, T> element) Reads given Element once from Modbus.static <T> CompletableFuture
<ModbusUtils.ReadElementsResult<T>> readElementsOnce
(ModbusProtocol modbusProtocol, BiPredicate<Task.ExecuteState, T> retryPredicate, ModbusRegisterElement<?, T>... elements) Reads given Elements once from Modbus.static String
registersToHexString
(com.ghgande.j2mod.modbus.procimg.InputRegister... registers) Converts aInputRegister
array to a String in the form "00C1 00B2".static String
registersToHexString
(com.ghgande.j2mod.modbus.procimg.Register... registers) Converts aRegister
array to a String in the form "00C1 00B2".static <T> boolean
retryOnNull
(Task.ExecuteState executeState, T value) Predefined `retryPredicate` that triggers a retry whenever `value` is null, i.e.
-
Constructor Details
-
ModbusUtils
public ModbusUtils()
-
-
Method Details
-
retryOnNull
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 TaskTask.ExecuteState
value
- the value- Returns:
- true for retry
-
doNotRetry
Predefined `retryPredicate` that never retries.- Type Parameters:
T
- the Type of the element- Parameters:
executeState
- the TaskTask.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
- theModbusProtocol
, that is linked with aBridgeModbus
retryPredicate
- yield true to retry reading values; false otherwise. Parameters are theTask.ExecuteState
of the entire task and the individual element valueelement
- theModbusRegisterElement
- 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
- theModbusProtocol
, that is linked with aBridgeModbus
retryPredicate
- yield true to retry reading values. Parameters are the Task success state and individual element valueelements
- theModbusRegisterElement
s- 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
Converts a int to a String in the form "00C1".- Parameters:
data
- byte array- Returns:
- string
-
registersToHexString
Converts aRegister
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 aInputRegister
array to a String in the form "00C1 00B2".- Parameters:
registers
-InputRegister
array- Returns:
- string
-