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. Node
  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

4 years 1 month 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

4 years 1 month ago

Thank you for clarifying

Thank you for clarifying Mikko.

Thanks,
Sathappa Subramaniam

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 08/26/2026 - 09:04
    Gurux.DLMS.Python 1.0.203
  • Mon, 08/17/2026 - 11:28
    Gurux.DLMS.Python 1.0.202
  • Mon, 08/17/2026 - 09:47
    gurux.dlms.cpp 9.0.2608.1701
  • Mon, 08/17/2026 - 09:25
    gurux.dlms.c 9.0.2608.1701
  • Mon, 07/27/2026 - 12:37
    gurux.dlms.cpp 9.0.2607.2701

New forum topics

  • Security vulnerability report — request for a private contact (GuruxDLMS.c / ANSI C)
  • Topic: Insufficient Memory Error When Reading Class 7 Profile Generic Objects
  • SN ReadResponse returns all-null values when response spans multiple HDLC frames
  • Gurux.Serial.Android 3.0.6 – CH340 (HL-340) USB-Serial Adapter Not Working,
  • Trying to talk to a L&G E360 meter (Using Python Gurux)
More

Who's new

  • Anaglyfos Trading CC
  • cyby
  • Metin Onan
  • ssv007
  • 3nzol3dur
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin