Class ModbusUtils
java.lang.Object
io.openems.edge.bridge.modbus.api.ModbusUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
byteArrayToHexString
(byte[] data) Converts a byte array to a String in the form "00C1 00B2".static Short
convert
(int value, int upperBytes) Converts upper/lower bytes to Short.static String
intToHexString
(int data) Converts a int to a String in the form "00C1".static <T> CompletableFuture
<T> readELementOnce
(ModbusProtocol modbusProtocol, ModbusRegisterElement<?, T> element, boolean tryAgainOnError) Reads given Element once from Modbus.static <T> CompletableFuture
<List<T>> readELementsOnce
(ModbusProtocol modbusProtocol, ModbusRegisterElement<?, T>[] elements, boolean tryAgainOnError) 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".
-
Constructor Details
-
ModbusUtils
public ModbusUtils()
-
-
Method Details
-
readELementOnce
public static <T> CompletableFuture<T> readELementOnce(ModbusProtocol modbusProtocol, ModbusRegisterElement<?, T> element, boolean tryAgainOnError) throws OpenemsExceptionReads given Element once from Modbus.- Type Parameters:
T
- the Type of the element- Parameters:
modbusProtocol
- theModbusProtocol
, that is linked with aBridgeModbus
element
- theModbusRegisterElement
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 theModbusProtocol
object
-
readELementsOnce
public static <T> CompletableFuture<List<T>> readELementsOnce(ModbusProtocol modbusProtocol, ModbusRegisterElement<?, T>[] elements, boolean tryAgainOnError) throws OpenemsExceptionReads given Elements once from Modbus.- Type Parameters:
T
- the Type of the elements- Parameters:
modbusProtocol
- theModbusProtocol
, that is linked with aBridgeModbus
elements
- theModbusRegisterElement
stryAgainOnError
- 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 theModbusProtocol
object
-
convert
Converts upper/lower bytes to Short.- Parameters:
value
- the int valueupperBytes
- 1 = upper two bytes, 0 = lower two bytes- Returns:
- the Short
-
byteArrayToHexString
Converts a byte array to a String in the form "00C1 00B2".- Parameters:
data
- byte array- Returns:
- string
-
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
-