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.
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
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
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
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
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 ?
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 ?
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!
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
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
}
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
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
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
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
Hi,
Hi,
Move this one line up before you use it.
gxRegister obj;
Also add #include "cosem.h"
BR,
Mikko
BR,
Mikko
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
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
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
Hi,
Hi,
remove obj_init2(&obj,ln);
rename var_toInterger to var_toInteger.
BR,
Mikko
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.
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 ?
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
Hello,
Hello,
Can you show any example how to use cl_readList ?
Hi,
Hi,
Check com_readScalerAndUnits. I believe it helps you.
https://github.com/Gurux/GuruxDLMS.c/blob/a0cc328ea7fbfa288b45d0e47e497…
BR,
Mikko
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 ?
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 ?
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
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);
Hi,
Hi,
Use:
gxArray list;
not:
gxArray* list;
BR,
Mikko
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);
Hi,
Hi,
Please, read the error message first.
Change
cl_readList(connection,list,&messages);
to:
cl_readList(connection,&list,&messages);
BR,
Mikko
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
}