Sending DLMS Push and Data Notification events.
Gurux.DLMS component supports DLMS Push and Data Notification messages. Structure of Data Notification messages is not so tight as the structure of Push messages. Basically, you can send all kinds of data using Data Notification messages, but problem is that they are more manufacturer-specific.The structure of push messages is defined in the push object list. Some meters send this list in the push message. If push object list is not included in the push message, the size of the push message is smaller, but user must define what kind of data Is received.
GXDLMSNotifyHandler notify = new GXDLMSNotifyHandler( //Is Logical name referencing used. true, //Client address 16, //Server address. 1, // Is used HDLC or COSEM transport layers for IPv4 networks (IEC 62056-47) InterfaceType.Wrapper);
GXDLMSNotifyHandler notify = new GXDLMSNotifyHandler( //Is Logical name referencing used. true, //Client address 16, //Server address. 1, // Is used HDLC or COSEM transport layers for IPv4 networks (IEC 62056-47) InterfaceType.WRAPPER);
//Delphi is not support notifications.
//C++ is not support notifications.
Sending Push messages
You can send and receive push messages easily. GeneratePushMessage is used to send Push messages. You will just give list of COSEM objects what you want to send in Push message. In code example below we will create Register object and send it's 2th and 3rd attributes.You will not receive an acknowledgment from the client, so do not wait it. Just send the data.
List<SimpleEntry<GXDLMSObject, Integer>> objects = new ArrayList<SimpleEntry<GXDLMSObject, Integer>>(); GXDLMSRegister r = new GXDLMSRegister(); objects.Add(new KeyValuePair<GXDLMSObject, int>(r, 2)); objects.Add(new KeyValuePair<GXDLMSObject, int>(r, 3)); byte[][] data = notify.GeneratePushMessage(null, objects); // Send data to the client using example GXNet media component.
List<KeyValuePair<GXDLMSObject, int>> objects = new List<KeyValuePair<GXDLMSObject, int>>(); GXDLMSRegister r = new GXDLMSRegister(); objects.Add(new KeyValuePair<GXDLMSObject, int>(r, 2)); objects.Add(new KeyValuePair<GXDLMSObject, int>(r, 3)); byte[][] data = notify.GeneratePushMessage(DateTime.Now, objects); // Send data to the client using example GXNet media component.
//Delphi is not supporting this functionality at the moment.
//C++ is not supporting this functionality at the moment.
Receiving Push messages
Push message receiving is made with ParsePushObjects.GXReplyData info = new GXReplyData(); client.getData(data, info); if (info.getMoreData() == RequestTypes.NONE) { info.getTime(); //Sent time. info.getValue(); //Received data. }
GXReplyData data = new GXReplyData(); GXReplyData notify= new GXReplyData(); client.GetData(reply, data, notify); if (notify.IsComplete && !notify.IsMoreData) { foreach (KeyValuePair<GXDLMSObject, GXDLMSCaptureObject> it in push.GetPushValues(client, (List<object>)notify.Value)) { int index = it.Value.AttributeIndex - 1; Console.WriteLine(((IGXDLMSBase)it.Key).GetNames()[index] + ": " + it.Key.GetValues()[index]); }
//Delphi is not supporting this functionality at the moment.
cl.GetData(bb, data, notify)); // If all data is received. if (notify.IsComplete()) { bb.SetSize(0); if (!notify.IsMoreData()) { std::vector<std::pair<CGXDLMSObject*, CGXDLMSCaptureObject> > result; if (push.GetPushValues(&cl, notify.GetValue().Arr, result) == 0) { for (std::vector<std::pair<CGXDLMSObject*, CGXDLMSCaptureObject> >::iterator it = result.begin(); it != result.end(); ++it) { std::vector<std::string> values; it->first->GetValues(values); printf("%s\r\n", values[it->second.GetAttributeIndex() - 1].c_str()); } for (std::vector<std::pair<CGXDLMSObject*, CGXDLMSCaptureObject> >::iterator it = result.begin(); it != result.end(); ++it) { delete it->first; } result.clear(); } } }
Sending Data Notification messages
You can send and receive Data Notification messages easily. GetDataNotificationMessage is used to send Data Notification messages. You will just give byte array what you want to send in Data Notification message. In code example below we will create Register object and send it's 2th and 3rd attributes.You will not receive an acknowledgment from the client, so do not wait it. Just send the data.
GXDLMSRegister r = new GXDLMSRegister(); GXByteBuffer bb = new GXByteBuffer(); bb.setUInt8((byte) DataType.ARRAY.GetValue()); bb.setUInt8(2); notify.addData(r, 2, bb); notify.addData(r, 3, bb); byte[][] data = notify.getDataNotificationMessage(null, bb); // Send data to the client using example GXNet media component.
GXDLMSRegister r = new GXDLMSRegister(); GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt8((byte) DataType.Array); bb.SetUInt8(2); notify.AddData(r, 2, bb); notify.AddData(r, 3, bb); byte[][] data = notify.GetDataNotificationMessage(DateTime.Now, bb); // Send data to the client using example GXNet media component.
//Delphi is not supporting this functionality at the moment.
//C++ is not supporting this functionality at the moment.
Receiving Data messages
Data message receiving is made with ParseDataObjects.GXReplyData info = new GXReplyData(); client.getData(data, info); if (info.getMoreData() == RequestTypes.NONE) { info.getTime(); //Sent time. info.getValue(); //Received data. }
GXReplyData info = new GXReplyData(); client.GetData(data, info); if (info.GetMoreData() == RequestTypes.None) { info.Time; //Sent time. info.Value; //Received data. }
//Delphi is not supporting this functionality at the moment.
//C++ is not supporting this functionality at the moment.