Skip to content
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

Closed
RottenVanSuti opened this issue Apr 18, 2019 · 6 comments
Closed

Strange float value reading #22

RottenVanSuti opened this issue Apr 18, 2019 · 6 comments

Comments

@RottenVanSuti
Copy link

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
I attached a image with the modbus addresses. I use addresses from 350 to 355
image

@sourceperl
Copy link
Owner

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).

@RottenVanSuti
Copy link
Author

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

@RottenVanSuti
Copy link
Author

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?

@sourceperl
Copy link
Owner

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))

@RottenVanSuti
Copy link
Author

Thank you @sourceperl , it worked

@sourceperl
Copy link
Owner

I'm glad to hear that !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants