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. Writing Bytearray With Write()?

Writing bytearray with write()?

By mick93, 11 April, 2025
Forums
Gurux.DLMS

Hi,
I have problem with changing value of object, which has 'bytearray' - as I could see after reading that OBIS. For changing "normal" values, such as APN, I use the following python snippet:

d = GXDLMSData("obis")
d.apn = "newAPN"
self.write(d, 2)

And it works fine, but there's also manufacturer's specific object - pinging setup, which consists of target IP and interval. First one is bytearray, second is integer. After reading this object it looks like below:

-------- Reading 1 0.0.131.6.0.255 Manufacturer specific
Attribute: 1 Value: 0.0.131.6.0.255
Attribute: 2 Value: bytearray(b''), 0

Or, if it is enabled:
Attribute: 2 Value: bytearray(b'8.8.8.8'), 60

But when I use:
d = GXDLMSData("0.0.131.6.0.255")
d.value = bytearray(b"8.8.8.8"), 60
self.write(d, 2)

then I have error: Exception: Invalid parameter. In python value type must give.

Any ideas how to solve that problem?

Profile picture for user Kurumi

Kurumi

6 months 3 weeks ago

Hi, I believe that you need…

Hi,

I believe that you need to write a structure. You can do it like this:

s = GXStructure()
s.append(bytearray(b"8.8.8.8"))
s.append(GXUInt8(60))

BR,
Mikko

mick93

6 months 3 weeks ago

I did as suggested: self…

I did as suggested:

self.newObisValue = GXStructure()
self.newObisValue.append(bytearray(b"8.8.8.8"))
self.newObisValue.append(GXUInt16(60))

in GXDLMSReader.py:
d = GXDLMSData("0.0.131.6.0.255")
d.value = newValue #(self.newObisValue from previous)

So using write() it was writing it:
[bytearray(b'8.8.8.8'), 60]

Still, it gave error: Exception: Invalid parameter. In python value type must give.

Specifically, from write() function:
File "C:\Users\x\Desktop\GURUX\Gurux.DLMS.Python-master\Gurux.DLMS.Client.Example.python\GXDLMSReader.py", line 316, in write
data = self.client.write(item, attributeIndex)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\site-packages\gurux_dlms\GXDLMSClient.py", line 1082, in write
return self.__write(item.name, value, type_, item.objectType, index)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\x\AppData\Local\Programs\Python\Python311\Lib\site-packages\gurux_dlms\GXDLMSClient.py", line 1093, in __write
raise Exception("Invalid parameter. In python value type must give.")

If you'd need more information: I was able to read this obis from GXDLMSDirector app:
<Structure>
<OctetString Value="382E382E382E38" />
<UInt16 Value="001E" />
</Structure>

And from xml:
<WRAPPER len="1B" >
<SourceAddress Value="1" />
<TargetAddress Value="1" />
<PDU>
<SetRequest>
<SetRequestNormal>
<!-- Priority: Normal, ServiceClass: Confirmed, Invoke ID: 1 -->
<InvokeIdAndPriority Value="41" />
<AttributeDescriptor>
<!-- Data -->
<ClassId Value="0001" />
<!-- 0.0.131.6.0.255 -->
<InstanceId Value="0000830600FF" />
<!-- Value -->
<AttributeId Value="02" />
</AttributeDescriptor>
<Value>
<Structure Qty="02" >
<!-- 8.8.8.8 -->
<OctetString Value="382E382E382E38" />
<UInt16 Value="001E" />
</Structure>
</Value>
</SetRequestNormal>
</SetRequest>
</PDU>
</WRAPPER>

Profile picture for user Kurumi

Kurumi

6 months 3 weeks ago

Hi, You need also set the…

Hi,

You need also set the data type like this:

d = GXDLMSData("0.0.131.6.0.255")
d.setDataType(2, DataType.STRUCTURE)

BR,
Mikko

mick93

6 months 3 weeks ago

That did work, many thanks!

That did work, many thanks!

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Wed, 10/29/2025 - 08:51
    gurux.dlms.c 9.0.2510.2901
  • Thu, 10/16/2025 - 09:59
    gurux.dlms.java 4.0.83
  • Wed, 10/08/2025 - 10:21
    gurux.dlms.c 9.0.2510.0801
  • Fri, 09/26/2025 - 10:02
    gurux.dlms.cpp 9.0.2509.2601
  • Fri, 09/26/2025 - 09:45
    gurux.dlms.c 9.0.2509.2601

New forum topics

  • How to get/convert user readable format data from readRowsByRange
  • Insufficient memory to continue the execution of the program.
  • The client instance code failed to connect to the electricity meter for authentication
  • Unable to Release Request when closing connection with meter.
  • Failed to receive reply from the device in given time.
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin