-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
None
-
x86_64
-
windows
A DESCRIPTION OF THE PROBLEM :
byte[] hexData = new byte[] { 0x01, 0x03, 0x04, 0x02, (byte)0x92, (byte) 0xFF, (byte)0x9B, 0x5A, 0x3D };
but when you use it, you should use
hexData[5]&0xFF
but in many ways, like use java.io.DataInputStream.readShort(); to read the hexData[5] hexData[6] (0x92FF)
you will read a wrong value, because in JVM, hexData[5] = (byte)0x92‘s value is
0xffffffffffffff92
in Modbus-RTU, the byte array handle is usual.
And I has no other way to handle it, only to override java.io.DataOutputStream's read() using that code
@Override
public int read() throws IOException {
return super.read()&0xFF;
}
Java really do no want to handle byte array, because it is no so convenient as C/Cpp or other language.
byte[] hexData = new byte[] { 0x01, 0x03, 0x04, 0x02, (byte)0x92, (byte) 0xFF, (byte)0x9B, 0x5A, 0x3D };
but when you use it, you should use
hexData[5]&0xFF
but in many ways, like use java.io.DataInputStream.readShort(); to read the hexData[5] hexData[6] (0x92FF)
you will read a wrong value, because in JVM, hexData[5] = (byte)0x92‘s value is
0xffffffffffffff92
in Modbus-RTU, the byte array handle is usual.
And I has no other way to handle it, only to override java.io.DataOutputStream's read() using that code
@Override
public int read() throws IOException {
return super.read()&0xFF;
}
Java really do no want to handle byte array, because it is no so convenient as C/Cpp or other language.