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. Get Value From OBIS Code

Get Value From OBIS Code

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 Techapirant , 7 October, 2019
Forums
Gurux.DLMS

Hello,

I have compiled and able to successfully run Gurux DLMS Client Example [ C Language ] in Ubuntu 14.0 Linux.
I want to know how can I directly read value of register based on OBIS Code. Is there any function in C which I can use to read value of register say for Example ReadValue("1.0.14.7.0.255") -> Return Value.
I have tried below function
ret = com_read(connection, obj, 2);
but how can I get / Print value for Index 2 [ want only value not Index 2 : .....]using above function.

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

It depends what kind of object you want to read. If value is register or data you can access value like this:

gxRegister obj;
obj_init2(&obj, ...);
ret = com_read(connection, obj, 2);
int value = var_toInterger(&obj.value);

BR,

Mikko

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

I am getting below Error

I am getting below Error

Code:
gxRegister obj;
obj_init2(&obj,"1.0.14.7.0.255");
ret = com_read(connection, obj, 2);
int value = var_toInterger(&obj.value);
printf("%d", value);

Error
:~/Desktop/DLMS/GuruxDLMSClientExample$ make
src/main.c: In function ‘readSerialPort’:
src/main.c:209:1: warning: implicit declaration of function ‘obj_init2’ [-Wimplicit-function-declaration]
obj_init2(&obj,"1.0.14.7.0.255");
^
src/main.c:211:1: warning: implicit declaration of function ‘var_toInterger’ [-Wimplicit-function-declaration]
value = var_toInterger(&obj.value);
^
src/main.c:211:28: error: request for member ‘value’ in something not a structure or union
value = var_toInterger(&obj.value);
^
make: *** [obj/main.o] Error 1

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,
unsigned char ln[6] = {1,0,14,7,0,255};
cosem_init2(&obj.base, DLMS_OBJECT_TYPE_REGISTER, ln);

You need to include gxobjects.h.

BR,
Mikko

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

Still getting error

Still getting error
Added Header Files
#include "../../development/include/gxobjects.h"

Code
unsigned char ln[6] = {1,0,14,7,0,255};
cosem_init2(&obj.base, DLMS_OBJECT_TYPE_REGISTER, &ln);
gxRegister obj;
obj_init2(&obj,ln);
ret = com_read(connection, obj, 2);
int value = var_toInterger(&obj.value);
printf("%d",value);

Error
src/main.c: In function ‘readSerialPort’:
src/main.c:210:1: warning: implicit declaration of function ‘cosem_init2’ [-Wimplicit-function-declaration]
cosem_init2(&obj.base, DLMS_OBJECT_TYPE_REGISTER, &ln);
^
src/main.c:210:14: error: ‘obj’ undeclared (first use in this function)
cosem_init2(&obj.base, DLMS_OBJECT_TYPE_REGISTER, &ln);
^
src/main.c:210:14: note: each undeclared identifier is reported only once for each function it appears in
src/main.c:212:1: warning: implicit declaration of function ‘obj_init2’ [-Wimplicit-function-declaration]
obj_init2(&obj,ln);
^
src/main.c:213:1: error: incompatible type for argument 2 of ‘com_read’
ret = com_read(connection, obj, 2);
^
In file included from src/main.c:32:0:
src/../include/communication.h:71:5: note: expected ‘struct gxObject *’ but argument is of type ‘gxRegister’
int com_read(
^
src/main.c:214:1: warning: implicit declaration of function ‘var_toInterger’ [-Wimplicit-function-declaration]
int value = var_toInterger(&obj.value);
^
make: *** [obj/main.o] Error 1

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,
Move this one line up before you use it.
gxRegister obj;

Also add #include "cosem.h"

BR,
Mikko
BR,
Mikko

Techapirant

6 years 9 months ago

Hello,

Hello,

Still Error
Added Header
#include "../../development/include/gxobjects.h"
#include "../../development/include/cosem.h"
Code :
unsigned char ln[6] = {1,0,14,7,0,255};
gxRegister obj;
cosem_init2(&obj.base, DLMS_OBJECT_TYPE_REGISTER, ln);
obj_init2(&obj,ln);
ret = com_read(connection, obj, 2);
int value = var_toInterger(&obj.value);
printf("%d",value);

Error:
src/main.c: In function ‘readSerialPort’:
src/main.c:214:1: error: incompatible type for argument 2 of ‘com_read’
ret = com_read(connection, obj, 2);
^
In file included from src/main.c:32:0:
src/../include/communication.h:71:5: note: expected ‘struct gxObject *’ but argument is of type ‘gxRegister’
int com_read(
^
src/main.c:215:1: warning: implicit declaration of function ‘var_toInterger’ [-Wimplicit-function-declaration]
int value = var_toInterger(&obj.value);
^
make: *** [obj/main.o] Error 1

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

Change this:
ret = com_read(connection, obj, 2);
to:
ret = com_read(connection, &obj.base, 2);

var_toInteger needs that you add add #include "variant.h"

BR,
Mikko
BR,
Mikko

Techapirant

6 years 9 months ago

Still error exists

Still error exists

Added Header
#include "../../development/include/gxobjects.h"
#include "../../development/include/cosem.h"
#include "../../development/include/variant.h"

Code:
const unsigned char ln[6] = {1,0,14,7,0,255};
gxRegister obj;
cosem_init2(&obj.base, DLMS_OBJECT_TYPE_REGISTER, ln);
obj_init2(&obj,ln);
ret = com_read(connection, &obj.base, 2);
int value = var_toInterger(&obj.value);
printf("%d",value);

Error:
~/Desktop/DLMS/GuruxDLMSClientExample$ make
src/main.c: In function ‘readSerialPort’:
src/main.c:213:1: warning: implicit declaration of function ‘obj_init2’ [-Wimplicit-function-declaration]
obj_init2(&obj,ln);
^
src/main.c:215:1: warning: implicit declaration of function ‘var_toInterger’ [-Wimplicit-function-declaration]
int value = var_toInterger(&obj.value);
^
Compiled src/main.c successfully!
obj/main.o: In function `readSerialPort':
main.c:(.text+0x5a1): undefined reference to `obj_init2'
main.c:(.text+0x5d1): undefined reference to `var_toInterger'
collect2: error: ld returned 1 exit status
make: *** [bin/gurux.dlms.client.bin] Error 1

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

remove obj_init2(&obj,ln);

rename var_toInterger to var_toInteger.

BR,
Mikko

Techapirant

6 years 9 months ago

Hello,

Hello,

Compiled successfully but on reading I am getting error as below
InitializeConnection
<- 7E A0 07 03 41 93 5A 64 7E
SNRMRequest failed Send failed.

Techapirant

6 years 9 months ago

In reply to Hello, by Techapirant

Hello,

Hello,

Its working now.
Can you tell me How can I read multiple registers in same manner & Is there any way I can read description for the object ?

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,
You can use cl_readList to read multiple registers.

Description parser is not implemented for ANSI C for memory usage reasons.
You can you GuruxDLMSTranslator to get the description.
http://www.gurux.fi/GuruxDLMSTranslator?obis=0000010000FF

You can read your meter with GXDLMSDirector and then read the data that you want to.

BR,
Mikko

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

Hello,

Hello,

Can you show any example how to use cl_readList ?

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

Check com_readScalerAndUnits. I believe it helps you.

https://github.com/Gurux/GuruxDLMS.c/blob/a0cc328ea7fbfa288b45d0e47e497…

BR,

Mikko

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

Hello,

Hello,

I am referring communication.c file but In that only function is defined. I want an example means I if I want to read two object and its index 2 values say
a. 1.0.14.7.0.255
b. 1.0.12.7.0.255

Then how can I declare gxArray* list and how can I print only values and can I result the output into an array ?

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

Hello,

Hello,

I am referring communication.c file but In that only function is defined. I want an example means I if I want to read two object and its index 2 values say
a. 1.0.14.7.0.255
b. 1.0.12.7.0.255

Then how can I declare gxArray* list and how can I print only values and can I result the output into an array ?

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

Please, don't post same question several times.

gxRegister r, rs;
//Initialize registers...

gxArray list;
arr_init(&list);
//Add object to the list.
//2 is attribute index.
arr_push(&list, key_init(r1.&base, (void*)2));
arr_push(&list, key_init(r2.&base, (void*)2));
cl_readList(&list);

After you have read values, you need to loop the results and save them as you wish.

BR,
Mikko

Techapirant

6 years 9 months ago

Getting Error :

Getting Error :
src/main.c: In function ‘readSerialPort’:
src/main.c:227:1: warning: passing argument 1 of ‘arr_init’ from incompatible pointer type [enabled by default]
arr_init(&list);
^
In file included from src/../include/../../development/include/gxobjects.h:43:0,
from src/../include/../../development/include/objectarray.h:41,
from src/../include/../../development/include/dlmssettings.h:42,
from src/../include/../../development/include/dlms.h:44,
from src/../include/../../development/include/client.h:43,
from src/../include/communication.h:22,
from src/main.c:32:
src/../include/../../development/include/gxarray.h:53:10: note: expected ‘struct gxArray *’ but argument is of type ‘struct gxArray **’
void arr_init(gxArray* arr);
^
src/main.c:228:1: warning: passing argument 1 of ‘arr_push’ from incompatible pointer type [enabled by default]
arr_push(&list, key_init(&r1.base, (void*)2));
^
In file included from src/../include/../../development/include/gxobjects.h:43:0,
from src/../include/../../development/include/objectarray.h:41,
from src/../include/../../development/include/dlmssettings.h:42,
from src/../include/../../development/include/dlms.h:44,
from src/../include/../../development/include/client.h:43,
from src/../include/communication.h:22,
from src/main.c:32:
src/../include/../../development/include/gxarray.h:59:9: note: expected ‘struct gxArray *’ but argument is of type ‘struct gxArray **’
int arr_push(gxArray * arr, void* item);
^
src/main.c:229:1: warning: passing argument 1 of ‘arr_push’ from incompatible pointer type [enabled by default]
arr_push(&list, key_init(&r2.base, (void*)2));
^
In file included from src/../include/../../development/include/gxobjects.h:43:0,
from src/../include/../../development/include/objectarray.h:41,
from src/../include/../../development/include/dlmssettings.h:42,
from src/../include/../../development/include/dlms.h:44,
from src/../include/../../development/include/client.h:43,
from src/../include/communication.h:22,
from src/main.c:32:
src/../include/../../development/include/gxarray.h:59:9: note: expected ‘struct gxArray *’ but argument is of type ‘struct gxArray **’
int arr_push(gxArray * arr, void* item);
^
src/main.c:230:1: warning: passing argument 1 of ‘cl_readList’ from incompatible pointer type [enabled by default]
cl_readList(connection,list,&messages);
^
In file included from src/../include/communication.h:22:0,
from src/main.c:32:
src/../include/../../development/include/client.h:100:9: note: expected ‘struct dlmsSettings *’ but argument is of type ‘struct connection *’
int cl_readList(
^
Compiled src/main.c successfully!
Linking complete!

Code :
const unsigned char ln1[] = {1,0,14,7,0,255};
const unsigned char ln2[] = {1,0,12,7,0,255};
message messages;
gxRegister r1, r2;
cosem_init2(&r1.base, DLMS_OBJECT_TYPE_REGISTER, ln1);
cosem_init2(&r2.base, DLMS_OBJECT_TYPE_REGISTER, ln2);

gxArray* list;
arr_init(&list);
arr_push(&list, key_init(&r1.base, (void*)2));
arr_push(&list, key_init(&r2.base, (void*)2));
cl_readList(connection,list,&messages);

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

Use:
gxArray list;
not:
gxArray* list;

BR,
Mikko

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

Tried with that too

Tried with that too
Error:
src/main.c: In function ‘readSerialPort’:
src/main.c:230:1: warning: passing argument 1 of ‘cl_readList’ from incompatible pointer type [enabled by default]
cl_readList(connection,list,&messages);
^
In file included from src/../include/communication.h:22:0,
from src/main.c:32:
src/../include/../../development/include/client.h:100:9: note: expected ‘struct dlmsSettings *’ but argument is of type ‘struct connection *’
int cl_readList(
^
src/main.c:230:1: error: incompatible type for argument 2 of ‘cl_readList’
cl_readList(connection,list,&messages);
^
In file included from src/../include/communication.h:22:0,
from src/main.c:32:
src/../include/../../development/include/client.h:100:9: note: expected ‘struct gxArray *’ but argument is of type ‘gxArray’
int cl_readList(
^
make: *** [obj/main.o] Error 1

Code:
const unsigned char ln1[] = {1,0,14,7,0,255};
const unsigned char ln2[] = {1,0,12,7,0,255};
message messages;
gxRegister r1, r2;
cosem_init2(&r1.base, DLMS_OBJECT_TYPE_REGISTER, ln1);
cosem_init2(&r2.base, DLMS_OBJECT_TYPE_REGISTER, ln2);

gxArray list;
arr_init(&list);
arr_push(&list, key_init(&r1.base, (void*)2));
arr_push(&list, key_init(&r2.base, (void*)2));
cl_readList(connection,list,&messages);

Profile picture for user Kurumi

Kurumi

6 years 9 months ago

Hi,

Hi,

Please, read the error message first.

Change
cl_readList(connection,list,&messages);
to:
cl_readList(connection,&list,&messages);

BR,

Mikko

Techapirant

6 years 9 months ago

In reply to Hi, by Kurumi

Hello,

Hello,

Changing
cl_readList(connection,&list,&messages);
to
cl_readList(&connection->settings,&list,&messages);

worked and compiled successfully as it is expecting dlms settings as first argument not the struct connection

The result I am getting is in messages variable. Looping this using below code how can I get the values from gxbuffer
int pos;
for (pos = 0; pos != messages.size; ++pos)
{
//Want Values
}

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701
  • Thu, 07/23/2026 - 16:19
    gurux.dlms.java 4.0.96
  • Thu, 07/09/2026 - 14:34
    Gurux.DLMS.Python 1.0.201
  • Fri, 06/26/2026 - 16:32
    Gurux.Service 3.0.2606.2601
  • Wed, 06/24/2026 - 08:36
    Gurux.DLMS.Python 1.0.200

New forum topics

  • Version mismatch between Gurux.DLMS 9.x and Gurux.Common/Gurux.Serial 8.x
  • Service not known error on gprs communication
  • Help Needed: Interfacing Saral 100 Energy Meter with Microcontroller via RS232
  • Connecting Meter to Agent via serial
  • Reading block profile with Compact array
More

Who's new

  • ArthurDaype
  • hirenec11mic
  • Yeyen
  • Virtual
  • joesa4
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin