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. [Question] Gurux.dlms.c - Read Single Object

[Question] Gurux.dlms.c - Read Single Object

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 Sathappa , 15 August, 2022
Forums
Gurux.DLMS

Hi,

Reading a ISKRA DLMS Meter using Gurux.dlms.c.

code sample how i'm reading the obis code - device name [0,0,42,0,0,255] is given below.

Issue: while reading the device name, some extra characters are appearing in
the end.
Ex: ISK0070777807016ýýýý

Expected result: ISK0070777807016

When i'm reading via GuruX Director, the value is proper.

Currently, to remove the extra character used a sub_string function, reading
based on capacity/length.

Kindly guide me how to get proper value using existing functions of gurux.

-----------------------------------------------------------------------
Code:
int ret;
unsigned char logicalname_dn[] = { 0,0,42,0,0,255 }; // device name
// Read - Device Name
gxData* _deviceName = (gxData*)malloc(sizeof(gxData));
INIT_OBJECT((*_deviceName), DLMS_OBJECT_TYPE_DATA, logicalname_dn);
ret = com_read(connection, &_deviceName->base, 2);
if (ret != DLMS_ERROR_CODE_OK)
{
return ret;
}
printf("\n Device Name: %s", _deviceName->value.strVal->data);
// Value is "ISK0070777807016ýýýý"
-----------------------------------------------------------------------
// ---- remove unnessary character ---- //
// ---- read only for string capacity ---- //
// SUBSSTRING FUNCTION to read from length "1 to capacity"
int capacity = _deviceName->value.strVal->capacity;
char* src = _deviceName->value.strVal->data;
int m = 1;
int n = capacity;

// get the length of the destination string
int len = n - m;

// allocate (len + 1) chars for destination (+1 for extra null character)
char* dest = (char*)malloc(sizeof(char) * (len + 1));

// extracts characters between m'th and n'th index from source string
// and copy them into the destination string
for (int i = m; i < n && (*(src + i) != '\0'); i++)
{
*dest = *(src + i);
dest++;
}

// null-terminate the destination string
*dest = '\0';

// return the destination string
dest = dest - len;

printf("\n after reading with capacity... %d", capacity);
printf("\n DEVICE NAME : %s\n", dest);
-----------------------------------------------------------------------

Thanks,
Sathappa Subramaniam

Profile picture for user Kurumi

Kurumi

3 years 10 months ago

Hi Sathappa,

Hi Sathappa,

There is no ending char ('\0') in DLMS strings and this is an octet string.
You can get the name as a string like this:

char* tmp = bb_toString(_deviceName->value.strVal);
printf("\n Device Name: %s", tmp);
free(tmp);

BR,
Mikko

Sathappa

3 years 10 months ago

Thank you for clarifying

Thank you for clarifying Mikko.

Thanks,
Sathappa Subramaniam

  • 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