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