Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. PF Reading Is Wrong With C Library.

PF reading is wrong with C library.

Forum Rules

Before commenting read Forum rules

Don't comment the topic if you have a new question.

You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.

By ayush , 27 May, 2021
Forums
Gurux.DLMS

Hi,
When i am decoding PF value with the C libraray its giving wrong value, but the same response if I am decoding in the DLMS translator its showing correct there. Can you pls tell me why its happening below is the data.

cmd: 7e a0 1a 02 a1 21 32 a2 cb e6 e6 00 c0 01 81 00 03 01 01 49 07 00 ff 02 00 97 73 7e
Response: 7e a0 13 21 02 a1 52 21 3f e6 e7 00 c4 01 81 00 0f aa 7d 5e 7e
Received data 1.1.73.7.0.255 , 2:
Value : 170 (actual data is -86)
Value in HEX: aa

cmd:7e a0 1a 02 a1 21 54 92 cd e6 e6 00 c0 01 81 00 03 01 01 49 07 00 ff 03 00 4f 6a 7e
Response: 7e a0 17 21 02 a1 74 05 56 e6 e7 00 c4 01 81 00 02 02 0f fe 16 ff 38 db 7e
Scaler : -2

Converted value : 1.70

Thank you.

ayush

5 years ago

Hi can you please update on

Hi can you please update on this please.

Profile picture for user Kurumi

Kurumi

5 years ago

Hi,

Hi,

You are reading different attributes. In the first command, you are reading attribute #2 (Value) and in the second you are reading attribute #3 (Scaler and unit).

Read the same attribute index and the values are the same.
BR,
Mikko

ayush

5 years ago

In reply to Hi, by Kurumi

Hi,

Hi,
Thanks for your reply. If you see the below data its coming proper for other PF. As per my observation whenever PF is in -ve value that time only this wrong conversion is happening from the resp.

cmd : 7e a0 1a 02 a1 21 fe c2 c7 e6 e6 00 c0 01 81 00 03 01 01 35 07 00 ff 02 00 62 87 7e
Resp: 7e a0 13 21 02 a1 1e 49 b7 e6 e7 00 c4 01 81 00 11 26 98 1f 7e
Value : 38
Value in HEX: 26

cmd: 7e a0 1a 02 a1 21 10 b2 c9 e6 e6 00 c0 01 81 00 03 01 01 35 07 00 ff 03 00 ba 9e 7e
resp: 7E A0 17 21 02 A1 30 25 52 E6 E7 00 C4 01 81 00 02 02 0F FE 16 FF 38 DB 7E
Scaler : -2

Converted Value : o.38

Profile picture for user Kurumi

Kurumi

5 years ago

Hi,

Hi,

ANSI C doesn't multiply the value with scaler for you. You must do it by yourself. The reason is that memory footprint is kept as small as possible.

BR,
Mikko

ayush

5 years ago

Hi,

Hi,
I think we are getting confused with the topic of conversation. I will start once again from the top to clarify my doubt.

cmd: 7e a0 1a 02 a1 21 32 a2 cb e6 e6 00 c0 01 81 00 03 01 01 49 07 00 ff 02 00 97 73 7e
Response: 7e a0 13 21 02 a1 52 21 3f e6 e7 00 c4 01 81 00 0f aa 7d 5e 7e

Above are the command and responses to collect one of the Power factor from the meter with OBIS 1.1.73.7.0.255.
In the meter display power factor for this particular OBIS is coming as "-0.86", but from the DLMS library after converting the response command (7e a0 13 21 02 a1 52 21 3f e6 e7 00 c4 01 81 00 0f aa 7d 5e 7e) the value is coming as "170" instead of "-86" in reg.value.lVal.

This is happening only when there is a negative power factor.
We are using the same DLMS library which has been purchased from Gurux.

Please clarify where this conversion is happening in DLMS library and how can we make it convert properly.

below is the code snippet for your reference.
if (requestType == DLMS_OBJECT_TYPE_REGISTER)
{
delay_us(100);
queryStatus = com_read(&con, &reg.base, 2);
if(queryStatus == 0)
{
debug_print("\r\nReceived data %s , 2: ",dlmsDevice->oidList.oid[oididx]);
debug_print("\r\nValue : %d\r\n",reg.value.lVal); // Here its coming 170 instead of -86
for(pIdx=0;pIdx<con.data.size;pIdx++)
{
debug_print("%02X ",con.data.data[pIdx]);
}
debug_puts("\n");
}

if(queryStatus == 0)
{
queryStatus1 = com_read(&con, &reg.base, 3);
if(queryStatus1 == 0)
{
debug_print("\r\nReceived data %s , 3: ",dlmsDevice->oidList.oid[oididx]);
debug_print("\r\nScaler : %d\r\n",reg.scaler);
for(pIdx=0;pIdx<con.data.size;pIdx++)
{
debug_print("%02X ",con.data.data[pIdx]);
}
debug_puts("\n");
}
}
}

Profile picture for user Kurumi

Kurumi

5 years ago

Hi,

Hi,

Please create a ticket, If you have purchased the stack. You get an answer faster.

I tested this and I get value -86 like below.

Index: 3 Value: Scaler: 0.010000 Unit: NoUnit
Index: 2 Value: -86

How you try to convert it?

BR,
Mikko

Profile picture for user Kurumi

Kurumi

5 years ago

Hi,

Hi,

Please, don't update the existing question. It's hard to find the updated questions.

Your value is a signed byte and you can get it from .cVal, not lVal.
You can get value as an integer using var_toInteger -method.

Something like this:
debug_print("\r\nValue : %d\r\n", var_toInteger(&reg.value));

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin