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 11 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 11 months ago

Thank you for clarifying

Thank you for clarifying Mikko.

Thanks,
Sathappa Subramaniam

  • 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

  • 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
  • DLMS server - serving multiple similar datasets gathered from multiple meters across distinct logical addresses
More

Who's new

  • JosephNok
  • IUJbutxeSTSNcNRN
  • Peraturaidetetug
  • NnmIomcqcTDVWiDuCD
  • iRnseovnShdVWR…
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin