public class ModbusUtil extends Object
| 构造器和说明 |
|---|
ModbusUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
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 String |
toHex(byte[] data) |
static String |
toHex(byte[] data,
int off,
int length) |
static byte[] |
toHex(int i)
Returns a byte[] containing the given byte as unsigned hexadecimal
number digits.
|
static int[] |
toIntArray(String[] values) |
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 int[] toIntArray(String[] values)
public static final String toHex(byte[] data)
public static final String toHex(byte[] data, int off, int length)
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 - DataOutputpublic 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 - Copyright © 2019. All Rights Reserved.