-
Notifications
You must be signed in to change notification settings - Fork 102
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
Strange float value reading #22
Comments
Hi, your document say data type is long for address 350 to 355. So, it's probably not float but 32 bits signed int. To deal with 32 bits you can use utils module (online doc). |
Thank you @sourceperl , I'm sorry, you're right, I got confused Long variable with Float, now I get the correct vaues. However, there some negative values in the energy meter that seems they can not be handle with the library, because when I print the result, it shows the max value of the 16bit register, no the negative value |
I'm sorry, I've been reading about the" two complement" utils. This is the function that I should use for the Long (signed) values, right? |
You can use pyModbusTCP.utils.get_2comp for deal with 2's complement integer. In your case, since your registers are long, you have to set val_size parameter to 32. Like this: from pyModbusTCP import utils
# 2's complement decode of 0xFFFFFFFF will give you -1
print(utils.get_2comp(0xFFFFFFFF, val_size=32)) |
Thank you @sourceperl , it worked |
I'm glad to hear that ! |
Hi @sourceperl I've been testing some Holding register readings with uint and int values from a energy meter and is ok, but there some values in float format. When I try to read the float values, the result is a very small number (for example, 3.44533e-35) and does not match the real value that's shown in the energy meter (let's say it shows 35.23 kW). I've used as guide the TCP float example. I don't know if this problem is related to the equipment
![image](https://user-images.githubusercontent.com/37563944/56375597-a1a96780-61cb-11e9-9ac7-2cb6a46e5352.png)
I attached a image with the modbus addresses. I use addresses from 350 to 355
The text was updated successfully, but these errors were encountered: