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. Not Able To Print Scaler and Unit

Not able to print Scaler and Unit

By ParthDesai , 15 July, 2024
Forums
General discussion

Hello,

I am working on a project where I need to read the Scalr, Unit, Value, and Logical name using C programming language. I've included my code below for reference. The issue I'm facing is that when I try to print the Scalar or Unit, they are not appearing as expected. I aim to convert them to strings and print them correctly. Any assistance on this matter would be greatly appreciated.

Thank you.

unsigned char logical_name[6];
char data_string[50] = "1.0.14.7.0.255,1.0.32.7.0.255";
char *data = NULL;
data_string[sizeof(data_string) - 1] = '\0';

char *token = strtok(data_string, ",");
int numberOfProcessedObisCode = 0;
while (token != NULL)
{
gxRegister register_object;
hlp_setLogicalName(logical_name, token);
cosem_init2(&register_object.base, DLMS_OBJECT_TYPE_REGISTER, logical_name);
memcpy(obisCodeInstantaneousData[numberOfProcessedObisCode].logical_name, &register_object.base.logicalName, sizeof(&register_object.base.logicalName));

int read_status = com_read(connection, &register_object.base, 3);
ret = obj_toString(&register_object.base, &data);
if (ret != DLMS_ERROR_CODE_OK)
{
return ret;
}
if (data != NULL)
{
sscanf(data, "Value: Scaler: %lf Unit: %s",
&obisCodeInstantaneousData[numberOfProcessedObisCode].scalar,
obisCodeInstantaneousData[numberOfProcessedObisCode].unit);
free(data);
data = NULL;
}

read_status = com_read(connection, &register_object.base, 2);
obisCodeInstantaneousData[numberOfProcessedObisCode].value = var_toInteger(&register_object.value);
numberOfProcessedObisCode++;
token = strtok(NULL, ",");
}

// Print the structured data from the array of measurements
for (int i = 0; i < numberOfProcessedObisCode; i++) {
printf("Value: %d\n", obisCodeInstantaneousData[i].value);
printf("Unit: %s\n", obisCodeInstantaneousData[i].unit);
printf("Scaler: %f\n", obisCodeInstantaneousData[i].scalar);
printf("Logical Name: ");
for (int j = 0; j < sizeof(token); j++) {
printf("%02X", obisCodeInstantaneousData[i].logical_name[j]);
}
printf("\n\n");
}

Profile picture for user Kurumi

Kurumi

1 year 10 months ago

Hi, You can use obj_toString…

Hi,

You can use obj_toString method. Something like this:

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

BR,
Mikko

  • 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
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin