
Read basic information from Gurux.DLMS component before you start to create DLMS client.
Device manufacturer custom objects
DLMS standard defines COSEM objects that manufacturers should use. Sometimes manufacturers use their own custom objects to extend the meter functionality. This is not recommended, but support for custom objects has been added to some of Gurux DLMS libraries.Impementing custom object
At first, implement a custom object and derive it from GXDLMSObject and IGXDLMSBase.
public class ManufacturerSpecificObject
extends GXDLMSObject
implements IGXDLMSBase {
/*
* Manufacturer specific attribute.
*/
public int Manufacturer;
/*
* Returns amount of attributes.
*/
@Override
public final int getAttributeCount() {
return 2;
}
/*
* Returns amount of methods.
*/
@Override
public final int getMethodCount() {
return 1;
}
/**
* Returns read attributes.
*/
@Override
public int[] getAttributeIndexToRead(boolean all) {
return new int[] { 1, 2 };
}
/**
* Returns attribute names.
*/
@Override
public String[] getNames() {
return new String[] { "Logical Name", "Manufacturer attribute" };
}
/**
* Returns method names.
*/
@Override
public String[] getMethodNames() {
return new String[] { "Reset", };
}
/*
* Returns value of given attribute.
*/
@Override
public final Object getValue(final GXDLMSSettings settings, final ValueEventArgs e) {
if (e.getIndex() == 1) {
return GXCommon.logicalNameToBytes(getLogicalName());
}
if (e.getIndex() == 2) {
return Manufacturer;
}
e.setError(ErrorCode.READ_WRITE_DENIED);
return null;
}
/*
* Set value of given attribute.
*/
@Override
public final void setValue(final GXDLMSSettings settings, final ValueEventArgs e) {
if (e.getIndex() == 1) {
setLogicalName(GXCommon.toLogicalName(e.getValue()));
} else if (e.getIndex() == 2) {
Manufacturer = ((Number) e.getValue()).intValue();
} else {
e.setError(ErrorCode.READ_WRITE_DENIED);
}
}
@Override
public void load(GXXmlReader reader) throws XMLStreamException {
// Load attribute values.
}
@Override
public void save(GXXmlWriter writer) throws XMLStreamException {
// Save attribute values.
}
@Override
public void postLoad(GXXmlReader reader) {
// Update attributes after load.
}
}
////// This class implments manucaturer spesific COSEM object. /// public class ManufacturerSpecificObject : GXDLMSObject, IGXDLMSBase { ////// Manufacturer specific attribute. /// public int Manufacturer { get; set; } ////// Returns amount of attributes. /// public int GetAttributeCount() { return 2; } ////// Returns read attributes. /// /// ///public int[] GetAttributeIndexToRead(bool all) { return new int[] { 1, 2 }; } public int GetMaxSupportedVersion() { return 0; } /// /// Returns amount of methods. /// public int GetMethodCount() { return 1; } ////// Returns method names. /// public string[] GetMethodNames() { return new string[] { "Reset" }; } ////// Returns attribute names. /// public string[] GetNames() { return new string[] { "Logical Name", "Manufacturer" }; } ////// Value is write for the meter. /// /// /// ///public object GetValue(GXDLMSSettings settings, ValueEventArgs e) { object ret; if (e.Index == 1) { ret = GXCommon.LogicalNameToBytes(LogicalName); } else if (e.Index == 2) { ret = (byte)Manufacturer; } else { e.Error = ErrorCode.ReadWriteDenied; ret = null; } return ret; } /// /// Value is read from the meter. /// /// /// public void SetValue(GXDLMSSettings settings, ValueEventArgs e) { switch (e.Index) { case 1: LogicalName = GXCommon.ToLogicalName(e.Value); break; case 2: Manufacturer = Convert.ToByte(e.Value); break; default: e.Error = ErrorCode.ReadWriteDenied; break; } } public byte[] Invoke(GXDLMSSettings settings, ValueEventArgs e) { //This is not needed on the client side. throw new NotImplementedException(); } public void Load(GXXmlReader reader) { // Load attribute values. } public void PostLoad(GXXmlReader reader) { // Update attributes after load. } public void Save(GXXmlWriter writer) { // Save attribute values. } }
Custom objects is not implemented at the moment.
Custom objects is not implemented at the moment.
Custom objects is not implemented at the moment.
public class GXDLMSSecureClient2 extends GXDLMSSecureClient implements IGXCustomObjectNotifier {
/**
* Create manufacturer specific custom COSEM object.
*/
@Override
public GXDLMSObject onObjectCreateEventHandler(int type, int version) {
if (type == 10006 && version == 1) {
return new ManufacturerSpecificObject();
}
return null;
}
}
GXDLMSClient client = new GXDLMSClient();
client.OnCustomObject += (type, version) =>
{
if (type == 6001 && version == 0)
{
return new ManufacturerSpecificObject();
}
return null;
};
Custom objects is not implemented at the moment.
Custom objects is not implemented at the moment.
Custom objects is not implemented at the moment.