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. GXByteBuffer.setPosition() Is Raising ValueError("position") - PYTHON

GXByteBuffer.setPosition() is raising ValueError("position") - PYTHON

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 Ugurcan , 24 February, 2021
Forums
Gurux.DLMS

Hello,

I am new to Gurux and this is my very first question.

-> Meters are randomly raising value errors.
This can happen at any given time (initializing a connection with the meter, reading a meter, updating the firmware,...)
When I catch the error, I re-execute the operation I was performing. Sometimes this operation suddenly succeeds again, and sometimes it keeps failing.

I debugged and I found that it happens when the returned buffer array is smaller than the value on setPosition() function.

File "/lib/python3.6/site-packages/gurux_dlms/GXDLMS.py", line 987, in getTcpData
value = buff.getUInt16()
File "/lib/python3.6/site-packages/gurux_dlms/GXByteBuffer.py", line 318, in getUInt16
self.position += 2
File "/lib/python3.6/site-packages/gurux_dlms/GXByteBuffer.py", line 124, in setPosition
raise ValueError("position")

When i print the results of this error i got this:
ValueError: position error, value = 16 and length of array = 15,
ValueError: position error, value = 9 and length of array = 8,
ValueError: position error, value = 10 and length of array = 8,
ValueError: position error, value = 800 and length of array = 799

Those errors are almost always thrown at getUInt16() function and inside of the function the operation of "self.position += 2" which is calling def setPosition(self, value)

Here are some of the byte arrays I got throwing that exception.
Byte aray hex: C4 02 C1 00 00 00 00 01
Byte aray hex: 61 29 A1 09 06 07 60 85 61 29 A1 09 06 07 60 61 29 A1 09 06 07 60 00 01 00 01 00 01 00
Byte aray hex: 00 00 00 00 00 00 00 00 00 01 00 01 00 01 00

I am using gurux_dlms==1.0.100

The fact that re-executing certain operations leading to a successful execution without performing any changes, makes me think that this might be related to network issues, or corrupted data being sent by the meter. But when I try to do the same operations using the GURUX DLMS DIRECTOR it successfully finishes nearly always

What I might be missing here?

Python version==3.8.0

Thanks in Advance.
Ugurcan Akpulat

Profile picture for user Kurumi

Kurumi

5 years 3 months ago

Hi,

Hi,

There is data missing for the byte arrays that you added and that is causing this issue. Because there is only part of the data I can't say what is causing this. Can you add a failed frame that contains all the data so I can check what might be the reason for this.

BR,
Mikko

Ugurcan

5 years 3 months ago

Authentication:

TX: 14:45:24 00 01 00 01 00 01 00 3D 60 3B A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B 07 60 85 74 05 08 02 01 AC 0F 80 0D 45 6C 65 65 6E 61 5F 45 6E 65 72 67 79 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 00 1E 5D FF FF
RX: 14:45:26 00 01 00 01 00 01 00 2B 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 18 1D 04 40 00 07
TX: 14:45:27 00 01 00 01 00 01 00 1B C1 01 C1 00 08 00 00 01 00 00 FF 02 00 09 0C 07 E5 02 18 03 0E 2D 1B FF 00 00 00
RX: 14:45:28 00 01 00 01 00 01 00 04 C5 01 C1 00
TX: 14:45:28 00 01 00 01 00 01 00 12 C1 01 C1 00 01 00 00 61 61 00 FF 02 00 06 00 00 00 00
RX: 14:45:30 00 01 00 01 00 01 00 04 C5 01 C1 00
TX: 14:45:30 00 01 00 01 00 01 00 0D C0 01 C1 00 01 00 00 60 0C 05 FF 02 00
RX: 14:45:31 00 01 00 01 00 01 00 06 C4 01 C1 00 0F C1
TX: 14:45:31 00 01 00 01 00 01 00 0D C0 01 C1 00 01 01 00 00 02 00 FF 02 00
RX: 14:45:32 00 01 00 01 00 01 00 32 C4 01 C1 00 09 2C 42 4C 4E 32 31 30 31 38 7C 58 4D 58 5F 4E 32 31 5F 32 67 54 69 56 36 33 42 7C 4C 47 5A 5A 43 46 31 30 30 41 43 2E 4D 35 39 00 00 00
TX: 14:45:32 00 01 00 01 00 01 00 0D C0 01 C1 00 07 01 00 63 01 00 FF 03 00
RX: 14:45:38 C4 01 C1 00 09 2C 42 4C 00 01 00 01 00 01 00
TX: 14:45:40 00 01 00 01 00 01 00 0D C0 01 C1 00 07 01 00 63 01 00 FF 03 00
RX: 14:45:40 4E C4 01 C1 00 01 04 02

Byte array hex: 4E C4 01 C1 00 01 04 02
================================
RX: 14:45:40 4E C4 01 C1 00 01 04 02
[210224 14:45:40] There was an error while reading meter id = 158 position error, value = 10 and length of array = 8.

Ugurcan

5 years 3 months ago

And another one:

And another one:

TX: 14:48:46 00 01 00 01 00 01 00 3D 60 3B A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B 07 60 85 74 05 08 02 01 AC 0F 80 0D 45 6C 65 65 6E 61 5F 45 6E 65 72 67 79 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 00 1E 5D FF FF
RX: 14:48:48 00 01 00 01 00 01 00 2B 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 18 1D 04 40 00 07
TX: 14:48:48 00 01 00 01 00 01 00 1B C1 01 C1 00 08 00 00 01 00 00 FF 02 00 09 0C 07 E5 02 18 03 0E 30 30 FF 00 00 00
RX: 14:48:50 00 01 00 01 00 01 00 04 C5 01 C1 00
TX: 14:48:50 00 01 00 01 00 01 00 12 C1 01 C1 00 01 00 00 61 61 00 FF 02 00 06 00 00 00 00
RX: 14:48:51 00 01 00 01 00 01 00 04 C5 01 C1 00
TX: 14:48:51 00 01 00 01 00 01 00 0D C0 01 C1 00 01 00 00 60 0C 05 FF 02 00
RX: 14:48:53 00 01 00 01 00 01 00 06 C4 01 C1 00 0F C3
TX: 14:48:53 00 01 00 01 00 01 00 0D C0 01 C1 00 01 01 00 00 02 00 FF 02 00
RX: 14:48:54 00 01 00 01 00 01 00 32 C4 01 C1 00 09 2C 42 4C 4E 32 31 30 31 38 7C 58 4D 58 5F 4E 32 31 5F 32 67 54 69 56 36 33 42 7C 4C 47 5A 5A 43 46 31 30 30 41 43 2E 4D 35 39 00 00 00
TX: 14:48:54 00 01 00 01 00 01 00 0D C0 01 C1 00 07 01 00 63 01 00 FF 03 00
RX: 14:48:56 00 01 00 01 00 01 00 4E C4 01 C1 00 01 04 02 04 12 00 08 09 06 00 00 01 00 00 FF 0F 02 12 00 00 02 04 12 00 01 09 06 00 00 60 0A 01 FF 0F 02 12 00 00 02 04 12 00 03 09 06 01 00 01 08 00 FF 0F 02 12 00 00 02 04 12 00 03 09 06 01 00 02 08 00 FF 0F 02 12 00 00
TX: 14:48:56 00 01 00 01 00 01 00 40 C0 01 C1 00 07 01 00 63 01 00 FF 02 01 01 02 04 02 04 12 00 08 09 06 00 00 01 00 00 FF 0F 02 12 00 00 09 0C 07 E5 02 17 02 08 0F 00 00 00 00 00 09 0C 07 E5 02 18 03 0E 30 36 00 00 00 00 01 00
RX: 14:49:00 00 01 00 01 00 01 04 40 C4 02 C1 00 00 00 00 01 00 82 04 34 01 7B 02 04 09 0C 07 E5 02 17 02 09 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A 41 02 04 09 0C 07 E5 02 17 02 09 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A 68 02 04 09 0C 07 E5 02 17 02 09 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A A2 02 04 09 0C 07 E5 02 17 02 0A 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A C2 02 04 09 0C 07 E5 02 17 02 0A 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A DD 02 04 09 0C 07 E5 02 17 02 0A 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A FE 02 04 09 0C 07 E5 02 17 02 0A 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8B 2E 02 04 09 0C 07 E5 02 17 02 0B 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8B 6C 02 04 09 0C 07 E5 02 17 02 0B 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8B BD 02 04 09 0C 07 E5 02 17 02 0B 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8C 16 02 04 09 0C 07 E5 02 17 02 0B 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8C 7E 02 04 09 0C 07 E5 02 17 02 0C 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8C EB 02 04 09 0C 07 E5 02 17 02 0C 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8D 59 02 04 09 0C 07 E5 02 17 02 0C 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8D B9 02 04 09 0C 07 E5 02 17 02 0C 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E 01 02 04 09 0C 07 E5 02 17 02 0D 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E 49 02 04 09 0C 07 E5 02 17 02 0D 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E 9D 02 04 09 0C 07 E5 02 17 02 0D 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E E0 02 04 09 0C 07 E5 02 17 02 0D 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8F 41 02 04 09 0C 07 E5 02 17 02 0E 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8F 96 02 04 09 0C 07 E5 02 17 02 0E 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 90 16 02 04 09 0C 07 E5 02 17 02 0E 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 90 84 02 04 09 0C 07 E5 02 17 02 0E 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 90 DE 02 04 09 0C 07 E5 02 17 02 0F 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 91 3E 02 04 09 0C 07 E5 02 17 02 0F 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 91 9D 02 04 09 0C 07 E5 02 17 02 0F 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 91 F8 02 04 09 0C 07 E5 02 17 02 0F 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 44 02 04 09 0C 07 E5 02 17 02 10 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 82 02 04 09 0C 07 E5 02 17 02 10 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 BA 02 04 09 0C 07 E5 02 17 02 10 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 E8 02 04 09 0C 07 E5 02 17 02 10 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 07 02 04 09 0C 07 E5 02 17 02 11 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 1F 02 04 09 0C 07 E5 02 17 02 11 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 31 02 04 09 0C 07 E5 02 17 02 11 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 3B 02 04 09 0C 07 E5 02 17 02 11 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 41 02 04 09 0C 07 E5 02 17 02 12 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 43 02 04 09 0C 07 E5 02 17 02 12 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 43 02 04 09 0C 07 E5 02 17 02 12 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 43 02 04 09 0C 07 E5 02 17 02 12
TX: 14:49:00 00 01 00 01 00 01 00 07 C0 02 C1 00 00 00 01
RX: 14:49:05 C4 02 C1 00 00 00 00 01

Byte array hex: C4 02 C1 00 00 00 00 01
================================
RX: 14:49:05 C4 02 C1 00 00 00 00 01
[210224 14:49:05] There was an error while reading meter id = 197 position error, value = 10 and length of array = 8.

Profile picture for user Kurumi

Kurumi

5 years 3 months ago

In reply to Authentication: by Ugurcan

Hi,

Hi,

Are you sure that you don't remove any data? Read is correct, but it seems like there is a header missing from the meter reply.

DATA is missing here: C4 01 C1 00 09 2C 42 4C 00 01 00 01 00 01 00

If this is really what the meter replies then there is an error in the meter.

BR,
Mikko

Profile picture for user Kurumi

Kurumi

5 years 3 months ago

In reply to And another one: by Ugurcan

Hi,

Hi,

Have you modified the code? You are asking the next block, but the meter didn't reply or it's missing here. There should be a timeout error if the meter is not answering.

BR,
Mikko

Profile picture for user Kurumi

Kurumi

5 years 3 months ago

In reply to And another one: by Ugurcan

Hi,

Hi,

Same thing here. The header is missing. Check that you don't remove it.

BR,
Mikko

Ugurcan

5 years 3 months ago

In reply to Hi, by Kurumi

Hello again, thanks for your

Hello again, thanks for your super fast replies. This is the full output. Meter actually replied here. Just there was a line that I printed in between.

I am not doing anything to remove the header in any of this calls. I don't even know what exactly you meant by header also. Can you elaborate a litte please?

Quarterly data reading of meter 197
TX: 14:48:54 00 01 00 01 00 01 00 0D C0 01 C1 00 07 01 00 63 01 00 FF 03 00
RX: 14:48:56 00 01 00 01 00 01 00 4E C4 01 C1 00 01 04 02 04 12 00 08 09 06 00 00 01 00 00 FF 0F 02 12 00 00 02 04 12 00 01 09 06 00 00 60 0A 01 FF 0F 02 12 00 00 02 04 12 00 03 09 06 01 00 01 08 00 FF 0F 02 12 00 00 02 04 12 00 03 09 06 01 00 02 08 00 FF 0F 02 12 00 00
TX: 14:48:56 00 01 00 01 00 01 00 40 C0 01 C1 00 07 01 00 63 01 00 FF 02 01 01 02 04 02 04 12 00 08 09 06 00 00 01 00 00 FF 0F 02 12 00 00 09 0C 07 E5 02 17 02 08 0F 00 00 00 00 00 09 0C 07 E5 02 18 03 0E 30 36 00 00 00 00 01 00
RX: 14:49:00 00 01 00 01 00 01 04 40 C4 02 C1 00 00 00 00 01 00 82 04 34 01 7B 02 04 09 0C 07 E5 02 17 02 09 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A 41 02 04 09 0C 07 E5 02 17 02 09 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A 68 02 04 09 0C 07 E5 02 17 02 09 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A A2 02 04 09 0C 07 E5 02 17 02 0A 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A C2 02 04 09 0C 07 E5 02 17 02 0A 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A DD 02 04 09 0C 07 E5 02 17 02 0A 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8A FE 02 04 09 0C 07 E5 02 17 02 0A 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8B 2E 02 04 09 0C 07 E5 02 17 02 0B 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8B 6C 02 04 09 0C 07 E5 02 17 02 0B 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8B BD 02 04 09 0C 07 E5 02 17 02 0B 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8C 16 02 04 09 0C 07 E5 02 17 02 0B 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8C 7E 02 04 09 0C 07 E5 02 17 02 0C 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8C EB 02 04 09 0C 07 E5 02 17 02 0C 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8D 59 02 04 09 0C 07 E5 02 17 02 0C 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8D B9 02 04 09 0C 07 E5 02 17 02 0C 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E 01 02 04 09 0C 07 E5 02 17 02 0D 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E 49 02 04 09 0C 07 E5 02 17 02 0D 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E 9D 02 04 09 0C 07 E5 02 17 02 0D 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8E E0 02 04 09 0C 07 E5 02 17 02 0D 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8F 41 02 04 09 0C 07 E5 02 17 02 0E 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 8F 96 02 04 09 0C 07 E5 02 17 02 0E 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 90 16 02 04 09 0C 07 E5 02 17 02 0E 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 90 84 02 04 09 0C 07 E5 02 17 02 0E 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 90 DE 02 04 09 0C 07 E5 02 17 02 0F 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 91 3E 02 04 09 0C 07 E5 02 17 02 0F 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 91 9D 02 04 09 0C 07 E5 02 17 02 0F 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 91 F8 02 04 09 0C 07 E5 02 17 02 0F 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 44 02 04 09 0C 07 E5 02 17 02 10 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 82 02 04 09 0C 07 E5 02 17 02 10 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 BA 02 04 09 0C 07 E5 02 17 02 10 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 92 E8 02 04 09 0C 07 E5 02 17 02 10 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 07 02 04 09 0C 07 E5 02 17 02 11 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 1F 02 04 09 0C 07 E5 02 17 02 11 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 31 02 04 09 0C 07 E5 02 17 02 11 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 3B 02 04 09 0C 07 E5 02 17 02 11 2D 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 41 02 04 09 0C 07 E5 02 17 02 12 00 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 43 02 04 09 0C 07 E5 02 17 02 12 0F 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 43 02 04 09 0C 07 E5 02 17 02 12 1E 00 00 00 3C 00 11 00 06 00 00 00 00 06 00 09 93 43 02 04 09 0C 07 E5 02 17 02 12
TX: 14:49:00 00 01 00 01 00 01 00 07 C0 02 C1 00 00 00 01
RX: 14:49:05 C4 02 C1 00 00 00 00 01

Profile picture for user Kurumi

Kurumi

5 years 3 months ago

Hi,

Hi,

Check this with some sniffer tool, but if this is what your meters really returns then there is a error in the meter and you need to ask meter manufacturer to fix it.

C4 02 C1 00 00 00 00 01

This is not a correct reply. That is the only payload (PDU) and the header is missing. There is nothing that you can do about it.

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