public final class ModbusUtil extends Object
| Constructor and Description |
|---|
ModbusUtil() |
| Modifier and Type | Method and Description |
|---|---|
static int[] |
calculateCRC(byte[] data,
int offset,
int len)
Calculate crc int [ ].
|
static int |
calculateLRC(byte[] data,
int off,
int len)
Calculate lrc int.
|
static byte[] |
doubleToRegisters(double d)
Converts a double value to a byte[8].
|
static byte[] |
floatToRegisters(float f)
Converts a float value to a byte[4] binary float value.
|
static byte |
hiByte(int wd)
Hi byte byte.
|
static byte[] |
intToRegisters(int v)
Converts an int value to a byte[4] array.
|
static byte[] |
longToRegisters(long v)
Converts a long value to a byte[8].
|
static byte |
lowByte(int wd)
Returs the low byte of an integer word.
|
static int |
makeWord(int hibyte,
int lowbyte)
Make word int.
|
static double |
registersToDouble(byte[] bytes)
Converts a byte[8] binary double value into a double primitive.
|
static float |
registersToFloat(byte[] bytes)
Converts a byte[4] binary float value to a float primitive.
|
static int |
registersToInt(byte[] bytes)
Converts a byte[4] binary int value to a primitive int.
|
static long |
registersToLong(byte[] bytes)
Converts a byte[8] binary long value into a long
primitive.
|
static short |
registerToShort(byte[] bytes)
Converts the given register (16-bit value) into
a short.
|
static short |
registerToShort(byte[] bytes,
int idx)
Converts the register (16-bit value) at the given index
into a short.
|
static int |
registerToUnsignedShort(byte[] bytes)
Converts the register (a 16 bit value) into an unsigned short.
|
static byte[] |
shortToRegister(short s)
Converts the given short into a register
(2 bytes).
|
static String |
toHex(byte[] data)
Returns the given byte[] as hex encoded string.
|
static String |
toHex(byte[] data,
int off,
int length)
Returns a String containing unsigned hexadecimal
numbers as digits.
|
static byte[] |
toHex(int i)
Returns a byte[] containing the given
byte as unsigned hexadecimal number digits.
|
static String |
toHex(ModbusMessage msg)
Converts a ModbusMessage instance into
a hex encoded string representation.
|
static int |
unsignedByteToInt(byte b)
Converts an unsigned byte to an integer.
|
static byte[] |
unsignedShortToRegister(int v)
Converts the given unsigned short into a register
(2 bytes).
|
public static final String toHex(ModbusMessage msg)
msg - the message to be converted.public static final String toHex(byte[] data)
data - a byte[] array.public static final String toHex(byte[] data, int off, int length)
data - the array of bytes to be converted into a hex-string.off - the offset to start converting from.length - the number of bytes to be converted.String.public static final byte[] toHex(int i)
i - the int to be converted into a hex string.byte[].public static final int registerToUnsignedShort(byte[] bytes)
(((a & 0xff) << 8) | (b & 0xff))
This conversion has been taken from the documentation of
the DataInput interface.bytes - a register as byte[2].DataInputpublic static final byte[] unsignedShortToRegister(int v)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
This conversion has been taken from the documentation of the DataOutput interface.
v - the vDataOutputpublic static final short registerToShort(byte[] bytes)
(short)((a << 8) | (b & 0xff))
This conversion has been taken from the documentation of the DataInput interface.
bytes - bytes a register as byte[2].public static final short registerToShort(byte[] bytes,
int idx)
(short)((a << 8) | (b & 0xff))
This conversion has been taken from the documentation of the DataInput interface.
bytes - a byte[] containing a short value.idx - an offset into the given byte[].public static final byte[] shortToRegister(short s)
(byte)(0xff & (v >> 8))
(byte)(0xff & v)
s - the spublic static final int registersToInt(byte[] bytes)
(((a & 0xff) << 24) | ((b & 0xff) << 16) |
((c & 0xff) << 8) | (d & 0xff))
bytes - registers as byte[4].public static final byte[] intToRegisters(int v)
v - the value to be converted.public static final long registersToLong(byte[] bytes)
bytes - a byte[8] containing a long value.public static final byte[] longToRegisters(long v)
v - the value to be converted.public static final float registersToFloat(byte[] bytes)
bytes - the byte[4] containing the float value.public static final byte[] floatToRegisters(float f)
f - the float to be converted.public static final double registersToDouble(byte[] bytes)
bytes - a byte[8] to be converted.public static final byte[] doubleToRegisters(double d)
d - the double to be converted.public static final int unsignedByteToInt(byte b)
b - the byte to be converted.public static final byte lowByte(int wd)
wd - the wdpublic static final byte hiByte(int wd)
wd - the wdpublic static final int makeWord(int hibyte,
int lowbyte)
hibyte - the hibytelowbyte - the lowbytepublic static final int[] calculateCRC(byte[] data,
int offset,
int len)
data - the dataoffset - the offsetlen - the lenpublic static final int calculateLRC(byte[] data,
int off,
int len)
data - the dataoff - the offlen - the lenCopyright © 2017. All rights reserved.