Skip to main content
Home
for DLMS smart meters

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Defining a Structure On Server

Defining a Structure on server

By Pablob, 17 October, 2025
Forums
Gurux DLMS for ANSI C

Hello.

Im triying to create a COSEM object class_id = 1 (DLMS_OBJECT_TYPE_DATA) of type structure. This structure will contain 4 different values. First 2 of them will be uint32 and last 2 will be int32.

The way i'm creating this object is the following:

gxData myMEASURES;
static dlmsVARIANT vUA, vIA, vPA, vQA;
uint32_t g_rmsUA, g_rmsIA;
int32_t g_rmsPA, g_rmsQA;
#define MAX_MEASURES 4
static dlmsVARIANT arrElements[MAX_MEASURES];
static variantArray arrBuf;

int addDataObject()
{
int ret;
const unsigned char ln[6] = { 1, 0, 99, 199, 0, 255 };
if ((ret = INIT_OBJECT(myMEASURES, DLMS_OBJECT_TYPE_DATA, ln)) == 0)
{

//Inicializo array de dlmsVariant
arrBuf.data = arrElements;
arrBuf.capacity = MAX_MEASURES;
arrBuf.size = 0;

//Inicializo objeto gurux
va_init(&myMEASURES.value);
myMEASURES.value.vt = DLMS_DATA_TYPE_STRUCTURE;
myMEASURES.value.Arr = &arrBuf;

va_init(&vUA);
vUA.vt = DLMS_DATA_TYPE_UINT32;
GX_UINT32_BYREF(vUA, g_rmsUA);
va_push(myMEASURES.value.Arr, &vUA);

va_init(&vIA);
vIA.vt = DLMS_DATA_TYPE_UINT32;
GX_UINT32_BYREF(vIA, g_rmsIA);
va_push(myMEASURES.value.Arr, &vIA);

va_init(&vPA);
vPA.vt = DLMS_DATA_TYPE_INT32;
GX_INT32_BYREF(vPA, g_rmsPA);
va_push(myMEASURES.value.Arr, &vPA);

va_init(&vQA);
vQA.vt = DLMS_DATA_TYPE_INT32;
GX_INT32_BYREF(vQA, g_rmsQA);
va_push(myMEASURES.value.Arr, &vQA);

}
return ret;
}

On srv preAction function, I'm assigning value to g_rmsUA, g_rmsIA, g_rmsPA and g_rmsQA.

When i try to read with GXDLMSDirector i get the following message.

"Failed to convert data type to DLMS data type. Unknown data type."

The message I'm getting from the server is:

C4 01 C1 00 02 04 20 00 85 00 00 00

When i try to translate with DLMS translator to XML i get the same error.

How should i define the object so i dont get this error?

Thanks!

Pablo

Profile picture for user Kurumi

Kurumi

1 month 2 weeks ago

Hi Pablo, I tested your code…

Hi Pablo,

I tested your code this and it works without problems.
You need to update the values on svr_preRead, not in preAction.
https://gurux.fi/Gurux.DLMS.Server

I used this code in svr_preRead to increase values for every read.

++g_rmsUA;
++g_rmsIA;
++g_rmsPA;
++g_rmsQA;

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 12/02/2025 - 10:21
    gurux.dlms.c 9.0.2512.0201
  • Mon, 12/01/2025 - 13:55
    Gurux.DLMS.Python 1.0.193
  • Thu, 11/13/2025 - 15:23
    Gurux.DLMS.Python 1.0.192
  • Thu, 11/13/2025 - 14:55
    gurux.dlms.java 4.0.84
  • Wed, 10/29/2025 - 08:51
    gurux.dlms.c 9.0.2510.2901

New forum topics

  • Incomplete Firmware Upgrade Process
  • SNRM byte mening
  • P384 Client Certificate incorrect issuer CN
  • Confirmed push service support
  • DLMS Stack hang during Firmware Upgrade
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin