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. Convert RX Values To String Value In "C"

Convert RX values to String value in "C"

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 imran10x , 14 June, 2021
Forums
Gurux.DLMS

Hi,

Reference thread : https://www.gurux.fi/node/18550
AS Suggested by you in above thread I am using "cl_getData". Blow is my code:

//*********
connection connection;
gxReplyData reply;

con_init(&connection, GX_TRACE_LEVEL_INFO);

cl_init(&connection.settings, 1, 16, 1, DLMS_AUTHENTICATION_NONE, NULL, DLMS_INTERFACE_TYPE_HDLC);

connection.settings.clientAddress = atoi("32");
connection.settings.serverAddress = atoi("1");

connection.data.data = "\x7E\xA0\x15\x41\x03\x52\x10\x8F\xE6\xE7\x00\xC4\x01\x81\x00\x06\x00\x3C\x03\x17\x20\xB2\x7E";
connection.data.position = 0;
connection.data.capacity = 0;
connection.data.size = 24;

printf("%s\n", connection.data.data);

read_data(&connection, &reply);
//******
int read_data (connection* connection, gxReplyData* reply){

int ret = 0;

reply->complete = 0;
do
{
ret = cl_getData(&connection->settings, &connection->data, reply);
if (ret != 0 && ret != DLMS_ERROR_CODE_FALSE)
{
break;
}

} while (reply->complete == 0);

return ret;
}
//** Please help us to get value from reply . We tried with this
reply->dataValue.strVal->data
no luck. Can you please suggest me how to get value from hex using above code.

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,

This is UInt32 value. You can convert it to the string like this:

gxByteBuffer bb;
bb_init(&bb);
var_toString(&reply->dataValue, &bb);
char* pStr = bb_toString(&bb);
print("%s\r\n", pStr);
free(pStr );
BR,
Mikko

imran10x

4 years 12 months ago

Hi,

Hi,
We used below code, but getting size 0 and value null.
gxByteBuffer bb;
bb_init(&bb);
var_toString(&reply.dataValue, &bb);

printf("%d\r\n", bb.size);

char *pStr = bb_toString(&bb);
printf("%s\r\n", pStr);

Can you please overview my above code. what I am doing wrong. Please help

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,

You need to add data to the bytebuffer. Now it's empty. Usually you read it from the meter, but I add bex string that you was using.
gxByteBuffer bb;
bb_init(&bb);
bb_addHexString(&bb, "7EA015410352108FE6E700C401810006003C031720B27E");var_toString(&reply.dataValue, &bb);

BR,
Mikko

imran10x

4 years 12 months ago

Hi ,

Hi ,
Hex:"\x7E\xA0\x15\x41\x03\x52\x10\x8F\xE6\xE7\x00\xC4\x01\x81\x00\x06\x00\x3C\x03\x17\x20\xB2\x7E"
Value :3932951
I have above hex which giving serial number value:3932951
I want convert this HEX to value-> 3932951

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,

I have given the code example here that converts it to the string.
https://www.gurux.fi/comment/21112#comment-21112

BR,
Mikko

imran10x

4 years 12 months ago

Hi,

Hi,

In function dlms_getHdlcData

there is condition:

if (reply->position == reply->size)
{
data->complete = 0;
// Not enough data to parse;
return 0;
}

My code returning from here because reply->position =23 and reply->size = 23

Can you please explain me what is the role of `position` here?.
and what should I pass connection.data.position = ? for
connection.data.data = "\x7E\xA0\x15\x41\x03\x52\x10\x8F\xE6\xE7\x00\xC4\x01\x81\x00\x06\x00\x3C\x03\x17\x20\xB2\x7E";

and what is the role of `capacity`?

Thank you in advance.

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,

Capacity defines how much memory is allocated. The position is used when data is read.
You don't need to use the position. Size is increased every time when you add new data to the buffer.

I have made an example for you that handles your meter data: https://www.gurux.fi/comment/21112#comment-21112

connection.data.data is byte array and it's not a string like you are handling it at the moment.

BR,
Mikko

imran10x

4 years 12 months ago

connection connection;

connection connection;
gxReplyData reply;

con_init(&connection, GX_TRACE_LEVEL_INFO);

connection.settings.clientAddress = atoi("32");
connection.settings.serverAddress = atoi("1");
connection.settings.interfaceType = DLMS_INTERFACE_TYPE_HDLC;

unsigned char d[] = {0x7E, 0xA0, 0x15, 0x41, 0x03, 0xB8, 0x44, 0xC7, 0xE6, 0xE7, 0x00, 0xC4, 0x01, 0x81, 0x00, 0x06, 0x00, 0x02, 0x83, 0x3C, 0x88, 0x37, 0x7E};

connection.data.data = d;
connection.data.capacity = 500;
connection.data.size = 23;

int ret;
ret = cl_getData(&connection.settings, &connection.data, &reply);
if (ret != 0 && ret != DLMS_ERROR_CODE_FALSE) {
printf("error: %d\n", ret);
}

gxByteBuffer bb;
bb_init(&bb);
var_toString(&reply.dataValue, &bb);
char *pStr = bb_toString(&bb);
printf("%s\n", pStr); // <---- getting blank/null value here

Please help me what is wrong I'm doing here...

Profile picture for user Kurumi

Kurumi

4 years 12 months ago

Hi,

Hi,

You don't allocate bytes. Please, don't use this.
connection.data.capacity = 500;
Remove this;
connection.data.data = d;
connection.data.capacity = 500;
connection.data.size = 23;

and add this line:
bb_set(&connection.data, d, sizeof(d));

BR,
Mikko

imran10x

4 years 12 months ago

Hi Mikko,

Hi Mikko,

Thank you so much for your patience and helping me with the issues.

As you suggested https://www.gurux.fi/comment/21130#comment-21130
I did the same but getting error:

ret: 260
Not enough memory available.

Thank you...

Profile picture for user Kurumi

Kurumi

4 years 11 months ago

Hi,

Hi,

The problem is that if you try only with this one frame, the frame sequence number is wrong and the message is skipped. Try to read all the data from the meter. You have also not initialized the reply data and the content of it is random values.
This example will work for this frame.

connection connection;
gxReplyData reply;
reply_init(&reply);
con_init(&connection, GX_TRACE_LEVEL_INFO);
cl_init(&connection.settings, 1, 32, 1, DLMS_AUTHENTICATION_NONE, NULL, DLMS_INTERFACE_TYPE_HDLC);
unsigned char d[] = { 0x7E, 0xA0, 0x15, 0x41, 0x03, 0xB8, 0x44, 0xC7, 0xE6, 0xE7, 0x00, 0xC4, 0x01, 0x81, 0x00, 0x06, 0x00, 0x02, 0x83, 0x3C, 0x88, 0x37, 0x7E };
bb_set(&connection.data, d, sizeof(d));
int ret;
connection.settings.receiverFrame = 184;
ret = cl_getData(&connection.settings, &connection.data, &reply);
if (ret != 0 && ret != DLMS_ERROR_CODE_FALSE) {
printf("error: %d\n", ret);
}

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

Who's new

  • Tuanhgg
  • Adel
  • charnon
  • Paddles
  • Miguel Ángel
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin