|
jamod at SF | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.wimpi.modbus.util.ModbusUtil
Helper class that provides utility methods.
Constructor Summary | |
ModbusUtil()
|
Method Summary | |
static int[] |
calculateCRC(byte[] data,
int offset,
int len)
|
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)
|
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)
|
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 java.lang.String |
toHex(byte[] data)
Returns the given byte[] as hex encoded string. |
static java.lang.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 java.lang.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). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ModbusUtil()
Method Detail |
public static final java.lang.String toHex(ModbusMessage msg)
msg
- the message to be converted.
public static final java.lang.String toHex(byte[] data)
data
- a byte[] array.
public static final java.lang.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].
DataInput
public 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
-
DataOutput
public 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
-
public 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
-
public static final byte hiByte(int wd)
wd
-
public static final int makeWord(int hibyte, int lowbyte)
hibyte
- lowbyte
-
public static final int[] calculateCRC(byte[] data, int offset, int len)
|
jamod at SF | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |