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.
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);
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
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";
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.
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
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.
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
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
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
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
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
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.
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
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...
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
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...
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