-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get "CD AB" order from ByteBuf? #8
Comments
I'm not sure what that software would consider the order to be by default (maybe DC BA), but try something like this: short cd = Short.reverseBytes(buffer.readShort());
short ab = Short.reverseBytes(buffer.readShort());
float f = Float.intBitsToFloat((cd << 16) | ab); Assuming the buffer contains at least 4 bytes (meaning you read at least 2 registers, because each register is 16-bit). |
@kevinherron Thank you for your reply. I'm trying using your code, but I got the value equal to order BA DC rather than CD AB. Is it because of different default order? |
Maybe this then? short ab = buffer.readShort();
short cd = buffer.readShort();
float f = Float.intBitsToFloat((cd << 16 | ab)); |
It works! Thanks! |
How can I get a "CD AB" ordered float from ByteBuf? Like:
I know very little about modbus. Can you please help me? Thanks.
The text was updated successfully, but these errors were encountered: