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

Read negative values #168

Open
thalesmaoa opened this issue Jan 27, 2022 · 8 comments
Open

Read negative values #168

thalesmaoa opened this issue Jan 27, 2022 · 8 comments

Comments

@thalesmaoa
Copy link

Hi there, I just need help to understand if I'm facing a bug, or if this is an equipment problem.
I have a Yg889E and I've implemented the modbus communication with ESP8266. I followed this link to help me through.

However, when the multimeter shows negative values, I don't receive negative values. I tried to evaluate if it is a code problem or if this is a hardware problem.

For example, here is part of my code:

union { uint32_t x; float f;} u;         // These codes required to merge 2 x 16 bits (2 register addresses into 1 float number
float z = u.f;

Serial.println("Real Power (W) per phase :");
u.x = ((unsigned long)node.getResponseBuffer(39) << 16) | node.getResponseBuffer(40); 
z = u.f; Pa = ( bitRead( node.getResponseBuffer(39), 15) ? z : z); Serial.print(Pa); Serial.print("; ");

u.x = ((unsigned long)node.getResponseBuffer(41) << 16) | node.getResponseBuffer(42); 
z = u.f; Pb = ( bitRead( node.getResponseBuffer(41), 15) ? z : z); Serial.print(Pb); Serial.print("; ");

u.x = ((unsigned long)node.getResponseBuffer(43) << 16) | node.getResponseBuffer(44); 
z = u.f; Pc = z; Serial.print(Pc); Serial.print("; ");

Using ModbusMaster, the bytes conversion using union is correct, however, I'm not sure if is the equipment, or if this is ModbusMaster.
In order to avoid to umount the system, I'm asking here first, maybe someone already faced similar problem with negative values.

@Frtrillo
Copy link

Frtrillo commented Feb 8, 2022

Yes, I have same issue when reading negative number because it converts the bit that indicates positive or negative to a whole number

@thalesmaoa
Copy link
Author

@Frtrillo, how are you dealing with it?

@Frtrillo
Copy link

Frtrillo commented Feb 8, 2022

@Frtrillo, how are you dealing with it?

Its a workaround but when I get negative values, I do a simple substraction, "modbusvalue"-65536.

@thalesmaoa
Copy link
Author

But how do you know that the values are negative?

@Frtrillo
Copy link

But how do you know that the values are negative?

Thats up to you, I do it because I know the ranges I should read, so If its value <-10000, I do the substraction

@thalesmaoa
Copy link
Author

thalesmaoa commented Feb 12, 2022

This a problem is with the meter or with the lib?

@Rambus100lica
Copy link

Hi,
I have same problem. The case is that sign is held in third register and I don't know how to read three registers and make a value from them

@thalesmaoa
Copy link
Author

This repo is old. Does anyone suggest a new one?

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

3 participants