-
-
Notifications
You must be signed in to change notification settings - Fork 241
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
Swapped float point #506
Comments
Hi any updates on this I have a similar use case ? |
try not to swapBytes yourself, find a buffer to float method, that swap it for you: |
Sorry not able to get your point, my usecase is |
here is an example: you need to remove the a. test that the raw data you get is the same the one in modscan, e.g. hex in modscan, and see that the hex value are the same for the same address. |
yes I tried these methods already but all of these return a 32 bit int value whereas I wanted it to be something of sort decimal like |
have you tried |
yes I tried returns same 32 bit |
|
I'm adding a help wanted because your problem sound very weird this is how 240.324 looks fp and swapped fp: in your example I can't find a 2 registrar (32 bit) hex that can represent a 0 to 1000 number using swapped fp (readFloatLE) assuming this is the same hex input used by modscan, I'm adding a help wanted in case someone knows what the issue is |
I pasted a console output of data being received from the meter device from which I want to infer the floating voltage value, |
const hexString = 'ab85000000000000000042a3c7ae4375ab850000';
const buf = Buffer.from(hexString, 'hex');
for (let i = 0; i < buf.length - 3; i++) {
const floatValue = buf.readFloatLE(i);
if (floatValue >= 0 && floatValue <= 1000) {
console.log(`Found float value ${floatValue} at position ${i}`);
}
} hmm, i can actually find some numbers:
|
so using your input in position 11 we have somthing that looks like usefull data ... |
Historically Modbus RTU was designed only for integer value type using 2-byte 'registers', so there was no definite specification for 4-byte IEEE-754 floating point values. As the result, there are 4 different ways to interpret/convert bytes buffer into IEEE-754 floating point values, see for example settings in the Modbus Poll tool: Also Modbus RTU uses "Register numbering" starting from 1 while the actual addressing starts from 0, e.g. Register 30001 means that Modbus RTU reading address should be set to 0 (3xxxx means using "Read Input Registers" command) - this also may lead to incorrect data reading/conversion. There is a very handy conversion tool https://www.h-schmidt.net/FloatConverter/IEEE754.html that can be used to try different combinations of bytes (from your data buffer) and see which one makes sense. For some reason your example buffer is not multiple of 4x - either there is an additional one byte or missing three bytes. |
I am using this library for a while reading floating points values from our instruments, so please consider the following that may be helpful in your case:
|
Hello, I tried to convert the data result to swapped float point but it did not work .
This is the result using modscan32.
My code
How to get data result in swapped float point. Please advise this
The text was updated successfully, but these errors were encountered: