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 Read/save/load ENUM Type PYTHON METCOM301C

DLMS read/save/load ENUM type PYTHON METCOM301C

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 bartoszszczepanik , 18 March, 2020
Forums
Gurux.DLMS

Hello
python module doesn't seem to handle enums . i've based my code on example code from official git repo. i can read objects without much problem but whenever i try scalers/unit/whateer that have enum values i get error from diffrent places in code trying to make unallowed operations on int objects (my meter returns int eg "<ContextId>1</ContextId>" instead of enum object
example of unallowed operations :

File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXDLMSAssociationLogicalName.py", line 615, in load
self.xDLMSContextInfo.conformance = reader.readElementContentAsInt("Conformance")
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXXmlReader.py", line 107, in readElementContentAsInt
ret =int(str_)
ValueError: invalid literal for int() with base 10: 'Conformance.NONE'

it tries to convert "ApplicationContextName.LOGICAL_NAME" , should i add wrapper during reading that will convert enum value to int and only then save it as object or am i missing something ?

or during reading (i already fixed it by making changes to repo code so i don't have error message to show)
module tried to access writer.writeElementString("Unit", self.unit.name) in file GXDLMSExtendedRegister.py wich ofc returned error since message i've got was string without attribute name (fixed it by calling writer.writeElementString("Unit", Unit(self.unit).name)

Profile picture for user Kurumi

Kurumi

6 years 2 months ago

Hi,

Hi,

Can you try to update to the latest version?
Run this:
pip install --upgrade gurux-dlms

Let me know if you have still problems. Let me also know your python version.
python --version

BR,
Mikko

bartoszszczepanik

6 years 2 months ago

In reply to Hi, by Kurumi

after update to gurux_dlms i

thank you for reply
after update to gurux_dlms i've got this error during parsing objects

Traceback (most recent call last):
File "C:/Users/xxx/xxx/xxx/dlmsdinconnect.py", line 146, in <module>
client.parseObjects(reply.data, True)
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\GXDLMSClient.py", line 711, in parseObjects
c.updateOBISCodeInformation(objects)
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\GXDLMSConverter.py", line 112, in updateOBISCodeInformation
self.__readStandardObisInfo(self.standard, self.codes)
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\GXDLMSConverter.py", line 155, in __readStandardObisInfo
str_ = str_.replace("\n", "\r")
TypeError: a bytes-like object is required, not 'str'

gurux_dlms version 1.0.58
gurux_common version 1.0.13
gurux_net version 1.0.17
python version : 3.6.8

Profile picture for user Kurumi

Kurumi

6 years 2 months ago

Hi,

Hi,

We was able to repeat this. I create an issue from this.
https://www.gurux.fi/node/15210

This is now fixed. Get the latest version.

BR,
Mikko

bartoszszczepanik

6 years 2 months ago

In reply to Hi, by Kurumi

than you so much :D now

than you so much :D now parsing works again
sadly reading unit/scaler still doesnt work

Traceback (most recent call last):
File "C:/Users/xxx/xxx/xxx/dlmsdinconnect.py", line 160, in <module>
client.objects.save("dlmsobjs.xml")
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXDLMSObjectCollection.py", line 146, in save
it.save(writer)
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXDLMSExtendedRegister.py", line 197, in save
writer.writeElementString("Unit", self.unit.value)
AttributeError: 'int' object has no attribute 'value'

same problem as before. code assumes that unit is enum instead of int (it can be easily fixed by just passing self.unit but i don't know if change like that won't have further consequences in code)

EDIT:

after making mentioned change ( writer.writeElementString("Unit", self.unit)) i saved cosem objects into xml, and tried to read it . following error occured

Traceback (most recent call last):
File "C:/Users/xxx/xxx/xxx/dlmsdinconnect.py", line 117, in <module>
c = GXDLMSObjectCollection.load("dlmsobjs.xml")
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXDLMSObjectCollection.py", line 127, in load
obj.load(reader)
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXDLMSAssociationLogicalName.py", line 612, in load
self.applicationContextName.contextId = ApplicationContextName(reader.readElementContentAsInt("ContextId"))
File "C:\Users\xxx\xxx\xxx\venv\lib\site-packages\gurux_dlms\objects\GXXmlReader.py", line 103, in readElementContentAsInt
ret = int(str_)
ValueError: invalid literal for int() with base 10: 'ApplicationContextName.LOGICAL_NAME'

Process finished with exit code 1

used method "readElementContentAsInt" assumes that code is int written as a string, but it is name of enum

Profile picture for user Kurumi

Kurumi

6 years 2 months ago

Hi,

Hi,

This is fixed. Get the latest version (1.0.60).

I believe we need to add a new distro for testing. What distro you are using? We tested those and it worked without problems and python version is the same.

BR,
Mikko

bartoszszczepanik

6 years 2 months ago

thank you for help , still

thank you for help , still doesn't seem to work ValueError: invalid literal for int() with base 10: 'ApplicationContextName.LOGICAL_NAME' still exists even on new version. i'm using windows 10. as ide i'm using pycharm

Profile picture for user Kurumi

Kurumi

6 years 2 months ago

Hi,

Hi,
Thank you for this info.
It seems that pycharm python is working differently.
We'll install pycharm tomorrow morning for one of the test PCs and release new version after we can finish the tests.

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