Class ConversionHelper
- java.lang.Object
-
- com.smartgridready.communicator.modbus.helper.ConversionHelper
-
public class ConversionHelper extends java.lang.ObjectA helper class for value conversion.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean[]byteArrToBooleanArr(byte[] bytes)Converts a byte array to a boolean array.static java.nio.ByteBufferbyteBufFromRegisters(int[] intArr)Converts Modbus registers to a byte buffer.static int[]bytesToRegisters(byte[] bytes)Converts a byte array to Modbus registers.static java.lang.StringconvRegistersToString(int[] registers, int offset, int stringLength)Converts 16 - Bit Register values to Stringstatic int[]convStringToRegisters(java.lang.String stringToConvert)Converts a String to 16 - Bit Registersstatic int[]doubleToRegisters(double dVal)Converts a double value to four Modbus registers.static int[]floatToRegisters(float fVal)Converts a float value to two Modbus registers.static int[]intToRegisters(int value)Converts an int value to two Modbus registers.static int[]longToRegisters(long lVal)Converts a long value to four Modbus registers.static int[]shortToRegister(short value)Converts a short value to a Modbus register.static byte[]toByteArray(int value)Converts an int to a byte array.static int[]uintToRegisters(long value)Converts an unsigned int value to two Modbus registers.static int[]unsignedLongToRegister(java.math.BigInteger value)Converts an unsigned long value to four Modbus registers.
-
-
-
Method Detail
-
bytesToRegisters
public static int[] bytesToRegisters(byte[] bytes)
Converts a byte array to Modbus registers. Each two bytes become a register value.- Parameters:
bytes- the byte array to convert.- Returns:
- an array of int
-
byteBufFromRegisters
public static java.nio.ByteBuffer byteBufFromRegisters(int[] intArr)
Converts Modbus registers to a byte buffer.- Parameters:
intArr- the Modbus register values- Returns:
- an instance of
ByteBuffer
-
floatToRegisters
public static int[] floatToRegisters(float fVal)
Converts a float value to two Modbus registers.- Parameters:
fVal- the value to convert- Returns:
- an array of int
-
doubleToRegisters
public static int[] doubleToRegisters(double dVal)
Converts a double value to four Modbus registers.- Parameters:
dVal- the value to convert- Returns:
- an array of int
-
longToRegisters
public static int[] longToRegisters(long lVal)
Converts a long value to four Modbus registers.- Parameters:
lVal- the value to convert- Returns:
- an array of int
-
unsignedLongToRegister
public static int[] unsignedLongToRegister(java.math.BigInteger value)
Converts an unsigned long value to four Modbus registers.- Parameters:
value- the value to convert- Returns:
- an array of int
-
intToRegisters
public static int[] intToRegisters(int value)
Converts an int value to two Modbus registers.- Parameters:
value- the value to convert- Returns:
- an array of int
-
uintToRegisters
public static int[] uintToRegisters(long value)
Converts an unsigned int value to two Modbus registers.- Parameters:
value- the value to convert- Returns:
- an array of int
-
shortToRegister
public static int[] shortToRegister(short value)
Converts a short value to a Modbus register.- Parameters:
value- the value to convert- Returns:
- an array of int
-
convRegistersToString
public static java.lang.String convRegistersToString(int[] registers, int offset, int stringLength)Converts 16 - Bit Register values to String- Parameters:
registers- Register array received via Modbusoffset- First Register containing the String to convertstringLength- number of characters in String (must be even)- Returns:
- Converted String
-
convStringToRegisters
public static int[] convStringToRegisters(java.lang.String stringToConvert)
Converts a String to 16 - Bit Registers- Parameters:
stringToConvert- String to Convert- Returns:
- Converted String
-
toByteArray
public static byte[] toByteArray(int value)
Converts an int to a byte array.- Parameters:
value- the value to convert- Returns:
- a byte array
-
byteArrToBooleanArr
public static boolean[] byteArrToBooleanArr(byte[] bytes)
Converts a byte array to a boolean array. Each element is true if the byte value is not zero.- Parameters:
bytes- the byte array to convert- Returns:
- an array of boolean
-
-