/// <summary> /// Client has send data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnReceived(object sender, Gurux.Common.ReceiveEventArgs e) { try { lock (this) { if (Trace > TraceLevel.Info) { Console.WriteLine("<- " + Gurux.Common.GXCommon.ToHex((byte[])e.Data, true)); } byte[] reply = HandleRequest((byte[])e.Data); //Reply is null if we do not want to send any data to the client. //This is done if client try to make connection with wrong device ID. if (reply != null) { if (Trace > TraceLevel.Info) { Console.WriteLine("-> " + Gurux.Common.GXCommon.ToHex(reply, true)); } Media.Send(reply, e.SenderInfo); } } } catch (Exception ex) { if (Trace > TraceLevel.Off) { Console.WriteLine(ex.Message); } } }
/// <summary> /// Client has send data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnReceived(object sender, Gurux.Common.ReceiveEventArgs e) { try { lock (this) { if (trace) { Console.WriteLine("<- " + Gurux.Common.GXCommon.ToHex((byte[])e.Data, true)); } reply.Set((byte[])e.Data); GetData(reply, data); // If all data is received. if (data.IsComplete && !data.IsMoreData) { try { List <KeyValuePair <GXDLMSObject, int> > list; list = ParsePush((Object[])data.Value); // Print received data. foreach (KeyValuePair <GXDLMSObject, int> it in list) { // Print LN. Console.WriteLine(it.Key.ToString()); // Print Value. Console.WriteLine(it.Key.GetValues()[it.Value - 1]); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { data.Clear(); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }