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);
-----------------------------------------------------------------------
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
Thank you for clarifying
Thank you for clarifying Mikko.
Thanks,
Sathappa Subramaniam