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. Cosem_init2

cosem_init2

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 ybou04 , 14 September, 2021
Forums
Gurux.DLMS

Hi,
I'm trying to use the server example from your directory NordicSemi on a PC, under National Instruments CVI IDE, before use it on a STM32 target.

I have an running error in cosem_init2() function, in cosem.c file, line 416 :

memset(object, 0, size);

When called from addLogicalDeviceName(), size is 32 (sizeof DLMS_OBJECT_TYPE_DATA) but gxObject* object is 16.

I've just replace this init line by :
memset(object, 0, sizeof(object));

Regards,
Yvan

Profile picture for user Kurumi

Kurumi

4 years 9 months ago

Hi,

Hi,

gxObject* is 16 because you are using 16 bytes addressing. You need to remove it and replace it with the original code. Not your gxData is not fully initialized.

BR,
Mikko

ybou04

4 years 9 months ago

Mikko,

Mikko,
Thanks for your answer, but I don't understand...
I've try to add __ptr32 before to cast in 32 bits the addressing :
gxObject* __ptr32 object,
But it's already in 32 bits addressing ! On CVI, I can use only 32 or 64 bits addressing, not 16.
Yvan

ybou04

4 years 9 months ago

Mikko,

Mikko,
gxObject* object, => 16 bytes

But size, which is int size = cosem_getObjectSize(type) ; where type = DLMS_OBJECT_TYPE_DATA
is : size = sizeof(gxData);

And gxData is :
typedef struct
{
/**
* Base class where class is derived.
*/
gxObject base;
dlmsVARIANT value;
} gxData;

Each : gxObject and dlmsVARIANT is 16, so size is really 32.

But the memset(object, 0, size);, where object is a gxObject* object, is not possible... except if you want to clear object and the next 16 bytes in the RAM.

Am I right ?

Yvan

Profile picture for user Kurumi

Kurumi

4 years 9 months ago

Hi Yvan,

Hi Yvan,

Yes, the purpose is clear the content of the object. In this case content of the gxData.
I believe that you have missed the base object. The size of the base object is 16 bytes.

const unsigned char ln[6] = { 0, 0, 42, 0, 0, 255 };
gxData data;
cosem_init2(BASE(data), DLMS_OBJECT_TYPE_DATA, ln);

BR,
Mikko

ybou04

4 years 9 months ago

I think we are not talking

I think we are not talking about the same thing ;)

gxData is 32 bytes and gxObject is 16 bytes
We can not use memset of 32 bytes on a 16 bytes buffer.
Some compiler will clear the gxObject and ... 16 other unknown RAM bytes.
My compiler don't want to and break on error.

Profile picture for user Kurumi

Kurumi

4 years 8 months ago

Hi,

Hi,

OK. :-)
I'll ask to install National Instruments CVI and make test build with this code:
const unsigned char ln[6] = { 0, 0, 42, 0, 0, 255 };
gxData data;
cosem_init2(BASE(data), DLMS_OBJECT_TYPE_DATA, ln);

I'll let you know the results later today.

BR,
Mikko

Profile picture for user Kurumi

Kurumi

4 years 8 months ago

Hi,

Hi,

The size of gxData is 32 and this is current and everything works like expected, but what seems to be happening is that CVI is treating object as a pointer to an gxObject and not gxData. This is causing the error. There was an article that if gxObject* is replaced with void* it will solve this. This was tried, but this error is still there. I hope that there is a way to handle this bug id 461C7P34.

BR,
Mikko

ybou04

4 years 8 months ago

Mikko,

Mikko,
Thanks for your answer.

I'm trying today to use the server on STM32 target (GCC compiler).

I'll be back with the behavior of this config !

Yvan

Profile picture for user Kurumi

Kurumi

4 years 8 months ago

Hi Yvan,

Hi Yvan,

There are changes in the source code for the LabWindows/CVI. Get the latest version. There is also an client example for the LabWindows/CVI. You must define objects like this in LabWindows/CVI:

const unsigned char ln[6] = { 0, 0, 42, 0, 0, 255 };
gxData data;
INIT_OBJECT(data, DLMS_OBJECT_TYPE_DATA, ln);

BR,
Mikko

ybou04

4 years 8 months ago

Mikko,

Mikko,
Porting server stack (Nordic Semi directory) on STM32 successful !
No need to change anything in your code.

Now, I have to configure reals COSEM objects and add security...

Yvan

Profile picture for user Kurumi

Kurumi

4 years 8 months ago

Hi,

Hi,

The source code should work with other compilers. LabWindows/CVI was interesting, but it should work now.

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