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. DLMS / COSEM Libraries For Linux Implementation

DLMS / COSEM Libraries for Linux implementation

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 cornelverster , 2 November, 2015

Good day

I've noticed it was mentioned in previous posts, but has a Linux suite of these libraries been developed?

Kind regards
Cornel Verster

Profile picture for user Kurumi

Kurumi

10 years 7 months ago

DLMS / COSEM Libraries for Linux implementation

Hi,

We have ANSI C version that is not open source and ANSI C++ version that is also available as open source.

You can download it here:

github.com/Gurux/GuruxDLMSLib

Client example is available here:

github.com/Gurux/GuruxDLMSLibClientExample

Server example is here:

github.com/Gurux/GuruxDLMSLibServerExample

BR,

Mikko

cornelverster

10 years 7 months ago

In reply to DLMS / COSEM Libraries for Linux implementation by Kurumi

Linux Compatibility

Hello Mikko

When attempting to migrate the libraries to Linux, I run into problems as a result of the SetCommState and GetCommState functions in the libraries. These functions are called in functions that seem common to both Windows and Linux implementations.

Is there code available where these functions are written for Linux (not having HANDLE, LPDCB etc.), or should I attempt an implementation by rewriting the functions for Linux myself?

Kind regards
Cornel Verster

Profile picture for user Kurumi

Kurumi

10 years 7 months ago

DLMS / COSEM Libraries for Linux implementation

Hi Cornel,

I check this and you are right.
We will change this on next week.
We will also make makefile so it's easier to compile on
Linux.

BR,

Mikko

jacqueswattel

10 years 5 months ago

DLMS/COSEM Serial for Linux

Hi Mikko,

Are there any plans to update the Windows serial implementation of the following libraries for Linux?
https://github.com/Gurux/GuruxDLMSLibClientExample

Kind Regards
Jacques Wattel

Profile picture for user Kurumi

Kurumi

10 years 5 months ago

DLMS/COSEM Serial for Linux

Hi,

We are making new API for ANSI C and C++ at the moment.
We will release ANSI C++ in latest next month. We have improved Linux support also.

BR,

Mikko

Leila

10 years 3 months ago

DLMS/COSEM Serial for Linux

Hi,

I've been following this topic and checked new App to find out the new API you mentioned.
However I did not fine it. Is it released now? Where can I find it?

Thank you.

cornelverster

10 years 3 months ago

All that seems to have been

All that seems to have been done is that an if statement was inserted to comment out windows code when in Linux, but no Linux code was actually added. That means it compiles, but you still can't talk via a serial link in Linux.

Will the code be updated with the required Linux functionality soon?

Profile picture for user Kurumi

Kurumi

10 years 3 months ago

DLMS/COSEM Serial for Linux

Hi,

I'm sorry that our ANSI C++ implementation has been delayed, but our clients have kept us busy.
We have started testing phase for ANSI C++ implemtation. New version should be available during this month. We have not implemented secured connection to it yet.

BR,

Mikko

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

DLMS/COSEM Serial for Linux

Hi,

You should check our new API for ANSI C++.
We have added serial port reading for Linux there.

You can read more:
http://www.gurux.fi/newAPI

BR,

Mikko

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi,
Thank you for the API released.
when i run it, I face below error which causes not to run completely.
Thisgurux.dlms.client.bin: wcsrtombs.c:99: __wcsrtombs: Assertion `data.__outbuf[-1] == '\0'' failed.
Connect failed Aborted (core dumped)
While running with gdb, below errors show up:
#4 0x00007ffff729944e in __wcsrtombs (dst=dst@entry=0x0,
src=src@entry=0x7fffffffcac0, len=len@entry=0, ps=ps@entry=0x7fffffffcad0)
at wcsrtombs.c:99
#5 0x00007ffff7243281 in _IO_vfprintf_internal (s=<optimized out>,
format=<optimized out>, ap=ap@entry=0x7fffffffcf68) at vfprintf.c:1661
#6 0x00007ffff7249499 in __printf (format=<optimized out>) at printf.c:33
#7 0x0000000000404870 in main (argc=1, argv=0x7fffffffdc48)
at src/GuruxDLMSClientExample.cpp:98
In my modified source code, line 98 contains:
TRACE("Connect failed %S.\r\n", CGXDLMSConverter::GetErrorMessage(ret));

Also I don't know what is wrong to open the /dev/ttyUSB0.

Thank you for your kind help in advance.
Best regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Leila,

Are you using USB to Serial port converter or do you have serial port indide of your PC?

Can you get any data from the meter? What meter you are reading (manufacturer and model)?

BR,

Mikko

Leila

10 years 2 months ago

set a breakpoint in gdb

Hi,

Also, I added '-g' in make file to be able to set a breakpoint while running the bin file by gdb.
CFLAGS = -c -g

Thanks.

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi again,
I'm using USB to Serial port(RS485) converter.
I haven't been able to connect to the meter with this new API, while i connected to the meter by the previews API in windows. The meter is SL7000

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi,

We have fix some issues. Get latest version from SVN and let us know if you still have probems.
What converter you are using (manufacturer and model)?

BR,

Mikko

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

Thank you very much for your kind help and attention.

I will check the new API.
I just realized that with the same code as below:
CGXDLMSClient cl(true, 7, 0x00020023, GXDLMS_AUTHENTICATION_LOW, "ABCDEFGH");
in previews version(without linux option), I got "7E A0 0A 00 02 00 23 07 93 FB 06 7E" as SNRM request,
while in the version (with linux option), I got "7E A0 0A 00 10 00 47 0F 93 FF FF 7E", and then did not let me to connect to the meter.

Thanks again.
Best regards,
Leila
I did this test in windows OS.

Leila

10 years 2 months ago

Hi Mikko,

Hi Mikko,
I used the lateset vesion but nothing had changed for me.
As I got an efficient result from one of the previews versions on windows, So I tested the latest one on windows OS too.
The result of running the latest one is below:

InitializeConnection
<- 16:27:33 7E A0 0A 00 10 00 47 0F 93 DF 0C 7E
SNRMRequest failed 41.
InitializeConnection failed Data send failed..

I'm using Itron SL7000 by FT232R USB UART converter (Z-TEK).

It seems that it sets the addresses inefficiently.

Best Regards,
Leila

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

By your kind help, I've already been able to run the latest API on windows. It, unfortunately, is not able to run on ubuntu 14.04. An error is appeared as below:
./gurux.dlms.client.bin
gurux.dlms.client.bin: wcsrtombs.c:99: __wcsrtombs: Assertion `data.__outbuf[-1] == '\0'' failed.
Connect failed port.
Aborted (core dumped)
It is not able to open the serial port tried to open as below codes:
if ((ret = comm.Open("/dev/ttyUSB0", false)) != 0)
and gives m_hComPort = -1
m_hComPort = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
I'm using Itron SL7000 by FT232R USB UART converter (Z-TEK).

Please let me know how to resolve it.

Thanks for your kind attention and help in advance.

Best regards,
Leila

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

I'm working on the latest API on linux. It seems it opens the serial port by running the bin file as sudo and it sends SNRM request correctly. (7E A0 0A 00 02 00 23 21 93 18 71 7E)
In the next step, I, unfortunately, faced below problem:

#0 __memcpy_sse2_unaligned ()
at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:36
#1 0x000000000040a219 in CGXByteBuffer::AddRange(void const*, int) ()
#2 0x0000000000406eae in GXClient::Read (this=0x7fffffffe400, eop=126 '~',
reply=...) at src/GXClient.cpp:272
#3 0x0000000000407ab5 in GXClient::ReadDLMSPacket (this=0x7fffffffe400,
data=..., reply=...) at src/GXClient.cpp:660
#4 0x0000000000407e76 in GXClient::ReadDataBlock (this=0x7fffffffe400,
data=..., reply=...) at src/GXClient.cpp:700
#5 0x0000000000407617 in GXClient::InitializeConnection (this=0x7fffffffe400)
at src/GXClient.cpp:583
#6 0x0000000000404a02 in main (argc=1, argv=0x7fffffffe5f8)
at src/GuruxDLMSClientExample.cpp:111

In GXClient::Read, there are cnt=1 and bytesRead=65535
I changed the source code of GXBytebuffer::AddRange as below:

while (m_Size + count > m_Capacity)
// if(m_Size + count > m_Capacity)
{
//First time data is reserved only for the added data.
if (m_Capacity == 0)
{
m_Capacity = count;
}
else
{
m_Capacity += count + VECTOR_CAPACITY;
}
m_Data = (unsigned char*) realloc(m_Data, m_Capacity);
}

But nothing changed. Could you please help me to solve it?

Thank you in advance for your kind attention.

Best regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi,

Thank you from this information. It help us to find your problem. Your problems was never occurred in our test environment and we had not found it without your trace.

We fixed this. Get latest version from GitHub.

BR,

Mikko

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

Your welcome and thank you for solving the problem. However I faced other problems.
In GXClient::Read function while bytesRead == 0xFFFF and errno == EAGAIN, it does not return from the function and then interrupts by reply.AddRange function.
I, also, hove to comment the part in this function which was not completed as below:
else if (cnt == 0/* || ret == */)

Thanks again for your efficient and kind help.

Rest regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Leila,

You are right. We updated wait time functionality for Linux.
Get latest version from GitHub.

BR,

Mikko

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

Thank you for the new version. I am using it but some inconvenience below described mostly occurs:
- Mostly It is not able to get a UA response from the meter. In cGXCommunication::ReadDLMSPacket() function bb variable has no data (m_Parser->GetData(bb, reply)). Finally some information appears on the terminal:
InitializeConnection
<- 10:19:29 7E A0 0A 00 02 00 23 07 93 FB 06 7E
SNRMRequest failed 41.
InitializeConnection failed Data send failed..
[Inferior 1 (process 3858) exited with code 01]
I tested this version on windows and it worked well even better than before. (In previews version, While it was receiving too many data from the meter, it was interrupted by not getting on time response)

I put some delay before write() function in cGXCommunication::ReadDLMSPacket. But it did not help.

Could you help me to solve it?

Best regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Leila,

We made some changed. Try to get latest version and let me know if you still have problems.
What meter (manufacturer and model) you try to read?

BR,

Mikko

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

Thank you for the new changes. I'll check it soon.
I'm using Itron SL7000 by FT232R USB UART converter (Z-TEK).

Best regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi,

Try to set iec = true.

BR,

Mikko

Leila

10 years 2 months ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

I used the latest version with both iec=false and iec=true. By iec=false, nothing has changed and the previews problem occurs.
The meter, moreover, does not work with iec=true. I always use the software with iec=false.

I would be pleased if you could help me.

Best regards,
Leila

Leila

10 years 1 month ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

It seems there are some problems in timing, the time which reads serial buffer received. When I run the software step by step by gdb, it sometimes gives UA response and then occur problem in getting AARE. It, however, does not get UA response while running without interruption.
In the previews version, it sometimes gave AARE after disconnecting:

Start InitializeConnection

(1) SNRMRequest & UAResponse

<- 12:15:38 7E A0 0A 00 02 00 23 21 93 18 71 7E

-> <- 12:15:38 7E A0 0A 00 02 00 23 21 93 18 71 7E12:15:38 7E A0 23 21 00 02 00 23 73 F6 C5 81 80 14 05 02 00 80 06 02 00 80 07 04 00 00 00 01 08 04 00 00 00 01

(2) AARQRequest & AAREResponse

<- 12:15:38 7E A0 2E 00 02 00 23 21 10 7E CB E6 E6 00 60 1D A1 09 06 07 60 85 74 05 08 01 01 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 00 7E 1F FF FF 99 C8 7E

AARQRequest failed 41.

1) InitializeConnection failed Data send failed..

<- 12:15:38 7E A0 0A 00 02 00 23 21 53 14 B7 7E

-> <- 12:15:38 7E A0 0A 00 02 00 23 21 53 14 B7 7E12:15:38 7E A0 3A 21 00 02 00 23 30 99 41 E6 E7 00 61 29 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00 A3 05 A1 03 02 01 00 BE 10 04 0E 08 00 06 5F 1F 04 00 00 30 1D 21 34 00 07 E9 1E 7E 7E A0 0A 21 00 02 00 23 73

[Inferior 1 (process 5642) exited with code 01]

All problems are seen on Ubuntu 14.04. None of these problems appear on Windows.

I don't know how and where 'CGXDLMSClient::GetData' function fills 'CGXByteBuffer& reply' variable.

would you please help me to trace efficiently and then solve the problem?

Best regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years 1 month ago

Error in running DLMS/COSEM Serial for linux

Hi,

I update new version. We improved client example trace and added few SN and LN flags,
but I can't get your error. It works without problems.

We will continue this tomorrow with different meter and optical strobe.
After we can dublicate your error we can fix it.

BR,

Mikko

Leila

10 years 1 month ago

Error in running DLMS/COSEM Serial for linux

Hi Mikko,

Thank you for your help and time. I added a 'do .. while' structure to ioctl() function in CGXCommunication::Read() function, then it helped to work better:

//Get bytes available.
// ret = ioctl(m_hComPort, FIONREAD, &cnt);
do{
usleep(10000);
ret = ioctl(m_hComPort, FIONREAD, &cnt);
}while(cnt == 0);

But I need a way more efficiently and securely.

I don't know if it is a mater or not, I have ran Ubuntu on a virtual machine. The software works well on windows.

Would you please help me to trace better and solve the problem?

Best regards,
Leila

Profile picture for user Kurumi

Kurumi

10 years ago

Error in running DLMS/COSEM Serial for linux

Hi Leila,

We updated new version to GitHub.
Please, let me know if you have problems.

BR,

Mikko

frato

9 years ago

Php is possible?

Hello, sorry for my english, have thought to do library for php, or there is some way to use it through php, the idea is to make a system that makes a report of the consumption, and that can make a plot of correinte and tension .

Many thanks, I am currently using GXDLMSDirector and it works great with Actaris meters.

Profile picture for user Kurumi

Kurumi

9 years ago

In reply to Php is possible? by frato

PHP

Hi,

Please, add new topic if you have a new question.

In my mind best way to go is if you create java application that collects data and save it to the DB or file. Then you have PHP app that reads data from DB.
Reason for this is that sometimes it might take long time to read or if you have multiple reads at the same time your second read will fail. Usually meters allow only one connection at the time.

Other solution is if you make reading app with java an call it from php using php exec.

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