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. How To Write Data To Meter?

How to write data to meter?

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 Mithun Tiruvedula , 1 April, 2021
Forums
Gurux DLMS for Java

Hi all,

I'm relatively new to DLMS and associated development. I'm trying to build a Tridium Niagara driver for DLMS. I am using the sources from
https://mvnrepository.com/artifact/org.gurux/gurux.dlms/4.0.24
https://mvnrepository.com/artifact/org.gurux/gurux.net/1.0.21
https://mvnrepository.com/artifact/org.gurux/gurux.common/1.0.17

I am able to read the data from an Indian Standard Elmeasure meter and the Gurux simulated server (https://github.com/Gurux/gurux.dlms.java/tree/master/gurux.dlms.server…).

I want to now write data to the meter and have a few questions regarding the same:

1. How to know if an attribute (GXDLMSObject -> Attribute OBIS) is a writable point?
2. How to use the writeObject method given in the GXDLMSReader (https://github.com/Gurux/gurux.dlms.java/blob/master/gurux.dlms.client…), as the sampleClient.java does not have any write example?

After a little digging around I think I may have to use the GXDLMSObject.setValue method, but it requires a parameter GXDLMSSettings, which I do not know how to pass; and I do not understand where to set the new value of the attribute I wish to edit.

Any help would be of immense help.

Thanks and regards,
Mithun
Leanovate Solutions

Mithun Tiruvedula

5 years 2 months ago

Hi,

Hi,

I was going through older answers and realized we could write in the following manner:

int pos = getIndexAttribute();
GXDLMSData prt = new GXDLMSData(this.getObis());
prt.setDataType(pos, DataType.BITSTRING);
GXBitString dt = new GXBitString("HELLO THERE");
prt.setValue(dt);
bDlDevice.reader.writeObject(prt, pos);

1. Is this the right way to do it?
2. Is there a way to write in general, or should I have a write method for each data type (string, int, date, etc)?

Again, thanks a lot!!!

Profile picture for user Kurumi

Kurumi

5 years 2 months ago

Hi Mithun,

Hi Mithun,

You don't need to set the data type if you have read the object from the meter. Write is a general method and you can use it for all the data types. You need to describe the data type before write or the meter will return an error.

You can write as you have shown above.

BR,
Mikko

Mithun Tiruvedula

5 years 2 months ago

Hi Mikko,

Hi Mikko,

Right now I am converting in the following way:

public GXDLMSData convertNtoDLMS(String obis, int attributePos, DataType dataType, String className, Object newVal) throws Exception {
GXDLMSData prt = new GXDLMSData(obis);
Object finalVal = null;

if (dataType == DataType.BCD) {
finalVal = decimalToBcd((int) newVal);
}
if (dataType == DataType.BOOLEAN) {
finalVal = (boolean) newVal;
}
if (dataType == DataType.ENUM) {
// MIKKO Should I crete new enum from gurux.dlms.enums ??
}
if (dataType == DataType.FLOAT32) {
finalVal = newVal;
}
if (dataType == DataType.FLOAT64) {
finalVal = newVal;
}
if (dataType == DataType.INT16) {
finalVal = newVal;
}
if (dataType == DataType.INT32) {
finalVal = newVal;
}
if (dataType == DataType.INT64) {
finalVal = newVal;
}
if (dataType == DataType.INT8) {
finalVal = newVal;
}
if (dataType == DataType.UINT8) {
finalVal = new GXUInt8((short) newVal);
}
if (dataType == DataType.UINT16) {
finalVal = new GXUInt16((int) newVal);
}
if (dataType == DataType.UINT32) {
finalVal = new GXUInt32((int) newVal);
}
if (dataType == DataType.UINT64) {
finalVal = new GXUInt32((int) newVal);
}
if (dataType == DataType.OCTET_STRING) {
finalVal = newVal;
}
if (dataType == DataType.STRING || dataType == DataType.NONE || dataType == DataType.STRING_UTF8) {
finalVal = (String) newVal;
}
if (dataType == DataType.BITSTRING) {
finalVal = new GXBitString((String) newVal);
}
if (dataType == DataType.DATE) {
//TODO
finalVal = new GXDate();
}
if (dataType == DataType.DATETIME) {
//TODO
finalVal = new GXDateTime();
}
if (dataType == DataType.TIME) {
//TODO
finalVal = new GXTime();
}
if (finalVal == null) {
throw new Exception("couldNotCreateException");
}
prt.setDataType(attributePos, dataType);
prt.setValue(finalVal);
return prt;
}

And then do

GXDLMSReader.writeObject(prt, pos);

is this correct?

Thanks a lot Mikko!!!!!!!!

Profile picture for user Kurumi

Kurumi

5 years 2 months ago

Hi,

Hi,

Usually, we are doing it like this, but yours works as well.

GXDLMSData prt = new GXDLMSData("OBIS_CODE");
prt.setDataType(pos, DataType.BITSTRING);
GXBitString dt = new GXBitString("010");
prt.setValue(dt);
device.reader.writeObject(prt, 2);
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