How to write data to meter?

5 posts / 0 new
Last post
Mithun Tiruvedula
How to write data to meter?

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.e...).

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.e...), 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

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!!!

Regards,
Mithun
Leanovate Info-Solutions
Bangalore, India

Kurumi
Kurumi's picture

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

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi

Mithun Tiruvedula

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!!!!!!!!

Regards,
Mithun
Leanovate Info-Solutions
Bangalore, India

Kurumi
Kurumi's picture

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

________________________________________
Mikko Kurunsaari
Gurux Ltd
http://www.gurux.fi