public final class ModbusByteUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static short |
computeCrc(byte[] data,
int start,
int end)
Compute a 16-bit cyclic redundancy check (CRC) value from a range of
bytes.
|
static short[] |
decode(byte[] data)
Get raw data as signed 16-bit values.
|
static short[] |
decode(byte[] data,
int start,
int end)
Get raw data as signed 16-bit values.
|
static byte[] |
decodeHexPadStart(char[] chars)
Convert a hex-encoded string to a byte array.
|
static byte[] |
decodeHexString(String s)
Convert a hex-encoded string to a byte array.
|
static int[] |
decodeUnsigned(byte[] data)
Get raw data as unsigned 16-bit values.
|
static int[] |
decodeUnsigned(byte[] data,
int start,
int end)
Get raw data as unsigned 16-bit values.
|
static byte[] |
encode(short[] registers)
Get raw data from unsigned 16-bit values.
|
static void |
encode(short[] registers,
byte[] dest,
int offset)
Get raw data from unsigned 16-bit values.
|
static void |
encode16(byte[] data,
int offset,
int value)
Encode a 16-bit value into a byte array.
|
static char[] |
encodeChar(byte b,
char[] toDigits,
char[] dest,
int destIndex)
Encode a single byte as a character.
|
static String |
encodeHexString(byte[] data,
int fromIndex,
int toIndex)
Encode a byte array into a hex-encoded upper-case string without spaces.
|
static String |
encodeHexString(byte[] data,
int fromIndex,
int toIndex,
boolean space)
Encode a byte array into a hex-encoded upper-case string.
|
static String |
encodeHexString(byte[] data,
int fromIndex,
int toIndex,
boolean space,
boolean lowerCase)
Encode a byte array into a hex-encoded string.
|
static byte[] |
encodeUnsigned(int[] registers)
Get raw data from unsigned 16-bit values.
|
static void |
reverse(byte[] data)
Reverse a byte array.
|
public static short computeCrc(byte[] data,
int start,
int end)
data - the data to compute the CRC valuestart - the starting index (inclusive)end - the ending index (exclusive)public static char[] encodeChar(byte b,
char[] toDigits,
char[] dest,
int destIndex)
b - the byte to encodetoDigits - the alphabet to usedest - the destination character buffer to write the encoded char todestIndex - the index within dest to write the encoded char at, along
with destIndex + 1dest arraypublic static byte[] decodeHexString(String s)
If the string does not have an even number of characters, a 0 will be inserted at the start of the string.
s - the string to decodedecodeHexPadStart(char[])public static byte[] decodeHexPadStart(char[] chars)
If the string does not have an even number of characters, a 0 will be inserted at the start of the string.
chars - the characters to decodepublic static String encodeHexString(byte[] data, int fromIndex, int toIndex)
data - the data to encode as hex stringsfromIndex - the starting index within data to encode (inclusive)toIndex - the ending index within data to encode (exclusive)public static String encodeHexString(byte[] data, int fromIndex, int toIndex, boolean space)
data - the data to encode as hex stringsfromIndex - the starting index within data to encode (inclusive)toIndex - the ending index within data to encode (exclusive)space - true to add a single space character between each hexpublic static String encodeHexString(byte[] data, int fromIndex, int toIndex, boolean space, boolean lowerCase)
data - the data to encode as hex stringsfromIndex - the starting index within data to encode (inclusive)toIndex - the ending index within data to encode (exclusive)space - true to add a single space character between each hexlowerCase - true to use lower case, false for upper case
pairpublic static byte[] encode(short[] registers)
registers - the 16-bit register values, treated as unsigned valuesregisters is
nullpublic static void encode(short[] registers,
byte[] dest,
int offset)
registers - the 16-bit register values, treated as unsigned valuesdest - the destination dataoffset - the offset within dest to start atpublic static byte[] encodeUnsigned(int[] registers)
registers - the 16-bit register values, treated as unsigned 16-bit valuesregisters is
nullpublic static short[] decode(byte[] data)
data - the datadata is nullpublic static short[] decode(byte[] data,
int start,
int end)
data - the datastart - the starting offset with data, inclusiveend - the ending offset with data, exclusivedata is nullpublic static int[] decodeUnsigned(byte[] data)
data - the datadata is nullpublic static int[] decodeUnsigned(byte[] data,
int start,
int end)
data - the datastart - the starting offset with data, inclusiveend - the ending offset with data, exclusivedata is nullpublic static void reverse(byte[] data)
This modifies the contents of the array directly.
data - the data to reversepublic static void encode16(byte[] data,
int offset,
int value)
data - the data arrayoffset - the offset within data to start populatingvalue - the value to populate